Class LinearSim

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

public class LinearSim extends Object implements Mount, Mountable
WPILib-backed simulation of a linear (elevator-style) mechanism driven by one or more Kraken X60 motors. Updates the TalonFX sim state each robot period and animates both a static backing ligament and a moving stage ligament in a Mechanism2d canvas. Implements Mount so other mechanisms can be attached to the moving stage, and implements Mountable so this stage can itself be attached to a parent mount.
  • Constructor Details

    • LinearSim

      public LinearSim(LinearConfig config, Mechanism2d mech, TalonFXSimState linearMotorSim, String name)
      Creates and registers a linear mechanism simulation.
      Parameters:
      config - physical and display configuration for the linear stage
      mech - the Mechanism2d canvas to draw the stage on
      linearMotorSim - the TalonFX sim state of the motor driving the stage
      name - unique name prefix used for Mechanism2d element labels
  • Method Details

    • getElevatorMech2d

      public MechanismLigament2d getElevatorMech2d()
      Returns the moving stage MechanismLigament2d, useful for attaching additional visual elements.
      Returns:
      the elevator moving-stage ligament
    • simulationPeriodic

      public void simulationPeriodic()
      Advances the elevator physics simulation by one robot period, updates the TalonFX rotor position and velocity, and refreshes both the static and moving Mechanism2d ligaments.
    • getDisplacementX

      public double getDisplacementX()
      Returns the horizontal component of the stage's current displacement from its initial position, accounting for the parent mount's angle when mounted.
      Specified by:
      getDisplacementX in interface Mount
      Returns:
      horizontal displacement in metres
    • getDisplacementY

      public double getDisplacementY()
      Returns the vertical component of the stage's current displacement from its initial position, accounting for the parent mount's angle when mounted.
      Specified by:
      getDisplacementY in interface Mount
      Returns:
      vertical displacement in metres
    • getAngle

      public double getAngle()
      Returns the effective absolute angle of the linear stage in radians, adding the parent mount's angle when mounted.
      Specified by:
      getAngle in interface Mount
      Returns:
      effective stage angle in radians
    • getMountX

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

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

      public LinearConfig getConfig()
      Configuration containing physical properties and display settings for this linear stage.
    • getMountType

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