Class ElevatorSimSupplier

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

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

    • ElevatorSimSupplier

      public ElevatorSimSupplier(org.wpilib.simulation.ElevatorSim simulation, SmartMotorController smartMotorController)
      Construct the ElevatorSim supplier
      Parameters:
      simulation - Simulation instance
      smartMotorController - SMC for the ElevatorSim.
  • 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()
      Get the mechanism position.
      Specified by:
      getMechanismPosition in interface SimSupplier
      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:
      setMechanismPosition in interface SimSupplier
      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:
      getRotorPosition in interface SimSupplier
      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:
      getMechanismVelocity in interface SimSupplier
      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:
      setMechanismVelocity in interface SimSupplier
      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:
      getRotorVelocity in interface SimSupplier
      Returns:
      rotor velocity.
      Throws:
      SmartMotorControllerConfigurationException - if the mechanism circumference is not configured.
    • 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()
      Get the rotor acceleration.
      Specified by:
      getRotorAcceleration in interface SimSupplier
      Returns:
      Rotor acceleration.
      Throws:
      SmartMotorControllerConfigurationException - if the mechanism circumference is not configured.