Class Mechanism

java.lang.Object
frc.spectrumLib.mechanism.Mechanism
All Implemented Interfaces:
Subsystem
Direct Known Subclasses:
FuelIntake, Hood, IndexerBed, IndexerTower, IntakeExtension, IntakeExtension.IntakeExtensionRight, Launcher

public abstract class Mechanism extends Object implements Subsystem
Abstract base class representing a CTRE TalonFX-driven robot mechanism with common control modes, telemetry, and convenience Command factories.

This class centralizes:

  • Motor creation/configuration (leader + optional followers) via the provided Mechanism.Config
  • Cached sensor readings (position, velocity, voltage, current) for efficient access
  • Common unit conversions (rotations/percent/degrees; RPS/RPM)
  • Standard closed-loop and open-loop control helpers (Motion Magic, velocity, voltage, percent, torque current)
  • Convenience Trigger factories (at/above/below thresholds)
  • Basic periodic current reporting to a battery/current logger

Attachment semantics

If Mechanism.Config.isAttached() is false, the mechanism will not attempt to construct or command hardware and will return safe default sensor values (typically 0).

Target tracking

The target field tracks the last commanded closed-loop setpoint sent by this class. It is used by helper triggers such as atTargetPosition(...).

Tracking stop

A mechanism whose config sets a tracking tolerance (Mechanism.Config.configPositionTrackingStop(double, double, boolean), Mechanism.Config.configVelocityTrackingStop(double, double, boolean)) logs TrackingError and TrackingFault under Mechanisms/<name>/. With Mechanism.Config.isTrackingStopEnabled() it also latches to neutral on a fault, until disabled or clearTrackingStop(). See TrackingStop.

Extending

Concrete mechanisms should provide a Mechanism.Config describing motor IDs, Talon configuration, follower configuration, and mechanism-specific min/max rotation bounds as needed.

Note: This class assumes CTRE Phoenix 6 units (rotations, rotations/sec, etc.) and uses Config.talonConfig.Feedback.SensorToMechanismRatio as the mechanism gearing ratio.

  • Field Details

    • motor

      protected TalonFX motor
      The primary (leader) TalonFX motor controller.
    • followerMotors

      protected TalonFX[] followerMotors
      Optional follower TalonFX motor controllers that mirror the leader.
    • config

      public Mechanism.Config config
      Configuration object holding motor IDs, Talon settings, and mechanism parameters.
  • Constructor Details

    • Mechanism

      protected Mechanism(Mechanism.Config config)
      Creates a Mechanism and, if Mechanism.Config.isAttached() is true, initializes the leader TalonFX and any configured follower motors. Sensor caches are always initialized so safe defaults (0) are returned even when unattached.
      Parameters:
      config - the mechanism configuration (motor IDs, Talon settings, follower config, etc.)
    • Mechanism

      protected Mechanism(Mechanism.Config config, boolean attached)
      Creates a Mechanism and explicitly overrides the attached flag in the config.
      Parameters:
      config - the mechanism configuration
      attached - true to enable hardware; false to run in software-only mode
  • Method Details

    • all

      public static List<Mechanism> all()
      Every mechanism constructed so far, in construction order, e.g. for pre-match checks.
      Returns:
      an unmodifiable view
    • periodic

      public void periodic()
      Called once per scheduler loop. Concrete subclasses should override to implement their periodic state-machine logic, telemetry, and sensor updates.
      Specified by:
      periodic in interface Subsystem
    • simulationPeriodic

      public void simulationPeriodic()
      Called once per simulation loop. Concrete subclasses should override to update simulation state (e.g., physics model inputs).
      Specified by:
      simulationPeriodic in interface Subsystem
    • getName

      public String getName()
      Returns the human-readable name of this mechanism, as defined in its Mechanism.Config.
      Specified by:
      getName in interface Subsystem
      Returns:
      the mechanism name
    • isAttached

      public boolean isAttached()
      Returns true if physical hardware is attached and motor commands should be sent.
      Returns:
      true when hardware is available
    • isMotorConnected

      public boolean isMotorConnected()
      Returns true when the leader motor is attached and its status frames are arriving over CAN. A mechanism that is commanded but reports 0 V with this false has dropped off the bus, which is what the hood did intermittently on the 2026-09-04 bench.
      Returns:
      true if the leader TalonFX is currently reachable
    • logBatteryUsage

      public void logBatteryUsage()
      Reports the combined supply current draw of the leader motor and all followers to the battery logger. Does nothing if the mechanism is not attached.
    • getCurrentCommandName

      protected String getCurrentCommandName()
      Returns the name of the command currently scheduled on this subsystem, or "none" if no command is running.
      Returns:
      the current command name
    • runningDefaultCommand

      public Trigger runningDefaultCommand()
      Returns a Trigger that is active whenever this subsystem's current command is its default command.
      Returns:
      trigger that is true while the default command is running
    • getTarget

      public double getTarget()
      Returns the last closed-loop setpoint (in rotations) sent to the motor by this class.
      Returns:
      the most recent target position in rotations
    • getVelocityTargetRPS

      public double getVelocityTargetRPS()
      Returns the last closed-loop velocity setpoint (in rotations per second) sent to the motor by this class.
      Returns:
      the most recent target velocity in rotations per second
    • atTargetPosition

      public Trigger atTargetPosition(DoubleSupplier tolerance)
      Returns a Trigger that is active when the motor is within tolerance rotations of the last commanded target position.
      Parameters:
      tolerance - maximum allowable error in rotations
      Returns:
      trigger that is true when position error is within tolerance
    • isAtTargetPosition

      public boolean isAtTargetPosition(DoubleSupplier tolerance)
      Returns true when the motor is within tolerance rotations of the last commanded target position.
      Parameters:
      tolerance - maximum allowable error in rotations
      Returns:
      true when position error is within tolerance
    • atRotations

      public Trigger atRotations(DoubleSupplier target, DoubleSupplier tolerance)
      Returns a Trigger that is active when the motor position is within tolerance of target (both in rotations).
      Parameters:
      target - the desired position in rotations
      tolerance - maximum allowable error in rotations
      Returns:
      trigger that is true when position is within tolerance of target
    • isAtRotations

      public boolean isAtRotations(DoubleSupplier target, DoubleSupplier tolerance)
      Returns true when the motor position is within tolerance of target (both in rotations).
      Parameters:
      target - the desired position in rotations
      tolerance - maximum allowable error in rotations
      Returns:
      true when position is within tolerance of target
    • belowRotations

      public Trigger belowRotations(DoubleSupplier target, DoubleSupplier tolerance)
      Returns a Trigger that is active when the motor position is below target + tolerance rotations.
      Parameters:
      target - reference position in rotations
      tolerance - offset added to target to form the upper bound
      Returns:
      trigger that is true when position is below the threshold
    • aboveRotations

      public Trigger aboveRotations(DoubleSupplier target, DoubleSupplier tolerance)
      Returns a Trigger that is active when the motor position is above target - tolerance rotations.
      Parameters:
      target - reference position in rotations
      tolerance - offset subtracted from target to form the lower bound
      Returns:
      trigger that is true when position is above the threshold
    • atPercentage

      public Trigger atPercentage(DoubleSupplier target, DoubleSupplier tolerance)
      Returns a Trigger that is active when the motor position is within tolerance of target (both as a percentage of max rotations).
      Parameters:
      target - the desired position as a percentage of max rotations
      tolerance - maximum allowable error as a percentage
      Returns:
      trigger that is true when position is within tolerance of target
    • belowPercentage

      public Trigger belowPercentage(DoubleSupplier target, DoubleSupplier tolerance)
      Returns a Trigger that is active when the motor position is below target + tolerance (as a percentage of max rotations).
      Parameters:
      target - reference position as a percentage
      tolerance - offset added to target to form the upper bound
      Returns:
      trigger that is true when position is below the threshold
    • abovePercentage

      public Trigger abovePercentage(DoubleSupplier target, DoubleSupplier tolerance)
      Returns a Trigger that is active when the motor position is above target - tolerance (as a percentage of max rotations).
      Parameters:
      target - reference position as a percentage
      tolerance - offset subtracted from target to form the lower bound
      Returns:
      trigger that is true when position is above the threshold
    • atDegrees

      public Trigger atDegrees(DoubleSupplier target, DoubleSupplier tolerance)
      Returns a Trigger that is active when the motor position is within tolerance of target (both in degrees).
      Parameters:
      target - the desired position in degrees
      tolerance - maximum allowable error in degrees
      Returns:
      trigger that is true when position is within tolerance of target
    • belowDegrees

      public Trigger belowDegrees(DoubleSupplier target, DoubleSupplier tolerance)
      Returns a Trigger that is active when the motor position is below target + tolerance degrees.
      Parameters:
      target - reference position in degrees
      tolerance - offset added to target to form the upper bound
      Returns:
      trigger that is true when position is below the threshold
    • aboveDegrees

      public Trigger aboveDegrees(DoubleSupplier target, DoubleSupplier tolerance)
      Returns a Trigger that is active when the motor position is above target - tolerance degrees.
      Parameters:
      target - reference position in degrees
      tolerance - offset subtracted from target to form the lower bound
      Returns:
      trigger that is true when position is above the threshold
    • atVelocityRPM

      public Trigger atVelocityRPM(DoubleSupplier target, DoubleSupplier tolerance)
      Returns a Trigger that is active when the motor velocity is within tolerance RPM of target.
      Parameters:
      target - the desired velocity in RPM
      tolerance - maximum allowable error in RPM
      Returns:
      trigger that is true when velocity is within tolerance of target
    • belowVelocityRPM

      public Trigger belowVelocityRPM(DoubleSupplier target, DoubleSupplier tolerance)
      Returns a Trigger that is active when the motor velocity is below target + tolerance RPM.
      Parameters:
      target - reference velocity in RPM
      tolerance - offset added to target to form the upper bound
      Returns:
      trigger that is true when velocity is below the threshold
    • aboveVelocityRPM

      public Trigger aboveVelocityRPM(DoubleSupplier target, DoubleSupplier tolerance)
      Returns a Trigger that is active when the motor velocity is above target - tolerance RPM.
      Parameters:
      target - reference velocity in RPM
      tolerance - offset subtracted from target to form the lower bound
      Returns:
      trigger that is true when velocity is above the threshold
    • atCurrent

      public Trigger atCurrent(DoubleSupplier target, DoubleSupplier tolerance)
      Returns a Trigger that is active when the motor stator current is within tolerance amps of target.
      Parameters:
      target - the desired stator current in amps
      tolerance - maximum allowable error in amps
      Returns:
      trigger that is true when stator current is within tolerance of target
    • belowCurrent

      public Trigger belowCurrent(DoubleSupplier target, DoubleSupplier tolerance)
      Returns a Trigger that is active when the motor stator current is below target + tolerance amps.
      Parameters:
      target - reference current in amps
      tolerance - offset added to target to form the upper bound
      Returns:
      trigger that is true when stator current is below the threshold
    • aboveCurrent

      public Trigger aboveCurrent(DoubleSupplier target, DoubleSupplier tolerance)
      Returns a Trigger that is active when the motor stator current is above target - tolerance amps.
      Parameters:
      target - reference current in amps
      tolerance - offset subtracted from target to form the lower bound
      Returns:
      trigger that is true when stator current is above the threshold
    • refreshSignalsOncePerLoop

      protected void refreshSignalsOncePerLoop()
      Refreshes every status signal this mechanism reads, once per robot loop, in one Phoenix call.

      Every Phoenix getter such as motor.getStatorCurrent() defaults to refreshing its signal, which is a JNI call each. With eight signals per mechanism read once or more a loop that was over a hundred JNI calls per loop across the robot. CTRE's recommendation is one refreshAll for the lot, which is what this does; every read in the same loop then sees the same sample, which is the behaviour the per-value caches used to provide.

    • softLimitsNeedReboot

      public boolean softLimitsNeedReboot()
      Whether a soft-limit param changed since this mechanism was built.
      Returns:
      true while the motor runs on soft limits the params no longer say
    • simulateReboot

      public void simulateReboot()
      Desktop simulation only: what a brownout does to the leader, its position back to 0 and a reset reported next loop. Phoenix's simulated devices never reboot.
    • clampToSoftLimits

      public double clampToSoftLimits(double rotations)
      The nearest position the motor can reach under the soft limits it booted with (each one only while enabled). Soft-limit params apply at boot only, so these are the motor's limits even after a params edit.
      Parameters:
      rotations - a position goal, rotations
      Returns:
      the goal clamped to the enabled soft limits
    • hasSoftLimits

      public boolean hasSoftLimits()
      The leader's position bounds its travel, so a reboot that restarts it matters.
      Returns:
      true if either soft limit is enabled
    • isPositionLost

      public boolean isPositionLost()
      The leader rebooted since this mechanism last set its position, so the position, the soft limits and any position setpoint are measured from a zero the reboot erased. Until a position write (homing) clears it, every soft-limited output is replaced by neutral. Only soft-limited mechanisms lose their position this way.
      Returns:
      true while the position cannot be trusted
    • isPositionWritePending

      public boolean isPositionWritePending()
      A position write (setMotorPosition(DoubleSupplier)) went out and the readings do not show it yet, so they are still measured from the old zero. Setpoints are held meanwhile; logic that reads the position as homed should wait too. Usually a loop or two.
      Returns:
      true until the readings show the written position
    • motorResetThisLoop

      protected boolean motorResetThisLoop()
      The leader's reset input this loop, after refreshing it. A mechanism that homes itself restarts its homing on this.
      Returns:
      true on the loop a reboot is seen
    • isTrackingStopped

      public boolean isTrackingStopped()
      This mechanism stayed out of tolerance of its goal past the debounce and is held in neutral (brake or coast per its config) until the robot is disabled or clearTrackingStop(). A re-home does not release it: homing takes a stall for the stop, so a jammed mechanism would zero itself at the jam.
      Returns:
      true while the tracking stop holds the mechanism
    • clearTrackingStop

      public void clearTrackingStop()
      The operator's override: releases the tracking stop. It latches again if still stuck.
    • updateInputs

      protected void updateInputs()
      Refreshes the motor inputs for this loop. Called from periodic() so the inputs are recorded every loop even when nothing reads them; subclasses that override periodic() get the same from their first getter call.
    • getStatorCurrent

      public double getStatorCurrent()
      Returns the stator current of the motor as of this loop.
      Returns:
      motor stator current in amps
    • getSupplyCurrent

      public double getSupplyCurrent()
      Returns the supply current of the motor as of this loop.
      Returns:
      motor supply current in amps
    • getVoltage

      public double getVoltage()
      Returns the applied motor voltage as of this loop.
      Returns:
      motor voltage in volts
    • getTemp

      public double getTemp()
      Returns the motor temperature as of this loop.
      Returns:
      motor temperature in Celsius
    • logDiagnostics

      protected void logDiagnostics(String prefix)
      Logs voltage, stator and supply current, temperature and connection under prefix/..., at 10 Hz. Subclasses call this from periodic() instead of logging these five values themselves. The keys are built on the first call.
      Parameters:
      prefix - log key prefix, e.g. "Hood"
    • logDiagnostics

      protected void logDiagnostics(String prefix, boolean dashboard)
      As logDiagnostics(String), optionally also publishing the values to the dashboard.
      Parameters:
      prefix - log key prefix, e.g. "Turret"
      dashboard - true to publish through Telemetry.logDash(String, double)
    • percentToRotations

      public double percentToRotations(DoubleSupplier percent)
      Converts a percentage of the mechanism's maximum range into an absolute rotation count.
      Parameters:
      percent - position as a percentage of max rotations (0 to 100)
      Returns:
      the equivalent position in rotations
    • rotationsToPercent

      public double rotationsToPercent(DoubleSupplier rotations)
      Converts an absolute rotation count into a percentage of the mechanism's maximum range.
      Parameters:
      rotations - position in rotations
      Returns:
      the equivalent percentage of max rotations (0 to 100)
    • degreesToRotations

      public double degreesToRotations(DoubleSupplier degrees)
      Converts degrees to rotations (1 rotation = 360 degrees).
      Parameters:
      degrees - angle in degrees
      Returns:
      the equivalent position in rotations
    • rotationsToDegrees

      public double rotationsToDegrees(DoubleSupplier rotations)
      Converts rotations to degrees (1 rotation = 360 degrees).
      Parameters:
      rotations - position in rotations
      Returns:
      the equivalent angle in degrees
    • getPositionRotations

      public double getPositionRotations()
      Returns the motor position in rotations as of this loop.
      Returns:
      motor position in rotations
    • getLatencyCompensatedPositionRotations

      public double getLatencyCompensatedPositionRotations()
      Returns the motor position in rotations projected from the signal's own timestamp to now along the velocity signal, so a mechanism moving at speed reads where it is rather than where it was when the CAN frame left the motor.
      Returns:
      latency-compensated motor position in rotations, or 0 if not attached
    • getLatencyCompensatedPositionDegrees

      public double getLatencyCompensatedPositionDegrees()
      Returns:
      latency-compensated motor position in degrees, or 0 if not attached
    • getPositionPercentage

      public double getPositionPercentage()
      Returns the motor position as a percentage of max rotations as of this loop.
      Returns:
      motor position in percentage of max rotations (0 to 100)
    • getPositionDegrees

      public double getPositionDegrees()
      Returns the motor position in degrees as of this loop.
      Returns:
      motor position in degrees
    • getPositionDegreesUncached

      public double getPositionDegreesUncached()
      Same as getPositionDegrees(). The per-loop signal refresh is keyed on the robot loop counter rather than the scheduler, so a caller that runs before CommandScheduler.run() (Vision, in Robot.robotPeriodic()) already gets this loop's sample. Kept so existing callers need not change.
      Returns:
      motor position in degrees, or 0 if not attached
    • getVelocityRPM

      public double getVelocityRPM()
      Returns the motor velocity in RPM as of this loop.
      Returns:
      motor velocity in revolutions per minute
    • runVelocity

      public Command runVelocity(DoubleSupplier velocityRPM)
      Returns a Command that continuously drives the mechanism at the specified velocity using closed-loop voltage control.
      Parameters:
      velocityRPM - the target velocity in revolutions per minute
      Returns:
      a command that runs the mechanism at the given velocity
    • runVelocityTcFocRPM

      public Command runVelocityTcFocRPM(DoubleSupplier velocityRPM)
      Returns a Command that continuously drives the mechanism at the specified velocity using closed-loop Torque Current FOC control (requires Phoenix Pro).
      Parameters:
      velocityRPM - the target velocity in revolutions per minute
      Returns:
      a command that runs the mechanism at the given velocity using torque current FOC
    • runPercentage

      public Command runPercentage(DoubleSupplier percent)
      Returns a Command that continuously applies an open-loop percent output to the mechanism using voltage compensation.
      Parameters:
      percent - fractional output between -1 and +1
      Returns:
      a command that runs the mechanism at the given percent output
    • runVoltage

      public Command runVoltage(DoubleSupplier voltage)
      Returns a Command that continuously applies the specified voltage to the mechanism, bypassing any closed-loop control.
      Parameters:
      voltage - the desired voltage in volts
      Returns:
      a command that applies the given voltage output
    • runVoltageNoSoftLimit

      public Command runVoltageNoSoftLimit(DoubleSupplier voltage)
      Returns a Command that continuously applies the specified voltage to the mechanism, bypassing closed-loop control and ignoring software limit switches.
      Parameters:
      voltage - the desired voltage in volts
      Returns:
      a command that applies the given voltage output, ignoring software limits
    • runTorqueCurrentFoc

      public Command runTorqueCurrentFoc(DoubleSupplier current)
      Returns a Command that continuously drives the mechanism at the specified torque current using FOC control (requires Phoenix Pro).
      Parameters:
      current - the desired torque current in amps
      Returns:
      a command that runs the mechanism at the given torque current
    • moveToRotations

      public Command moveToRotations(DoubleSupplier rotations)
      Returns a Command that continuously moves the mechanism to the specified position using Motion Magic Torque Current FOC control (requires Phoenix Pro).
      Parameters:
      rotations - the target position in rotations
      Returns:
      a command that moves the mechanism to the given position
    • moveToPercentage

      public Command moveToPercentage(DoubleSupplier percent)
      Returns a Command that continuously moves the mechanism to the specified position using Motion Magic Torque Current FOC control (requires Phoenix Pro).
      Parameters:
      percent - the target position as a percentage of max rotations (0 to 100)
      Returns:
      a command that moves the mechanism to the given percentage position
    • moveToDegrees

      public Command moveToDegrees(DoubleSupplier degrees)
      Returns a Command that continuously moves the mechanism to the specified angular position using Motion Magic Torque Current FOC control (requires Phoenix Pro).
      Parameters:
      degrees - the target position in degrees
      Returns:
      a command that moves the mechanism to the given position in degrees
    • runFocRotations

      public Command runFocRotations(DoubleSupplier rotations)
      Returns a Command that continuously moves the mechanism to the specified position using Motion Magic Torque Current FOC control (requires Phoenix Pro).

      Equivalent to moveToRotations(DoubleSupplier). Prefer that method for clarity.

      Parameters:
      rotations - the target position in rotations
      Returns:
      a command that moves the mechanism to the given position
    • runStop

      public Command runStop()
      Returns a Command that stops the mechanism and holds it stopped for its duration.
      Returns:
      a command that stops the mechanism
    • coastMode

      public Command coastMode()
      Returns a Command that sets the mechanism to coast mode while active, then reverts to brake mode when the command ends. Safe to run while the robot is disabled.
      Returns:
      a command that temporarily enables coast mode
    • ensureBrakeMode

      public Command ensureBrakeMode()
      Returns a Command that sets the mechanism to brake mode if it is currently in coast mode. Safe to run while the robot is disabled.
      Returns:
      a command that ensures brake mode is active
    • runCurrentLimits

      protected Command runCurrentLimits(DoubleSupplier supplyLimit, DoubleSupplier statorLimit)
      Returns a Command that applies new supply and stator current limits to the mechanism.
      Parameters:
      supplyLimit - the new supply current limit in amps
      statorLimit - the new stator current limit in amps
      Returns:
      a command that updates the current limits
    • setCurrentLimits

      protected void setCurrentLimits(DoubleSupplier supplyLimit, DoubleSupplier statorLimit)
      Immediately applies new supply and stator current limits to the motor configuration.
      Parameters:
      supplyLimit - the new supply current limit in amps
      statorLimit - the new stator current limit in amps
    • stop

      protected void stop()
      Stops the motor output. Does nothing if the mechanism is not attached.
    • tareMotor

      protected void tareMotor()
      Sets the mechanism's reported position to zero (tares the motor encoder). Does nothing if the mechanism is not attached.
    • setMotorPosition

      protected void setMotorPosition(DoubleSupplier rotations)
      Sets the motor's internal position register to the specified value without moving the motor.

      Sent off the main thread (sendPosition(double)), since homing calls this while enabled. Until the readings show the new position, isPositionWritePending() is true and setpoints are held (PositionWrite).

      Parameters:
      rotations - the position to write to the motor in rotations
    • setMMVelocityFOC

      protected void setMMVelocityFOC(DoubleSupplier velocityRPS)
      Closed-loop velocity control using Motion Magic with Torque Current FOC (requires Phoenix Pro).
      Parameters:
      velocityRPS - the target velocity in rotations per second
    • setVelocityTorqueCurrentFOC

      protected void setVelocityTorqueCurrentFOC(DoubleSupplier velocityRPS)
      Closed-loop velocity control using Torque Current FOC (requires Phoenix Pro).
      Parameters:
      velocityRPS - the target velocity in rotations per second
    • setVelocityTCFOCrpm

      protected void setVelocityTCFOCrpm(DoubleSupplier velocityRPM)
      Closed-loop velocity control using Torque Current FOC with an RPM input (requires Phoenix Pro). The RPM value is converted to RPS internally before being sent to the motor.
      Parameters:
      velocityRPM - the target velocity in revolutions per minute
    • setVelocity

      protected void setVelocity(DoubleSupplier velocityRPS)
      Closed-loop velocity control with voltage compensation.
      Parameters:
      velocityRPS - the target velocity in rotations per second
    • setVelocityRPM

      protected void setVelocityRPM(DoubleSupplier velocityRPM)
      Closed-loop velocity control with voltage compensation, taking RPM. The RPM value is converted to RPS internally before being sent to the motor.
      Parameters:
      velocityRPM - the target velocity in revolutions per minute
    • setPosition

      protected void setPosition(DoubleSupplier rotations)
      Closed-loop position control with voltage compensation.
      Parameters:
      rotations - the target position in rotations
    • setPositionWithVelocity

      protected void setPositionWithVelocity(DoubleSupplier rotations, DoubleSupplier velocityRPS)
      Closed-loop position control with voltage compensation and an explicit velocity feedforward. This is the correct primitive for tracking a continuously moving setpoint (e.g. a turret aiming at a target while the robot drives), where profiling would introduce steady-state lag.
      Parameters:
      rotations - the target position in mechanism rotations
      velocityRPS - the velocity feedforward in mechanism rotations per second
    • setMMPositionFoc

      protected void setMMPositionFoc(DoubleSupplier rotations)
      Closed-loop position control using Motion Magic with Torque Current FOC (requires Phoenix Pro).
      Parameters:
      rotations - the target position in rotations
    • setPositionFocWithVelocity

      protected void setPositionFocWithVelocity(DoubleSupplier rotations, DoubleSupplier velocityRPS)
      Closed-loop position control using PositionTorqueCurrentFOC with an explicit velocity feedforward. This is the correct primitive for tracking a continuously moving setpoint (e.g. a turret aiming at a target while the robot drives), where profiling would introduce steady-state lag.
      Parameters:
      rotations - the target position in mechanism rotations
      velocityRPS - the velocity feedforward in mechanism rotations per second
    • setDynMMPositionFoc

      protected void setDynMMPositionFoc(DoubleSupplier rotations, DoubleSupplier velocity, DoubleSupplier acceleration, DoubleSupplier jerk)
      Closed-loop position control using Dynamic Motion Magic with Torque Current FOC (requires Phoenix Pro). Trajectory parameters can be changed every loop cycle.
      Parameters:
      rotations - the target position in rotations
      velocity - the cruise velocity in rotations per second
      acceleration - the acceleration in rotations per second squared
      jerk - the jerk in rotations per second cubed
    • setDynMMPositionVoltage

      protected void setDynMMPositionVoltage(DoubleSupplier rotations, DoubleSupplier velocity, DoubleSupplier acceleration, DoubleSupplier jerk)
      Closed-loop position control using Dynamic Motion Magic with voltage compensation. Trajectory parameters can be changed every loop cycle.
      Parameters:
      rotations - the target position in rotations
      velocity - the cruise velocity in rotations per second
      acceleration - the acceleration in rotations per second squared
      jerk - the jerk in rotations per second cubed
    • setMMPosition

      protected void setMMPosition(DoubleSupplier rotations)
      Closed-loop position control using Motion Magic with voltage compensation (slot 0).
      Parameters:
      rotations - the target position in rotations
    • setMMPosition

      protected void setMMPosition(DoubleSupplier rotations, int slot)
      Closed-loop position control using Motion Magic with voltage compensation and an explicit PID/FF gain slot.
      Parameters:
      rotations - the target position in rotations
      slot - the gain slot to use (0, 1, or 2)
    • setPercentOutput

      protected void setPercentOutput(DoubleSupplier percent)
      Open-loop percent output control with voltage compensation. The output voltage is percent × voltageCompSaturation.
      Parameters:
      percent - fractional output between -1 and +1
    • setVoltageOutput

      protected void setVoltageOutput(DoubleSupplier voltage)
      Open-loop voltage control. It applies the requested voltage directly, without compensation scaling.
      Parameters:
      voltage - the desired voltage in volts
    • setVoltageOutputNoSoftLimit

      protected void setVoltageOutputNoSoftLimit(DoubleSupplier voltage)
      Open-loop voltage control that ignores software limit switches. Use with caution. This can drive the mechanism past its configured travel limits.
      Parameters:
      voltage - the desired voltage in volts
    • setTorqueCurrentFoc

      public void setTorqueCurrentFoc(DoubleSupplier current)
      Applies a torque current setpoint using FOC control (requires Phoenix Pro).
      Parameters:
      current - the desired torque current in amps
    • setBrakeMode

      public void setBrakeMode(boolean isInBrake)
      Sets the motor's neutral mode to brake or coast and immediately applies the change to hardware.
      Parameters:
      isInBrake - true to set brake mode; false to set coast mode
    • toggleReverseSoftLimit

      public void toggleReverseSoftLimit(boolean enabled)
      Enables or disables the reverse software limit switch and immediately applies the change. The threshold is read from the current configuration.
      Parameters:
      enabled - true to enable the reverse soft limit; false to disable it
    • toggleTorqueCurrentLimit

      public void toggleTorqueCurrentLimit(DoubleSupplier enabledLimit, boolean enabled)
      Enables or disables a forward/reverse torque current limit and immediately applies the change. When disabled, the peak torque current is reset to ±300 A (effectively unlimited).
      Parameters:
      enabledLimit - the torque current limit in amps when enabled is true
      enabled - true to apply the limit; false to remove it
    • toggleSupplyCurrentLimit

      public void toggleSupplyCurrentLimit(DoubleSupplier enabledLimit, boolean enabled)
      Enables or disables the supply current limit and immediately applies the change.
      Parameters:
      enabledLimit - the supply current limit in amps
      enabled - true to enable the limit; false to disable it
    • applyCurrentLimit

      public void applyCurrentLimit(DoubleSupplier supplyLimit, DoubleSupplier statorLimit)
      Applies new supply and stator current limits if the requested values differ from the currently configured limits. The update is retried up to 10 times on failure.
      Parameters:
      supplyLimit - the new supply current limit in amps
      statorLimit - the new stator current limit in amps
    • checkAvgCurrent

      public Command checkAvgCurrent(DoubleSupplier expectedCurrent, DoubleSupplier tolerance)
      Returns a Command that measures the average stator current over its runtime and fires a warning Alert if the average deviates from expectedCurrent by more than tolerance.
      Parameters:
      expectedCurrent - the expected average stator current in amps
      tolerance - the maximum acceptable deviation in amps
      Returns:
      a diagnostic command that checks average current
    • checkMaxCurrent

      public Command checkMaxCurrent(DoubleSupplier expectedCurrent)
      Returns a Command that tracks the peak stator current over its runtime and fires a warning Alert if the peak exceeds expectedCurrent.
      Parameters:
      expectedCurrent - the maximum acceptable peak stator current in amps
      Returns:
      a diagnostic command that checks peak current
    • checkMinThresholdCurrent

      public Command checkMinThresholdCurrent(DoubleSupplier expectedCurrent)
      Returns a Command that tracks the peak stator current over its runtime and fires a warning Alert if the peak never reaches expectedCurrent. Use this to verify that a mechanism drew at least the expected minimum load.
      Parameters:
      expectedCurrent - the minimum acceptable peak stator current in amps
      Returns:
      a diagnostic command that checks whether a minimum current threshold was reached
    • getMotor

      public TalonFX getMotor()
      The primary (leader) TalonFX motor controller.
    • getFollowerMotors

      public TalonFX[] getFollowerMotors()
      Optional follower TalonFX motor controllers that mirror the leader.
    • getInputs

      public MotorInputs getInputs()
      This loop's motor readings as an AdvantageKit input. Every getter reads from here, so a replayed log drives the mechanism's logic exactly as the field did. See MotorInputs.