Class ArmSim

java.lang.Object
frc.spectrumLib.sim.ArmSim
All Implemented Interfaces:
Mount, Mountable

public class ArmSim extends Object implements Mount, Mountable
WPILib-backed simulation of a single-jointed arm driven by one or more Kraken X60 motors. Updates the TalonFX sim state each robot period and animates the arm in a Mechanism2d canvas. Implements Mount so other mechanisms can be attached to this arm's tip, and implements Mountable so this arm can itself be attached to a parent mount.
  • Constructor Details

    • ArmSim

      public ArmSim(ArmConfig config, Mechanism2d mech, TalonFXSimState armMotorSim, String name)
      Creates and registers an arm simulation.
      Parameters:
      config - physical and display configuration for the arm
      mech - the Mechanism2d canvas to draw the arm on
      armMotorSim - the TalonFX sim state of the motor driving the arm
      name - unique name prefix used for Mechanism2d element labels
  • Method Details

    • simulationPeriodic

      public void simulationPeriodic()
      Advances the arm physics simulation by one robot period, updates the TalonFX rotor position and velocity, and refreshes the Mechanism2d visualization.
    • getAngleRads

      public double getAngleRads()
      Returns the current arm angle from the WPILib physics simulation.
      Returns:
      arm angle in radians
    • getDisplacementX

      public double getDisplacementX()
      Returns how far the pivot has moved horizontally from its initial position.
      Specified by:
      getDisplacementX in interface Mount
      Returns:
      horizontal displacement in metres
    • getDisplacementY

      public double getDisplacementY()
      Returns how far the pivot has moved vertically from its initial position.
      Specified by:
      getDisplacementY in interface Mount
      Returns:
      vertical displacement in metres
    • getAngle

      public double getAngle()
      Returns the effective arm angle accounting for the parent mount's angle when mounted and not using an absolute angle reference.
      Specified by:
      getAngle in interface Mount
      Returns:
      effective arm angle in radians
    • getMountX

      public double getMountX()
      Returns the X coordinate of the arm pivot, used by child mechanisms as their mount point.
      Specified by:
      getMountX in interface Mount
      Returns:
      pivot X position in metres
    • getMountY

      public double getMountY()
      Returns the Y coordinate of the arm pivot, used by child mechanisms as their mount point.
      Specified by:
      getMountY in interface Mount
      Returns:
      pivot Y position in metres
    • getConfig

      public ArmConfig getConfig()
      Configuration containing physical properties and display settings for this arm.
    • getMountType

      public Mount.MountType getMountType()
      Always Mount.MountType.ARM; used by child mechanisms to determine positioning logic.
      Specified by:
      getMountType in interface Mount
      Returns:
      this mount's Mount.MountType