Class ElevatorSimSupplier
java.lang.Object
yams.core.motorcontrollers.simulation.ElevatorSimSupplier
- All Implemented Interfaces:
SimSupplier
ElevatorSim Supplier simulates an elevator mechanism using WPILib's
ElevatorSim.
This supplier steps WPILib's ElevatorSim physics model each control loop and exposes
the resulting height, linear velocity, current draw, and voltage through the
SimSupplier interface. Because ElevatorSim operates in linear
units (meters), positions and velocities are converted to and from mechanism (angular) units
using the associated SmartMotorController's config.
Example
// 1. Build the WPILib elevator physics model
ElevatorSim elevatorPhysics = new ElevatorSim(
DCMotor.getNEO(1),
10.0, // gear ratio (rotor/mechanism)
5.0, // carriage mass (kg)
Units.inchesToMeters(1.0), // drum radius (meters)
0.0, // minimum height (meters)
1.5, // maximum height (meters)
true, // simulate gravity
0.0); // starting height (meters)
// 2. Configure and build the YAMS smart motor controller
SmartMotorController motor = new SparkMaxController(
new SmartMotorControllerConfig()
.withGearing(new MechanismGearing(10.0))
.withClosedLoopControlPeriod(Milliseconds.of(20)));
// 3. Wrap physics model in the supplier and register it
ElevatorSimSupplier sim = new ElevatorSimSupplier(elevatorPhysics, motor);
motor.getConfig().withSimSupplier(sim);
-
Constructor Summary
ConstructorsConstructorDescriptionElevatorSimSupplier(org.wpilib.simulation.ElevatorSim simulation, SmartMotorController smartMotorController) Construct the ElevatorSim 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
-
ElevatorSimSupplier
public ElevatorSimSupplier(org.wpilib.simulation.ElevatorSim simulation, SmartMotorController smartMotorController) Construct the ElevatorSim supplier- Parameters:
simulation- Simulation instancesmartMotorController- SMC for the ElevatorSim.
-
-
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()Get the mechanism position.- Specified by:
getMechanismPositionin interfaceSimSupplier- Returns:
- mechanism angle.
- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
setMechanismPosition
public void setMechanismPosition(org.wpilib.units.measure.Angle position) Set the Mechanism position- Specified by:
setMechanismPositionin interfaceSimSupplier- Parameters:
position- Position of the mechanism.- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
getRotorPosition
public org.wpilib.units.measure.Angle getRotorPosition()Get the rotor position.- Specified by:
getRotorPositionin interfaceSimSupplier- Returns:
- rotor position.
- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
getMechanismVelocity
public org.wpilib.units.measure.AngularVelocity getMechanismVelocity()Get the mechanism velocity.- Specified by:
getMechanismVelocityin interfaceSimSupplier- Returns:
- Mechanism velocity.
- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
setMechanismVelocity
public void setMechanismVelocity(org.wpilib.units.measure.AngularVelocity velocity) Set the Mechanism velocity.- Specified by:
setMechanismVelocityin interfaceSimSupplier- Parameters:
velocity- Mechanism velocity.- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
getRotorVelocity
public org.wpilib.units.measure.AngularVelocity getRotorVelocity()Get the rotor velocity.- Specified by:
getRotorVelocityin interfaceSimSupplier- Returns:
- rotor velocity.
- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-
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()Get the rotor acceleration.- Specified by:
getRotorAccelerationin interfaceSimSupplier- Returns:
- Rotor acceleration.
- Throws:
SmartMotorControllerConfigurationException- if the mechanism circumference is not configured.
-