Class DCMotorSimSupplier
java.lang.Object
yams.core.motorcontrollers.simulation.DCMotorSimSupplier
- All Implemented Interfaces:
SimSupplier
DCMotorSim Supplier simulates a generic DC motor load (flywheel, roller, or elevator)
using WPILib's
DCMotorSim.
This supplier steps WPILib's DCMotorSim physics model each control loop and exposes
the resulting angular position, angular velocity, current draw, and acceleration through the
SimSupplier interface. Unlike
ArmSimSupplier, this model does not simulate gravity or
joint limits it is suited for continuous-rotation mechanisms such as flywheels or rollers, as
well as linear mechanisms (elevators) when paired with appropriate gearing.
The gear ratio and control period are read from the associated
SmartMotorController's config, so they do not need to be repeated
here.
Example
// 1. Build the WPILib DC motor physics model (e.g. a flywheel with MOI 0.001 kg·m²)
DCMotorSim flywheelPhysics = new DCMotorSim(
Models.singleJointedArmFromPhysicalConstants(DCMotor.getNEO(1), 0.001, 1.0),
DCMotor.getNEO(1));
// 2. Configure and build the YAMS smart motor controller
SmartMotorController motor = new SparkMaxController(
new SmartMotorControllerConfig()
.withGearing(new MechanismGearing(1.0))
.withClosedLoopControlPeriod(Milliseconds.of(20)));
// 3. Wrap physics model in the supplier and register it
DCMotorSimSupplier sim = new DCMotorSimSupplier(flywheelPhysics, motor);
motor.getConfig().withSimSupplier(sim);
-
Constructor Summary
ConstructorsConstructorDescriptionDCMotorSimSupplier(org.wpilib.simulation.DCMotorSim simulation, SmartMotorController smartMotorController) Construct the DCMotorSim supplier -
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.
-
Constructor Details
-
DCMotorSimSupplier
public DCMotorSimSupplier(org.wpilib.simulation.DCMotorSim simulation, SmartMotorController smartMotorController) Construct the DCMotorSim supplier- Parameters:
simulation- Simulatoin instancesmartMotorController- SMC for the DCMotorSim..
-
-
Method Details
-
updateSimState
public void updateSimState()Description copied from interface:SimSupplierUpdate the sim state.- Specified by:
updateSimStatein interfaceSimSupplier
-
getUpdatedSim
public boolean getUpdatedSim()Description copied from interface:SimSupplierGet the updated sim watchdog.- Specified by:
getUpdatedSimin interfaceSimSupplier- Returns:
- Updated sim.
-
feedUpdateSim
public void feedUpdateSim()Description copied from interface:SimSupplierFeed the update sim watch- Specified by:
feedUpdateSimin interfaceSimSupplier
-
starveUpdateSim
public void starveUpdateSim()Description copied from interface:SimSupplierStarve the update sim watch.- Specified by:
starveUpdateSimin interfaceSimSupplier
-
isInputFed
public boolean isInputFed()Description copied from interface:SimSupplierCheck if the input was fed.- Specified by:
isInputFedin interfaceSimSupplier- Returns:
- Input fed.
-
feedInput
public void feedInput()Description copied from interface:SimSupplierFeed input- Specified by:
feedInputin interfaceSimSupplier
-
starveInput
public void starveInput()Description copied from interface:SimSupplierStarve the input.- Specified by:
starveInputin interfaceSimSupplier
-
setMechanismStatorDutyCycle
public void setMechanismStatorDutyCycle(double dutyCycle) Description copied from interface:SimSupplierSet the dutycyle of the mechanism stator.- Specified by:
setMechanismStatorDutyCyclein interfaceSimSupplier- Parameters:
dutyCycle- Dutycycle value.
-
getMechanismSupplyVoltage
public org.wpilib.units.measure.Voltage getMechanismSupplyVoltage()Description copied from interface:SimSupplierGets the supply voltage for the motor controller.- Specified by:
getMechanismSupplyVoltagein interfaceSimSupplier- Returns:
- Supply voltage to the motor controller
-
getMechanismStatorVoltage
public org.wpilib.units.measure.Voltage getMechanismStatorVoltage()Description copied from interface:SimSupplierGet the mechanism stator voltage.- Specified by:
getMechanismStatorVoltagein interfaceSimSupplier- Returns:
- Stator voltage of the mechanism.
-
setMechanismStatorVoltage
public void setMechanismStatorVoltage(org.wpilib.units.measure.Voltage volts) Description copied from interface:SimSupplierSet mechanism voltage, mostly used for SysId testing.- Specified by:
setMechanismStatorVoltagein interfaceSimSupplier- Parameters:
volts- Voltage to set.
-
getMechanismPosition
public org.wpilib.units.measure.Angle getMechanismPosition()Description copied from interface:SimSupplierGet the mechanism position.- Specified by:
getMechanismPositionin interfaceSimSupplier- Returns:
- mechanism angle.
-
setMechanismPosition
public void setMechanismPosition(org.wpilib.units.measure.Angle position) Description copied from interface:SimSupplierSet the Mechanism position- Specified by:
setMechanismPositionin interfaceSimSupplier- Parameters:
position- Position of the mechanism.
-
getRotorPosition
public org.wpilib.units.measure.Angle getRotorPosition()Description copied from interface:SimSupplierGet the rotor position.- Specified by:
getRotorPositionin interfaceSimSupplier- Returns:
- rotor position.
-
getMechanismVelocity
public org.wpilib.units.measure.AngularVelocity getMechanismVelocity()Description copied from interface:SimSupplierGet the mechanism velocity.- Specified by:
getMechanismVelocityin interfaceSimSupplier- Returns:
- Mechanism velocity.
-
setMechanismVelocity
public void setMechanismVelocity(org.wpilib.units.measure.AngularVelocity velocity) Description copied from interface:SimSupplierSet the Mechanism velocity.- Specified by:
setMechanismVelocityin interfaceSimSupplier- Parameters:
velocity- Mechanism velocity.
-
getRotorVelocity
public org.wpilib.units.measure.AngularVelocity getRotorVelocity()Description copied from interface:SimSupplierGet the rotor velocity.- Specified by:
getRotorVelocityin interfaceSimSupplier- Returns:
- rotor velocity.
-
getStatorCurrent
public org.wpilib.units.measure.Current getStatorCurrent()Description copied from interface:SimSupplierGet the stator current draw of from the sim.- Specified by:
getStatorCurrentin interfaceSimSupplier- Returns:
- stator current draw.
-
getSupplyCurrent
public org.wpilib.units.measure.Current getSupplyCurrent()Description copied from interface:SimSupplierGet the supply current draw of the motor controller.- Specified by:
getSupplyCurrentin interfaceSimSupplier- Returns:
- supply current draw.
-
getRotorAcceleration
public org.wpilib.units.measure.AngularAcceleration getRotorAcceleration()Description copied from interface:SimSupplierGet the rotor acceleration.- Specified by:
getRotorAccelerationin interfaceSimSupplier- Returns:
- Rotor acceleration.
-