Class RotaryMechanismIOTalonFX

java.lang.Object
com.marslib.mechanisms.RotaryMechanismIOTalonFX
All Implemented Interfaces:
RotaryMechanismIO

public class RotaryMechanismIOTalonFX extends Object implements 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.

  • Constructor Details

    • RotaryMechanismIOTalonFX

      public RotaryMechanismIOTalonFX(int motorId, String canbus, double gearRatio, boolean inverted)
      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

      public void updateInputs(RotaryMechanismIO.RotaryMechanismIOInputs inputs)
      Specified by:
      updateInputs in interface RotaryMechanismIO
    • setVoltage

      public void setVoltage(double volts)
      Specified by:
      setVoltage in interface RotaryMechanismIO
    • 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:
      setClosedLoopPosition in interface RotaryMechanismIO
      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: RotaryMechanismIO
      Resets the internal encoder to a given position.
      Specified by:
      setEncoderPosition in interface RotaryMechanismIO
    • setCurrentLimit

      public void setCurrentLimit(double amps)
      Specified by:
      setCurrentLimit in interface RotaryMechanismIO
    • setBrakeMode

      public void setBrakeMode(boolean enable)
      Specified by:
      setBrakeMode in interface RotaryMechanismIO