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

    Nested classes/interfaces inherited from class java.lang.Thread

    java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
  • Field Summary

    Fields inherited from class java.lang.Thread

    MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
  • 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 distance
    boolean isTriggered()
    Checks if the measured distance is less than the boundary
    void run()  
    void setBoundary​(double boundary)
    Sets a new boundary for the sensor

    Methods 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

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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 mode
      echo - Pin that sends signals back
      boundary - 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 interface java.lang.Runnable
      Overrides:
      run in class java.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