Class DistanceSensorDevice

java.lang.Object
com.cdarobotics.cdalib.devices.Device
com.cdarobotics.cdalib.devices.sensors.DistanceSensorDevice

public class DistanceSensorDevice extends Device
A Device wrapping a DistanceSensor. The distance is read once per update() (in centimetres) and cached; getDistance(DistanceUnit) converts the cached reading into any requested unit without touching hardware again.

Getters reflect the value from the most recent update().

  • Constructor Summary

    Constructors
    Constructor
    Description
    DistanceSensorDevice(com.qualcomm.robotcore.hardware.DistanceSensor sensor)
    Wraps an already-resolved distance sensor.
    DistanceSensorDevice(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String name)
    Resolves the distance sensor from the hardware map by configured name.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    getDistance(org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit unit)
     
    double
     
    com.qualcomm.robotcore.hardware.DistanceSensor
     
    void
    Flush pending writes to, or refresh cached reads from, the underlying hardware.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DistanceSensorDevice

      public DistanceSensorDevice(com.qualcomm.robotcore.hardware.DistanceSensor sensor)
      Wraps an already-resolved distance sensor.
    • DistanceSensorDevice

      public DistanceSensorDevice(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String name)
      Resolves the distance sensor from the hardware map by configured name.
  • Method Details

    • getDistance

      public double getDistance(org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit unit)
      Returns:
      the last measured distance, converted into the requested unit.
    • getDistanceCm

      public double getDistanceCm()
      Returns:
      the last measured distance in centimetres.
    • getSensor

      public com.qualcomm.robotcore.hardware.DistanceSensor getSensor()
      Returns:
      the wrapped SDK sensor, for operations not exposed here.
    • update

      public void update()
      Description copied from class: Device
      Flush pending writes to, or refresh cached reads from, the underlying hardware.
      Specified by:
      update in class Device