Package com.marslib.mechanisms
Class RotaryMechanismIOTalonFX
java.lang.Object
com.marslib.mechanisms.RotaryMechanismIOTalonFX
- All Implemented Interfaces:
RotaryMechanismIO
Hardware binding layer for singular Rotary Mechanisms utilizing CTRE TalonFX (Kraken/Falcon)
motors.
Students: This IO class natively integrates CTRE's Phoenix 6 API. Notice how we use
`StatusSignal` to fetch velocity and positions. Phoenix 6 runs Odometry internally at 1000Hz
(1kHz) natively. When calling setClosedLoopPosition(double, double), this layer leverages Phoenix 6
"Motion Magic", which is a trapezoidal profile generator running physically on the motor
controller directly.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.marslib.mechanisms.RotaryMechanismIO
RotaryMechanismIO.RotaryMechanismIOInputs -
Constructor Summary
ConstructorsConstructorDescriptionRotaryMechanismIOTalonFX(int motorId, String canbus, double gearRatio, boolean inverted) Initializes the TalonFX hardware and pre-configures MotionMagic. -
Method Summary
Modifier and TypeMethodDescriptionvoidsetBrakeMode(boolean enable) voidsetClosedLoopPosition(double positionRad, double feedforwardVolts) Pushes a target state using Phoenix 6 Motion Magic.voidsetCurrentLimit(double amps) voidsetEncoderPosition(double positionRad) Resets the internal encoder to a given position.voidsetVoltage(double volts) void
-
Constructor Details
-
RotaryMechanismIOTalonFX
Initializes the TalonFX hardware and pre-configures MotionMagic.- Parameters:
motorId- The physical CAN ID of the TalonFX.canbus- The CANBus string (e.g. "rio" or "canivore").gearRatio- Total mechanical gear reduction from the motor to the output shaft (e.g. 10.0 for 10:1).inverted- Whether the positive motor rotation direction drives the mechanism "forward".
-
-
Method Details
-
updateInputs
- Specified by:
updateInputsin interfaceRotaryMechanismIO
-
setVoltage
public void setVoltage(double volts) - Specified by:
setVoltagein interfaceRotaryMechanismIO
-
setClosedLoopPosition
public void setClosedLoopPosition(double positionRad, double feedforwardVolts) Pushes a target state using Phoenix 6 Motion Magic.Students: The target parameter `positionRad` is passed as pure mechanism Radians. This class handles scaling that value up through the Gear Ratio automatically so the physical TalonFX understands how many raw Motor Rotations it needs to accomplish to hit your target.
- Specified by:
setClosedLoopPositionin interfaceRotaryMechanismIO- Parameters:
positionRad- The target angle of the total mechanism (radians).feedforwardVolts- Dynamic SysId feedforward volts aiding the onboard PID.
-
setEncoderPosition
public void setEncoderPosition(double positionRad) Description copied from interface:RotaryMechanismIOResets the internal encoder to a given position.- Specified by:
setEncoderPositionin interfaceRotaryMechanismIO
-
setCurrentLimit
public void setCurrentLimit(double amps) - Specified by:
setCurrentLimitin interfaceRotaryMechanismIO
-
setBrakeMode
public void setBrakeMode(boolean enable) - Specified by:
setBrakeModein interfaceRotaryMechanismIO
-