Package frc.team670.pi.sensors
Class UltrasonicSensor
java.lang.Object
java.lang.Thread
frc.team670.pi.sensors.UltrasonicSensor
- All Implemented Interfaces:
java.lang.Runnable
public class UltrasonicSensor
extends java.lang.Thread
Represents an ultrasonic sensor connected to the pi motor shield
- Author:
- ctychen, lakshbhambhani
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
Constructors Constructor Description UltrasonicSensor(com.pi4j.io.gpio.Pin trig, com.pi4j.io.gpio.Pin echo, int boundary)
Creates an ultrasonic sensor that could measure distance and check if its triggered based on a boundary -
Method Summary
Modifier and Type Method Description double
getDist()
Calculates and returns the distanceboolean
isTriggered()
Checks if the measured distance is less than the boundaryvoid
run()
void
setBoundary(double boundary)
Sets a new boundary for the sensorMethods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Constructor Details
-
UltrasonicSensor
public UltrasonicSensor(com.pi4j.io.gpio.Pin trig, com.pi4j.io.gpio.Pin echo, int boundary)Creates an ultrasonic sensor that could measure distance and check if its triggered based on a boundary- Parameters:
trig
- trig pin for sending signal to put sensor in detecting modeecho
- Pin that sends signals backboundary
- an integer specifying the minimum distance at which the sensor will return a triged response of True.
-
-
Method Details
-
run
public void run()- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
getDist
public double getDist()Calculates and returns the distance- Returns:
- Double distance - The distance sensed by the us sensor
-
isTriggered
public boolean isTriggered()Checks if the measured distance is less than the boundary- Returns:
- Boolean triggered based on whether its within the boundary
-
setBoundary
public void setBoundary(double boundary)Sets a new boundary for the sensor- Parameters:
boundary
- The new value for the boundary
-