Class ArmSimSupplier

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

public class ArmSimSupplier extends Object implements SimSupplier
ArmSim Supplier simulates a single-jointed arm mechanism using WPILib's SingleJointedArmSim.

This supplier steps WPILib's SingleJointedArmSim physics model each control loop and exposes the resulting angle, angular velocity, current draw, and voltage through the SimSupplier interface. The arm's gear ratio and control period are read directly from the associated SmartMotorController's config, so no duplication of parameters is required.

Example

// 1. Build the WPILib arm physics model
SingleJointedArmSim armPhysics = new SingleJointedArmSim(
    DCMotor.getNEO(1),
    SingleJointedArmSim.estimateMOI(0.5, 2.0), // moment of inertia (kg·m²)
    5.0,                                         // gear ratio (rotor/mechanism)
    0.5,                                         // arm length (meters)
    Units.degreesToRadians(-10),                 // min angle (radians)
    Units.degreesToRadians(90),                  // max angle (radians)
    true,                                        // simulate gravity
    0);                                          // starting angle (radians)

// 2. Configure and build the YAMS smart motor controller
SmartMotorController motor = new SparkMaxController(
    new SmartMotorControllerConfig()
        .withGearing(new MechanismGearing(5.0))
        .withClosedLoopControlPeriod(Milliseconds.of(20)));

// 3. Wrap physics model in the supplier and register it
ArmSimSupplier sim = new ArmSimSupplier(armPhysics, motor);
motor.getConfig().withSimSupplier(sim);
  • Constructor Details

    • ArmSimSupplier

      public ArmSimSupplier(org.wpilib.simulation.SingleJointedArmSim simulation, SmartMotorController smartMotorController)
      Construct the ArmSim supplier
      Parameters:
      simulation - Simulatoin instance
      smartMotorController - SMC for the ArmSim..
  • 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.