Class TimeOfFlight

  • All Implemented Interfaces:
    edu.wpi.first.wpilibj.PIDSource, edu.wpi.first.wpilibj.Sendable, java.lang.AutoCloseable

    public class TimeOfFlight
    extends java.lang.Object
    implements edu.wpi.first.wpilibj.PIDSource, edu.wpi.first.wpilibj.Sendable, java.lang.AutoCloseable
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected edu.wpi.first.wpilibj.PIDSourceType m_pidSource  
    • Constructor Summary

      Constructors 
      Constructor Description
      TimeOfFlight​(int sensorId)
      Create an instance of the CAN Time Of Flight sensor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Destroy the TimeOfFlight object and free any asscioated resources
      double getAmbientLightLevel()
      Get ambient lighting level in mega counts per second.
      long getFirmwareVersion()
      Determine the sensor firmware version
      edu.wpi.first.wpilibj.PIDSourceType getPIDSourceType()  
      double getRange()
      Get the distance between the sensor and the target
      double getRangeSigma()
      Get the standard deviation of the distance measurment in millimeters
      TimeOfFlight.RangingMode getRangingMode()
      Get the sensor ranging mode
      double getSampleTime()
      Get the sensor sampling period in milliseconds
      long getSerialNumber()
      Determine the sensor hardware serial number
      TimeOfFlight.Status getStatus()
      Get status of the last distance measurement.
      void identifySensor()
      Flash the time of flight sensor LED red and green to idicate the sensor asscioated with this instance of software
      void initSendable​(edu.wpi.first.wpilibj.smartdashboard.SendableBuilder builder)  
      boolean isRangeValid()
      Determine if the last measurment was valid
      double pidGet()  
      void setPIDSourceType​(edu.wpi.first.wpilibj.PIDSourceType pidSource)  
      void setRangeOfInterest​(int topLeftX, int topLeftY, int bottomRightX, int bottomRightY)
      Specify the region of the imaging sensor used for range measurement.
      void setRangingMode​(TimeOfFlight.RangingMode mode, double sampleTime)
      Configure the ranging mode as well as the sample rate of the time of flight sensor The ranging mode specifies the trade off between maximum measure distance verses reliablity in bright situations.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface edu.wpi.first.wpilibj.Sendable

        addChild, getName, getSubsystem, setName, setName, setName, setName, setSubsystem
    • Field Detail

      • m_pidSource

        protected edu.wpi.first.wpilibj.PIDSourceType m_pidSource
    • Constructor Detail

      • TimeOfFlight

        public TimeOfFlight​(int sensorId)
        Create an instance of the CAN Time Of Flight sensor. This is designed to support the Playing With Fusion (PWF) SEN-36005 time of flight sensor
        Parameters:
        sensorId - The 6-bit identifier used to select a particular sensor on the CAN bus. This identifier may be set through the PWF Device configuration page on the roboRIO.
    • Method Detail

      • close

        public void close()
        Destroy the TimeOfFlight object and free any asscioated resources
        Specified by:
        close in interface java.lang.AutoCloseable
      • setPIDSourceType

        public void setPIDSourceType​(edu.wpi.first.wpilibj.PIDSourceType pidSource)
        Specified by:
        setPIDSourceType in interface edu.wpi.first.wpilibj.PIDSource
      • getPIDSourceType

        public edu.wpi.first.wpilibj.PIDSourceType getPIDSourceType()
        Specified by:
        getPIDSourceType in interface edu.wpi.first.wpilibj.PIDSource
      • pidGet

        public double pidGet()
        Specified by:
        pidGet in interface edu.wpi.first.wpilibj.PIDSource
      • initSendable

        public void initSendable​(edu.wpi.first.wpilibj.smartdashboard.SendableBuilder builder)
        Specified by:
        initSendable in interface edu.wpi.first.wpilibj.Sendable
      • identifySensor

        public void identifySensor()
        Flash the time of flight sensor LED red and green to idicate the sensor asscioated with this instance of software
      • getFirmwareVersion

        public long getFirmwareVersion()
        Determine the sensor firmware version
        Returns:
        The sensor firmware version
      • getSerialNumber

        public long getSerialNumber()
        Determine the sensor hardware serial number
        Returns:
        The sensor hardware serial number
      • isRangeValid

        public boolean isRangeValid()
        Determine if the last measurment was valid
        Returns:
        TRUE if the Time Of Flight Sensor sucessfully measured distance to an object
      • getRange

        public double getRange()
        Get the distance between the sensor and the target
        Returns:
        Distance to target in millimeters
      • getRangeSigma

        public double getRangeSigma()
        Get the standard deviation of the distance measurment in millimeters
        Returns:
        Standard deviation of distance measurment in millimeters
      • getAmbientLightLevel

        public double getAmbientLightLevel()
        Get ambient lighting level in mega counts per second.
        Returns:
        Ambient lighting level in mega counts per second.
      • getStatus

        public TimeOfFlight.Status getStatus()
        Get status of the last distance measurement.
        Returns:
        Status of last measurement. See VL53L1X datasheet for more details
      • getRangingMode

        public TimeOfFlight.RangingMode getRangingMode()
        Get the sensor ranging mode
        Returns:
        Sensor ranging mode
      • getSampleTime

        public double getSampleTime()
        Get the sensor sampling period in milliseconds
        Returns:
        Sensor sampling period in milliseconds
      • setRangingMode

        public void setRangingMode​(TimeOfFlight.RangingMode mode,
                                   double sampleTime)
        Configure the ranging mode as well as the sample rate of the time of flight sensor The ranging mode specifies the trade off between maximum measure distance verses reliablity in bright situations. Short mode (default) works the best in bright lighting conditions, but can only measure 1.3 meters. Long mode can measure up to 4 meters in the dark, but may only be able to measure shorter distances depending on the lighting conditions. See the Vl53L1x datasheet for more information The sample time specifies the how frequently the time of flight sensor attempts to measure the distance to a target. The sample time must be between 24 and 1000 milliseconds.
        Parameters:
        mode - The desired sensor ranging mode (short, medium, long)
        sampleTime - The desired sample time in milliseconds
      • setRangeOfInterest

        public void setRangeOfInterest​(int topLeftX,
                                       int topLeftY,
                                       int bottomRightX,
                                       int bottomRightY)
        Specify the region of the imaging sensor used for range measurement.

        The region of interest refers to the pixels within the time of flight imaging sensor that are used to detect reflected laser light form the target. The sensor contains a 16x16 pixel grid. By default, all 256 pixels are used which results in a roughly 27 degree field of view.

        The Field of view refers to a cone which grows from the time of flight sensor outward. By reducing the size of the region of interest (by using a smaller area of pixels) it is possible to reduce the field of view. This can be helpfull when measuring objects far away. The smaller the field of view, the smaller the area where the sensor can detect targets.

        Reducing the region of interest will reduce the sensitivity of the sensor. It may be necessary to increase the reflectivity of the target or to increase the sample time to compensate.

        The range of interest rows and columns must be greater or equal to zero and less than or equal to fifteen. The top left corner row/column must be smaller than the bottom right column/row. The region of interest must be at least four coulmns wide and four rows tall. For example, to specify a 4x4 region at the center of the image sensor use:

        TimeOfFlight_SetRangeOfInterest(pHandle, 8, 8, 12, 12);

        Parameters:
        topLeftX - Column of the top left corner of the region of interest.
        topLeftY - Row of the top left corner of the region of interest.
        bottomRightX - Column of the bottom right corner of the region of interest.
        bottomRightY - Row of the bottom right corner of the region of interest.