Interface SimSupplier
- All Known Implementing Classes:
ArmSimSupplier, DCMotorSimSupplier, ElevatorSimSupplier
SimSupplier is the abstract bridge between WPILib's physics simulation models (such as
SingleJointedArmSim and DCMotorSim)
and YAMS SmartMotorController wrappers. Concrete
implementations translate the simulation state position, velocity, current draw, voltage into
the typed unit-safe values that YAMS motor controller wrappers consume each control loop.
On a real robot the motor controller hardware provides these values; in simulation a
SimSupplier steps the physics model forward and exposes the same interface so that mechanism and
control code requires no changes between real and simulated runs.
How to use
Create a concrete SimSupplier (e.g.
ArmSimSupplier or
DCMotorSimSupplier) and pass it to
SmartMotorControllerConfig via withSimSupplier():
// Create the WPILib physics model
SingleJointedArmSim armPhysics = new SingleJointedArmSim(
DCMotor.getNEO(1),
SingleJointedArmSim.estimateMOI(0.5, 2.0),
5.0,
0.5,
Units.degreesToRadians(-10),
Units.degreesToRadians(90),
true,
0);
// Wrap it in a YAMS supplier
SmartMotorControllerConfig config = new SmartMotorControllerConfig()
// ... other config ...
.withSimSupplier(new ArmSimSupplier(armPhysics, motorController));
Implementations must advance the physics model on each control loop tick via
updateSimState(), and signal readiness through the watchdog helpers (
feedUpdateSim()/starveUpdateSim()).
-
Method Summary
Modifier and TypeMethodDescriptionvoidFeed inputvoidFeed the update sim watchorg.wpilib.units.measure.AngleGet the mechanism position.org.wpilib.units.measure.VoltageGet the mechanism stator voltage.org.wpilib.units.measure.VoltageGets the supply voltage for the motor controller.org.wpilib.units.measure.AngularVelocityGet the mechanism velocity.org.wpilib.units.measure.AngularAccelerationGet the rotor acceleration.org.wpilib.units.measure.AngleGet the rotor position.org.wpilib.units.measure.AngularVelocityGet the rotor velocity.org.wpilib.units.measure.CurrentGet the stator current draw of from the sim.org.wpilib.units.measure.CurrentGet the supply current draw of the motor controller.booleanGet the updated sim watchdog.booleanCheck if the input was fed.voidsetMechanismPosition(org.wpilib.units.measure.Angle position) Set the Mechanism positionvoidsetMechanismStatorDutyCycle(double dutyCycle) Set the dutycyle of the mechanism stator.voidsetMechanismStatorVoltage(org.wpilib.units.measure.Voltage volts) Set mechanism voltage, mostly used for SysId testing.voidsetMechanismVelocity(org.wpilib.units.measure.AngularVelocity velocity) Set the Mechanism velocity.voidStarve the input.voidStarve the update sim watch.voidUpdate the sim state.
-
Method Details
-
updateSimState
void updateSimState()Update the sim state. -
getUpdatedSim
boolean getUpdatedSim()Get the updated sim watchdog.- Returns:
- Updated sim.
-
feedUpdateSim
void feedUpdateSim()Feed the update sim watch -
starveUpdateSim
void starveUpdateSim()Starve the update sim watch. -
isInputFed
boolean isInputFed()Check if the input was fed.- Returns:
- Input fed.
-
feedInput
void feedInput()Feed input -
starveInput
void starveInput()Starve the input. -
setMechanismStatorDutyCycle
void setMechanismStatorDutyCycle(double dutyCycle) Set the dutycyle of the mechanism stator.- Parameters:
dutyCycle- Dutycycle value.
-
getMechanismSupplyVoltage
org.wpilib.units.measure.Voltage getMechanismSupplyVoltage()Gets the supply voltage for the motor controller.- Returns:
- Supply voltage to the motor controller
-
getMechanismStatorVoltage
org.wpilib.units.measure.Voltage getMechanismStatorVoltage()Get the mechanism stator voltage.- Returns:
- Stator voltage of the mechanism.
-
setMechanismStatorVoltage
void setMechanismStatorVoltage(org.wpilib.units.measure.Voltage volts) Set mechanism voltage, mostly used for SysId testing.- Parameters:
volts- Voltage to set.
-
getMechanismPosition
org.wpilib.units.measure.Angle getMechanismPosition()Get the mechanism position.- Returns:
- mechanism angle.
-
setMechanismPosition
void setMechanismPosition(org.wpilib.units.measure.Angle position) Set the Mechanism position- Parameters:
position- Position of the mechanism.
-
getRotorPosition
org.wpilib.units.measure.Angle getRotorPosition()Get the rotor position.- Returns:
- rotor position.
-
getMechanismVelocity
org.wpilib.units.measure.AngularVelocity getMechanismVelocity()Get the mechanism velocity.- Returns:
- Mechanism velocity.
-
setMechanismVelocity
void setMechanismVelocity(org.wpilib.units.measure.AngularVelocity velocity) Set the Mechanism velocity.- Parameters:
velocity- Mechanism velocity.
-
getRotorVelocity
org.wpilib.units.measure.AngularVelocity getRotorVelocity()Get the rotor velocity.- Returns:
- rotor velocity.
-
getStatorCurrent
org.wpilib.units.measure.Current getStatorCurrent()Get the stator current draw of from the sim.- Returns:
- stator current draw.
-
getSupplyCurrent
org.wpilib.units.measure.Current getSupplyCurrent()Get the supply current draw of the motor controller.- Returns:
- supply current draw.
-
getRotorAcceleration
org.wpilib.units.measure.AngularAcceleration getRotorAcceleration()Get the rotor acceleration.- Returns:
- Rotor acceleration.
-