Package frc.spectrumLib.sim
Class ArmSim
java.lang.Object
frc.spectrumLib.sim.ArmSim
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.-
Nested Class Summary
Nested classes/interfaces inherited from interface frc.spectrumLib.sim.Mount
Mount.MountType -
Constructor Summary
ConstructorsConstructorDescriptionArmSim(ArmConfig config, Mechanism2d mech, TalonFXSimState armMotorSim, String name) Creates and registers an arm simulation. -
Method Summary
Modifier and TypeMethodDescriptiondoublegetAngle()Returns the effective arm angle accounting for the parent mount's angle when mounted and not using an absolute angle reference.doubleReturns the current arm angle from the WPILib physics simulation.Configuration containing physical properties and display settings for this arm.doubleReturns how far the pivot has moved horizontally from its initial position.doubleReturns how far the pivot has moved vertically from its initial position.AlwaysMount.MountType.ARM; used by child mechanisms to determine positioning logic.doubleReturns the X coordinate of the arm pivot, used by child mechanisms as their mount point.doubleReturns the Y coordinate of the arm pivot, used by child mechanisms as their mount point.voidAdvances the arm physics simulation by one robot period, updates the TalonFX rotor position and velocity, and refreshes the Mechanism2d visualization.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
-
ArmSim
Creates and registers an arm simulation.- Parameters:
config- physical and display configuration for the armmech- the Mechanism2d canvas to draw the arm onarmMotorSim- the TalonFX sim state of the motor driving the armname- 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:
getDisplacementXin interfaceMount- Returns:
- horizontal displacement in metres
-
getDisplacementY
public double getDisplacementY()Returns how far the pivot has moved vertically from its initial position.- Specified by:
getDisplacementYin interfaceMount- 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. -
getMountX
public double getMountX()Returns the X coordinate of the arm pivot, used by child mechanisms as their mount point. -
getMountY
public double getMountY()Returns the Y coordinate of the arm pivot, used by child mechanisms as their mount point. -
getConfig
Configuration containing physical properties and display settings for this arm. -
getMountType
AlwaysMount.MountType.ARM; used by child mechanisms to determine positioning logic.- Specified by:
getMountTypein interfaceMount- Returns:
- this mount's
Mount.MountType
-