Class SensorConfig
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet the list of Fields (SensorData) for this sensor.getName()Get the name of the sensor.Get theSensorfor this sensor.withField(String name, BooleanSupplier supplier, boolean defaultVal) Add a field to the sensor.withField(String name, DoubleSupplier supplier, double defaultVal) Add a field to the sensor.withField(String name, IntSupplier supplier, int defaultVal) Add a field to the sensor.withField(String name, LongSupplier supplier, long defaultVal) Add a field to the sensor.withSimulatedValue(String fieldName, BooleanSupplier trigger, boolean value) Add a simulated value to the sensor at a given trigger.withSimulatedValue(String fieldName, BooleanSupplier trigger, double value) Add a simulated value to the sensor at a given trigger.withSimulatedValue(String fieldName, BooleanSupplier trigger, int value) Add a simulated value to the sensor at a given trigger.withSimulatedValue(String fieldName, BooleanSupplier trigger, long value) Add a simulated value to the sensor at a given trigger.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.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.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.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.
-
Constructor Details
-
SensorConfig
Sensor configuration.- Parameters:
name- Name of sensor to display in the simulation window.
-
-
Method Details
-
withField
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
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
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
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-Timeat which to start the data simulation.end-Timeat 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-Timeat which to start the data simulation.end-Timeat 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-Timeat which to start the data simulation.end-Timeat 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-Timeat which to start the data simulation.end-Timeat which to end the data simulation.value- Value to simulate.- Returns:
SensorConfig
-
withSimulatedValue
Add a simulated value to the sensor at a given trigger.- Parameters:
fieldName- Name of the field to change.trigger-BooleanSupplierfor when data should be simulated.value- Value to simulate.- Returns:
SensorConfig
-
withSimulatedValue
Add a simulated value to the sensor at a given trigger.- Parameters:
fieldName- Name of the field to change.trigger-BooleanSupplierfor when data should be simulated.value- Value to simulate.- Returns:
SensorConfig
-
withSimulatedValue
Add a simulated value to the sensor at a given trigger.- Parameters:
fieldName- Name of the field to change.trigger-BooleanSupplierfor when data should be simulated.value- Value to simulate.- Returns:
SensorConfig
-
withSimulatedValue
Add a simulated value to the sensor at a given trigger.- Parameters:
fieldName- Name of the field to change.trigger-BooleanSupplierfor when data should be simulated.value- Value to simulate.- Returns:
SensorConfig
-
getSensor
-
getName
-
getFields
Get the list of Fields (SensorData) for this sensor.- Returns:
- list of
SensorDatafor this sensor
-