Class SimMotor

java.lang.Object
frc.spectrumLib.sim.SimMotor

public final class SimMotor extends Object
Shared wiring between a TalonFX and the WPILib physics sims in this package.
  • Method Details

    • simState

      public static TalonFXSimState simState(TalonFX motor, boolean reversedLinkage)
      Returns the motor's sim state, flipping Orientation when the sim's travel runs opposite the motor's positive direction.

      The physics sims here are driven by getMotorVoltage() and feed position back through setRawRotorPosition(); Orientation negates both as a matched pair, so flipping it mirrors the whole loop and leaves it self-consistent.

      Deliberately not derived from the motor's invert. CTRE documents Orientation as describing mechanical linkage, not the invert, and the invert alone does not determine the sign. What matters is the direction each sim's geometry produces:

      • ElevatorSim travels [minHeight, max] with min normally 0, so its rotor term is always positive.
      • ArmSim feeds back angle - startingAngle, which is negative whenever the arm starts at its maximum.

      So an inverted motor is fine on a sim whose geometry already runs negative, and broken on one that runs positive: the model clamps at its limit, feeds the same position back, and the mechanism never moves. Only the mechanism author knows which case applies, hence the explicit per-sim flag.

      Parameters:
      motor - the motor driving the simulated mechanism
      reversedLinkage - true when the sim's travel opposes the motor's positive direction
      Returns:
      the motor's (cached) sim state, with orientation set