Class LinearMechanismIOTalonFX

java.lang.Object
com.marslib.mechanisms.LinearMechanismIOTalonFX
All Implemented Interfaces:
LinearMechanismIO

public class LinearMechanismIOTalonFX extends Object implements LinearMechanismIO
Hardware binding layer for singular Linear Mechanisms (Elevators, Extensors) utilizing CTRE TalonFX (Kraken/Falcon) motors.

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.

  • 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

      public void updateInputs(LinearMechanismIO.LinearMechanismIOInputs inputs)
      Specified by:
      updateInputs in interface LinearMechanismIO
    • setVoltage

      public void setVoltage(double volts)
      Specified by:
      setVoltage in interface LinearMechanismIO
    • 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:
      setClosedLoopPosition in interface LinearMechanismIO
      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:
      setCurrentLimit in interface LinearMechanismIO
    • setBrakeMode

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