Class DCMotorSimSupplier

java.lang.Object
yams.core.motorcontrollers.simulation.DCMotorSimSupplier
All Implemented Interfaces:
SimSupplier

public class DCMotorSimSupplier extends Object implements 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 Details

    • DCMotorSimSupplier

      public DCMotorSimSupplier(org.wpilib.simulation.DCMotorSim simulation, SmartMotorController smartMotorController)
      Construct the DCMotorSim supplier
      Parameters:
      simulation - Simulatoin instance
      smartMotorController - SMC for the DCMotorSim..
  • Method Details

    • updateSimState

      public void updateSimState()
      Description copied from interface: SimSupplier
      Update the sim state.
      Specified by:
      updateSimState in interface SimSupplier
    • getUpdatedSim

      public boolean getUpdatedSim()
      Description copied from interface: SimSupplier
      Get the updated sim watchdog.
      Specified by:
      getUpdatedSim in interface SimSupplier
      Returns:
      Updated sim.
    • feedUpdateSim

      public void feedUpdateSim()
      Description copied from interface: SimSupplier
      Feed the update sim watch
      Specified by:
      feedUpdateSim in interface SimSupplier
    • starveUpdateSim

      public void starveUpdateSim()
      Description copied from interface: SimSupplier
      Starve the update sim watch.
      Specified by:
      starveUpdateSim in interface SimSupplier
    • isInputFed

      public boolean isInputFed()
      Description copied from interface: SimSupplier
      Check if the input was fed.
      Specified by:
      isInputFed in interface SimSupplier
      Returns:
      Input fed.
    • feedInput

      public void feedInput()
      Description copied from interface: SimSupplier
      Feed input
      Specified by:
      feedInput in interface SimSupplier
    • starveInput

      public void starveInput()
      Description copied from interface: SimSupplier
      Starve the input.
      Specified by:
      starveInput in interface SimSupplier
    • setMechanismStatorDutyCycle

      public void setMechanismStatorDutyCycle(double dutyCycle)
      Description copied from interface: SimSupplier
      Set the dutycyle of the mechanism stator.
      Specified by:
      setMechanismStatorDutyCycle in interface SimSupplier
      Parameters:
      dutyCycle - Dutycycle value.
    • getMechanismSupplyVoltage

      public org.wpilib.units.measure.Voltage getMechanismSupplyVoltage()
      Description copied from interface: SimSupplier
      Gets the supply voltage for the motor controller.
      Specified by:
      getMechanismSupplyVoltage in interface SimSupplier
      Returns:
      Supply voltage to the motor controller
    • getMechanismStatorVoltage

      public org.wpilib.units.measure.Voltage getMechanismStatorVoltage()
      Description copied from interface: SimSupplier
      Get the mechanism stator voltage.
      Specified by:
      getMechanismStatorVoltage in interface SimSupplier
      Returns:
      Stator voltage of the mechanism.
    • setMechanismStatorVoltage

      public void setMechanismStatorVoltage(org.wpilib.units.measure.Voltage volts)
      Description copied from interface: SimSupplier
      Set mechanism voltage, mostly used for SysId testing.
      Specified by:
      setMechanismStatorVoltage in interface SimSupplier
      Parameters:
      volts - Voltage to set.
    • getMechanismPosition

      public org.wpilib.units.measure.Angle getMechanismPosition()
      Description copied from interface: SimSupplier
      Get the mechanism position.
      Specified by:
      getMechanismPosition in interface SimSupplier
      Returns:
      mechanism angle.
    • setMechanismPosition

      public void setMechanismPosition(org.wpilib.units.measure.Angle position)
      Description copied from interface: SimSupplier
      Set the Mechanism position
      Specified by:
      setMechanismPosition in interface SimSupplier
      Parameters:
      position - Position of the mechanism.
    • getRotorPosition

      public org.wpilib.units.measure.Angle getRotorPosition()
      Description copied from interface: SimSupplier
      Get the rotor position.
      Specified by:
      getRotorPosition in interface SimSupplier
      Returns:
      rotor position.
    • getMechanismVelocity

      public org.wpilib.units.measure.AngularVelocity getMechanismVelocity()
      Description copied from interface: SimSupplier
      Get the mechanism velocity.
      Specified by:
      getMechanismVelocity in interface SimSupplier
      Returns:
      Mechanism velocity.
    • setMechanismVelocity

      public void setMechanismVelocity(org.wpilib.units.measure.AngularVelocity velocity)
      Description copied from interface: SimSupplier
      Set the Mechanism velocity.
      Specified by:
      setMechanismVelocity in interface SimSupplier
      Parameters:
      velocity - Mechanism velocity.
    • getRotorVelocity

      public org.wpilib.units.measure.AngularVelocity getRotorVelocity()
      Description copied from interface: SimSupplier
      Get the rotor velocity.
      Specified by:
      getRotorVelocity in interface SimSupplier
      Returns:
      rotor velocity.
    • getStatorCurrent

      public org.wpilib.units.measure.Current getStatorCurrent()
      Description copied from interface: SimSupplier
      Get the stator current draw of from the sim.
      Specified by:
      getStatorCurrent in interface SimSupplier
      Returns:
      stator current draw.
    • getSupplyCurrent

      public org.wpilib.units.measure.Current getSupplyCurrent()
      Description copied from interface: SimSupplier
      Get the supply current draw of the motor controller.
      Specified by:
      getSupplyCurrent in interface SimSupplier
      Returns:
      supply current draw.
    • getRotorAcceleration

      public org.wpilib.units.measure.AngularAcceleration getRotorAcceleration()
      Description copied from interface: SimSupplier
      Get the rotor acceleration.
      Specified by:
      getRotorAcceleration in interface SimSupplier
      Returns:
      Rotor acceleration.