Class SimMotorState

java.lang.Object
org.ironmaple.simulation.motorsims.SimMotorState

public class SimMotorState extends Object

Represents the state of a simulated motor at a given point in time.

This record holds the final angular position and velocity of the motor. It is used to track the motor's state during each simulation step.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    edu.wpi.first.units.measure.Angle
     
    edu.wpi.first.units.measure.AngularVelocity
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    SimMotorState(edu.wpi.first.units.measure.Angle mechanismAngularPosition, edu.wpi.first.units.measure.AngularVelocity mechanismAngularVelocity)
    Constructs a new sim motor state with initial angle and velocity
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    step(edu.wpi.first.units.measure.Torque finalElectricTorque, edu.wpi.first.units.measure.Torque finalFrictionTorque, edu.wpi.first.units.measure.MomentOfInertia loadMOI, edu.wpi.first.units.measure.Time dt)
    Simulates a step in the motor's motion based on the applied forces.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • mechanismAngularPosition

      public edu.wpi.first.units.measure.Angle mechanismAngularPosition
    • mechanismAngularVelocity

      public edu.wpi.first.units.measure.AngularVelocity mechanismAngularVelocity
  • Constructor Details

    • SimMotorState

      public SimMotorState(edu.wpi.first.units.measure.Angle mechanismAngularPosition, edu.wpi.first.units.measure.AngularVelocity mechanismAngularVelocity)

      Constructs a new sim motor state with initial angle and velocity

      Parameters:
      mechanismAngularPosition - the final angular position of the motor, in radians
      mechanismAngularVelocity - the final angular velocity of the motor, in radians per second
  • Method Details

    • step

      public void step(edu.wpi.first.units.measure.Torque finalElectricTorque, edu.wpi.first.units.measure.Torque finalFrictionTorque, edu.wpi.first.units.measure.MomentOfInertia loadMOI, edu.wpi.first.units.measure.Time dt)

      Simulates a step in the motor's motion based on the applied forces.

      This method calculates the new angular position and velocity of the motor after applying electric and frictional torques over a time step.

      The method follows these steps:

      • Convert all units to SI units for calculation.
      • Apply the electric torque to the current angular velocity.
      • Compute the change in angular velocity due to friction.
      • If friction reverses the direction of angular velocity, the velocity is set to zero.
      • Integrate the angular velocity to find the new position.
      Parameters:
      finalElectricTorque - the final applied electric torque, in Newton-meters
      finalFrictionTorque - the final frictional torque, in Newton-meters
      loadMOI - the moment of inertia of the load, in kilogram square meters
      dt - the time step for the simulation, in seconds