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 Mount
Mount.MountType -
Constructor Summary
ConstructorsConstructorDescriptionArmSim(ArmConfig config, Mechanism2d mech, TalonFX motor, 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.voidupdate(double dt) Advances the arm physics simulation by one robot period, updates the TalonFX rotor position and velocity, and refreshes the Mechanism2d visualization.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface 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 onmotor- the TalonFX driving the armname- unique name prefix used for Mechanism2d element labels
-
-
Method Details
-
update
public void update(double dt) 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
-
getMountX
-
getMountY
-
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
-