Sensor and simulation
Package: yams.core.motorcontrollers.simulation
Javadoc: Sensor
A Sensor models a named hardware sensor whose fields are readable from robot code and, in simulation, visible in the WPILib Glass GUI. Every field delegates to a real hardware supplier on a physical robot. In simulation, Glass can override any field's value, and trigger-based overrides can inject specific readings at scripted moments during automated testing.
Use SensorConfig to build a Sensor declaratively. Direct construction is available when you need finer control over the underlying SensorData objects.
Value resolution priority
Each field's value is resolved in this order every loop iteration:
Real robot: always returns the live hardware supplier value immediately.
Active trigger: if any registered
addSimTriggercondition returnstrue, the associated override value is written to Glass and returned.Glass value: if no trigger fired, returns whatever Glass has set for the field (including the configured default).
Supplier fallback: if no Glass value is available, returns the hardware supplier value.
Constructors
Sensor(String sensorName, List<SensorData> sensorFields)
Sensor(SensorConfig cfg)Both constructors throw IllegalStateException if two fields share the same name.
The SensorConfig overload is the preferred way to create sensors; see SensorConfig.
sensorName
Display name shown in the Glass simulation window under Sensor[name].
sensorFields
Fields to register. Each field must have a unique name within this sensor.
cfg
A completed SensorConfig builder.
Field access methods
getField(String name)
SensorData
Returns the named field. Throws IllegalArgumentException if the name does not exist.
getAsDouble(String name)
double
Typed convenience accessor. Throws IllegalStateException if the field is not a double.
getAsInt(String name)
int
Typed convenience accessor. Throws an IllegalStateException if not an int field.
getAsBoolean(String name)
boolean
Typed convenience accessor. Throws an IllegalStateException if not a boolean field.
getAsLong(String name)
long
Typed convenience accessor. Throws an IllegalStateException if not a long field.
getDevice()
Optional<SimDevice>
The underlying WPILib SimDevice. Empty on a real robot.
Simulation methods
addSimTrigger(String field, HALValue value, BooleanSupplier trigger)
Registers a conditional override: whenever trigger returns true, the named field is set to value and Glass is updated. Use SensorData.convert() to produce a HALValue from a primitive.
SensorData
SensorData (yams.core.motorcontrollers.simulation.SensorData) represents a single typed field inside a Sensor. You interact with SensorData directly when constructing sensors without SensorConfig, or when calling addSimTrigger on an individual field.
Constructors
Typed getters
getAsDouble()
double
Throws IllegalStateException if type mismatch.
getAsInt()
int
getAsBoolean()
boolean
getAsLong()
long
getValue()
HALValue
Raw value applying full priority logic.
getDefault()
HALValue
The default value set at construction.
getName()
String
Field name.
getType()
HALValueType
SensorData.HALValueType: kBoolean, kDouble, kEnum, kInt, kLong.
Setters (simulation only)
set(double val)
Directly writes to the Glass SimValue.
set(int val)
set(boolean val)
set(long val)
set(HALValue val)
Raw HAL write.
Trigger injection
Registers a conditional override on this field directly. Triggers are evaluated in registration order; the first active one wins.
Static converters
SensorData.convert(double value)
Wraps a primitive in a HALValue.
SensorData.convert(int value)
SensorData.convert(boolean value)
SensorData.convert(long value)
SensorData.convert(DoubleSupplier supplier)
Wraps a supplier in a Supplier<HALValue>.
SensorData.convert(IntSupplier supplier)
SensorData.convert(BooleanSupplier supplier)
SensorData.convert(LongSupplier supplier)
Example
Related pages
Last updated
Was this helpful?
