Class LinearMechanismIOTalonFX
- All Implemented Interfaces:
LinearMechanismIO
Students: This IO class natively integrates CTRE's Phoenix 6 API identically to the Rotary layer, except it manages the `spoolDiameterMeters` allowing it to physically convert Motor Rotations into absolute Metric Extents (meters).
Phoenix 6 runs current limits natively on the stator coil at 1000Hz (1kHz) providing robust
physical limits. 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.LinearMechanismIO
LinearMechanismIO.LinearMechanismIOInputs -
Constructor Summary
ConstructorsConstructorDescriptionLinearMechanismIOTalonFX(int leaderId, int[] followerIds, boolean[] opposeLeader, String canbus, double gearRatio, double spoolDiameterMeters, boolean inverted) LinearMechanismIOTalonFX(int motorId, String canbus, double gearRatio, double spoolDiameterMeters, boolean inverted) Initializes the TalonFX hardware and pre-configures Linear MotionMagic parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoidsetBrakeMode(boolean enable) voidsetClosedLoopPosition(double positionMeters, double feedforwardVolts) Pushes a target state using Phoenix 6 Motion Magic.voidsetCurrentLimit(double amps) voidsetVoltage(double volts) void
-
Constructor Details
-
LinearMechanismIOTalonFX
public LinearMechanismIOTalonFX(int motorId, String canbus, double gearRatio, double spoolDiameterMeters, boolean inverted) Initializes the TalonFX hardware and pre-configures Linear MotionMagic parameters.- 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 spool.spoolDiameterMeters- The physical diameter of the output spool pulling the belt/string.inverted- Whether positive rotation extends the mechanism outward.
-
LinearMechanismIOTalonFX
public LinearMechanismIOTalonFX(int leaderId, int[] followerIds, boolean[] opposeLeader, String canbus, double gearRatio, double spoolDiameterMeters, boolean inverted)
-
-
Method Details
-
updateInputs
- Specified by:
updateInputsin interfaceLinearMechanismIO
-
setVoltage
public void setVoltage(double volts) - Specified by:
setVoltagein interfaceLinearMechanismIO
-
setClosedLoopPosition
public void setClosedLoopPosition(double positionMeters, double feedforwardVolts) Pushes a target state using Phoenix 6 Motion Magic.Students: The target parameter `positionMeters` is passed natively as Extent Meters. This class handles scaling that value up through the Spool Circumference and Gear Ratio automatically so the TalonFX understands how many internal motor rotations it must make to drive the elevator to your target height.
- Specified by:
setClosedLoopPositionin interfaceLinearMechanismIO- Parameters:
positionMeters- The target extension length of the mechanism (meters).feedforwardVolts- Dynamic SysId feedforward volts (usually Gravity compensation) aiding the onboard PID.
-
setCurrentLimit
public void setCurrentLimit(double amps) - Specified by:
setCurrentLimitin interfaceLinearMechanismIO
-
setBrakeMode
public void setBrakeMode(boolean enable) - Specified by:
setBrakeModein interfaceLinearMechanismIO
-