Package frc.spectrumLib.sim
Class LinearSim
java.lang.Object
frc.spectrumLib.sim.LinearSim
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.-
Nested Class Summary
Nested classes/interfaces inherited from interface frc.spectrumLib.sim.Mount
Mount.MountType -
Constructor Summary
ConstructorsConstructorDescriptionLinearSim(LinearConfig config, Mechanism2d mech, TalonFXSimState linearMotorSim, String name) Creates and registers a linear mechanism simulation. -
Method Summary
Modifier and TypeMethodDescriptiondoublegetAngle()Returns the effective absolute angle of the linear stage in radians, adding the parent mount's angle when mounted.Configuration containing physical properties and display settings for this linear stage.doubleReturns the horizontal component of the stage's current displacement from its initial position, accounting for the parent mount's angle when mounted.doubleReturns the vertical component of the stage's current displacement from its initial position, accounting for the parent mount's angle when mounted.Returns the moving stageMechanismLigament2d, useful for attaching additional visual elements.AlwaysMount.MountType.LINEAR; used by child mechanisms to determine positioning logic.doubleReturns the X coordinate of the static root of this stage, used by child mechanisms as their mount point.doubleReturns the Y coordinate of the static root of this stage, used by child mechanisms as their mount point.voidAdvances the elevator physics simulation by one robot period, updates the TalonFX rotor position and velocity, and refreshes both the static and moving Mechanism2d ligaments.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface frc.spectrumLib.sim.Mountable
getUpdatedX, getUpdatedX, getUpdatedX, getUpdatedX, getUpdatedY, getUpdatedY, getUpdatedY, getUpdatedY
-
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 stagemech- the Mechanism2d canvas to draw the stage onlinearMotorSim- the TalonFX sim state of the motor driving the stagename- unique name prefix used for Mechanism2d element labels
-
-
Method Details
-
getElevatorMech2d
Returns the moving stageMechanismLigament2d, 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:
getDisplacementXin interfaceMount- 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:
getDisplacementYin interfaceMount- 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. -
getMountX
public double getMountX()Returns the X coordinate of the static root of this stage, used by child mechanisms as their mount point. -
getMountY
public double getMountY()Returns the Y coordinate of the static root of this stage, used by child mechanisms as their mount point. -
getConfig
Configuration containing physical properties and display settings for this linear stage. -
getMountType
AlwaysMount.MountType.LINEAR; used by child mechanisms to determine positioning logic.- Specified by:
getMountTypein interfaceMount- Returns:
- this mount's
Mount.MountType
-