Class TouchSensorDevice

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

public class TouchSensorDevice extends Device
A Device wrapping a TouchSensor. The sensor is read once per update() and the result is cached, so any number of isPressed() calls in a loop cost one hardware read.

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

  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    com.qualcomm.robotcore.hardware.TouchSensor
     
    double
     
    boolean
     
    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

    • TouchSensorDevice

      public TouchSensorDevice(com.qualcomm.robotcore.hardware.TouchSensor sensor)
      Wraps an already-resolved touch sensor.
    • TouchSensorDevice

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

    • isPressed

      public boolean isPressed()
      Returns:
      whether the sensor was pressed as of the last update().
    • getValue

      public double getValue()
      Returns:
      the raw sensor value (0.0–1.0 for analog touch sensors) as of the last update().
    • getSensor

      public com.qualcomm.robotcore.hardware.TouchSensor 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