Class SensorConfig

java.lang.Object
yams.core.mechanisms.config.SensorConfig

public class SensorConfig extends Object
Sensor configuration for simulated and real sensors.

SensorConfig describes a named sensor that can expose one or more typed fields (double, int, boolean, long) to both the real robot and the simulation environment. It is used to wire hardware sensors such as limit switches, encoders, or custom I/O devices — into YAMS's simulation framework so that the same code path runs identically in simulation and on a real robot.

Each field is registered with a live supplier (the real hardware value) and a default value used when simulation overrides are not active. Simulated values can be injected by match-time window or by an arbitrary BooleanSupplier trigger, allowing a team to script realistic sensor behaviour during automated testing.

The finished configuration is converted to a Sensor via getSensor(), which handles the real/simulated value arbitration at runtime.

Example

import static org.wpilib.units.Units.Seconds;
import yams.core.mechanisms.config.SensorConfig;

// Hardware limit switch wired to a DIO channel
DigitalInput limitSwitch = new DigitalInput(0);

SensorConfig forwardLimit = new SensorConfig("ForwardLimitSwitch")
    .withField("triggered", limitSwitch::get, false)
    // Simulate the switch being pressed between 10 s and 12 s of match time
    .withSimulatedValue("triggered", Seconds.of(10), Seconds.of(12), true);

// Custom encoder exposing position and velocity
SensorConfig encoderConfig = new SensorConfig("ArmEncoder")
    .withField("positionRotations", myEncoder::getPosition, 0.0)
    .withField("velocityRPM",       myEncoder::getVelocity, 0.0)
    // Override position to 2.5 rotations whenever a BooleanSupplier fires
    .withSimulatedValue("positionRotations", () -> Robot.isInTest(), 2.5);
  • Constructor Details

    • SensorConfig

      public SensorConfig(String name)
      Sensor configuration.
      Parameters:
      name - Name of sensor to display in the simulation window.
  • Method Details

    • withField

      public SensorConfig withField(String name, DoubleSupplier supplier, double defaultVal)
      Add a field to the sensor.
      Parameters:
      name - Name of the field to add.
      supplier - Supplier of the real field value.
      defaultVal - Default value of the field.
      Returns:
      SensorConfig
    • withField

      public SensorConfig withField(String name, IntSupplier supplier, int defaultVal)
      Add a field to the sensor.
      Parameters:
      name - Name of the field to add.
      supplier - Supplier of the real field value.
      defaultVal - Default value of the field.
      Returns:
      SensorConfig
    • withField

      public SensorConfig withField(String name, BooleanSupplier supplier, boolean defaultVal)
      Add a field to the sensor.
      Parameters:
      name - Name of the field to add.
      supplier - Supplier of the real field value.
      defaultVal - Default value of the field.
      Returns:
      SensorConfig
    • withField

      public SensorConfig withField(String name, LongSupplier supplier, long defaultVal)
      Add a field to the sensor.
      Parameters:
      name - Name of the field to add.
      supplier - Supplier of the real field value.
      defaultVal - Default value of the field.
      Returns:
      SensorConfig
    • withSimulatedValue

      public SensorConfig withSimulatedValue(String fieldName, org.wpilib.units.measure.Time start, org.wpilib.units.measure.Time end, double value)
      Add a simulated value to the sensor at a given match time.
      Parameters:
      fieldName - Name of the field to change.
      start - Time at which to start the data simulation.
      end - Time at which to end the data simulation.
      value - Value to simulate.
      Returns:
      SensorConfig
    • withSimulatedValue

      public SensorConfig withSimulatedValue(String fieldName, org.wpilib.units.measure.Time start, org.wpilib.units.measure.Time end, int value)
      Add a simulated value to the sensor at a given match time.
      Parameters:
      fieldName - Name of the field to change.
      start - Time at which to start the data simulation.
      end - Time at which to end the data simulation.
      value - Value to simulate.
      Returns:
      SensorConfig
    • withSimulatedValue

      public SensorConfig withSimulatedValue(String fieldName, org.wpilib.units.measure.Time start, org.wpilib.units.measure.Time end, long value)
      Add a simulated value to the sensor at a given match time.
      Parameters:
      fieldName - Name of the field to change.
      start - Time at which to start the data simulation.
      end - Time at which to end the data simulation.
      value - Value to simulate.
      Returns:
      SensorConfig
    • withSimulatedValue

      public SensorConfig withSimulatedValue(String fieldName, org.wpilib.units.measure.Time start, org.wpilib.units.measure.Time end, boolean value)
      Add a simulated value to the sensor at a given match time.
      Parameters:
      fieldName - Name of the field to change.
      start - Time at which to start the data simulation.
      end - Time at which to end the data simulation.
      value - Value to simulate.
      Returns:
      SensorConfig
    • withSimulatedValue

      public SensorConfig withSimulatedValue(String fieldName, BooleanSupplier trigger, double value)
      Add a simulated value to the sensor at a given trigger.
      Parameters:
      fieldName - Name of the field to change.
      trigger - BooleanSupplier for when data should be simulated.
      value - Value to simulate.
      Returns:
      SensorConfig
    • withSimulatedValue

      public SensorConfig withSimulatedValue(String fieldName, BooleanSupplier trigger, int value)
      Add a simulated value to the sensor at a given trigger.
      Parameters:
      fieldName - Name of the field to change.
      trigger - BooleanSupplier for when data should be simulated.
      value - Value to simulate.
      Returns:
      SensorConfig
    • withSimulatedValue

      public SensorConfig withSimulatedValue(String fieldName, BooleanSupplier trigger, long value)
      Add a simulated value to the sensor at a given trigger.
      Parameters:
      fieldName - Name of the field to change.
      trigger - BooleanSupplier for when data should be simulated.
      value - Value to simulate.
      Returns:
      SensorConfig
    • withSimulatedValue

      public SensorConfig withSimulatedValue(String fieldName, BooleanSupplier trigger, boolean value)
      Add a simulated value to the sensor at a given trigger.
      Parameters:
      fieldName - Name of the field to change.
      trigger - BooleanSupplier for when data should be simulated.
      value - Value to simulate.
      Returns:
      SensorConfig
    • getSensor

      public Sensor getSensor()
      Get the Sensor for this sensor.
      Returns:
      Sensor for fetching real and simulated values.
    • getName

      public String getName()
      Get the name of the sensor.
      Returns:
      Name of the sensor.
    • getFields

      public List<SensorData> getFields()
      Get the list of Fields (SensorData) for this sensor.
      Returns:
      list of SensorData for this sensor