Package frc.spectrumLib.mechanism
Class Mechanism
java.lang.Object
frc.spectrumLib.mechanism.Mechanism
- All Implemented Interfaces:
Subsystem
- Direct Known Subclasses:
FuelIntake,Hood,IndexerBed,IndexerTower,IntakeExtension,IntakeExtension.IntakeExtensionRight,Launcher
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
Triggerfactories (at/above/below thresholds) - Basic periodic current reporting to a battery/current logger
Attachment semantics
IfMechanism.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
Thetarget field tracks the last commanded closed-loop setpoint sent by this class. It is
used by helper triggers such as atTargetPosition(...).
Extending
Concrete mechanisms should provide aMechanism.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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConfiguration for aMechanism, encapsulating the TalonFX hardware configuration, control request objects, and mechanism-level parameters (gear ratio, soft limits, PID/FF gains, Motion Magic profile, current limits, etc.).static classConfiguration for a TalonFX follower motor that mirrors the leader. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedMechanism(Mechanism.Config config) Creates a Mechanism and, ifMechanism.Config.isAttached()istrue, initializes the leader TalonFX and any configured follower motors.protectedMechanism(Mechanism.Config config, boolean attached) Creates a Mechanism and explicitly overrides theattachedflag in the config. -
Method Summary
Modifier and TypeMethodDescriptionaboveCurrent(DoubleSupplier target, DoubleSupplier tolerance) Returns aTriggerthat is active when the motor stator current is abovetarget - toleranceamps.aboveDegrees(DoubleSupplier target, DoubleSupplier tolerance) Returns aTriggerthat is active when the motor position is abovetarget - tolerancedegrees.abovePercentage(DoubleSupplier target, DoubleSupplier tolerance) Returns aTriggerthat is active when the motor position is abovetarget - tolerance(as a percentage of max rotations).aboveRotations(DoubleSupplier target, DoubleSupplier tolerance) Returns aTriggerthat is active when the motor position is abovetarget - tolerancerotations.aboveVelocityRPM(DoubleSupplier target, DoubleSupplier tolerance) Returns aTriggerthat is active when the motor velocity is abovetarget - toleranceRPM.voidapplyCurrentLimit(DoubleSupplier supplyLimit, DoubleSupplier statorLimit) Applies new supply and stator current limits if the requested values differ from the currently configured limits.atCurrent(DoubleSupplier target, DoubleSupplier tolerance) atDegrees(DoubleSupplier target, DoubleSupplier tolerance) Returns aTriggerthat is active when the motor position is withintoleranceoftarget(both in degrees).atPercentage(DoubleSupplier target, DoubleSupplier tolerance) Returns aTriggerthat is active when the motor position is withintoleranceoftarget(both as a percentage of max rotations).atRotations(DoubleSupplier target, DoubleSupplier tolerance) Returns aTriggerthat is active when the motor position is withintoleranceoftarget(both in rotations).atTargetPosition(DoubleSupplier tolerance) Returns aTriggerthat is active when the motor is withintolerancerotations of the last commanded target position.atVelocityRPM(DoubleSupplier target, DoubleSupplier tolerance) belowCurrent(DoubleSupplier target, DoubleSupplier tolerance) Returns aTriggerthat is active when the motor stator current is belowtarget + toleranceamps.belowDegrees(DoubleSupplier target, DoubleSupplier tolerance) Returns aTriggerthat is active when the motor position is belowtarget + tolerancedegrees.belowPercentage(DoubleSupplier target, DoubleSupplier tolerance) Returns aTriggerthat is active when the motor position is belowtarget + tolerance(as a percentage of max rotations).belowRotations(DoubleSupplier target, DoubleSupplier tolerance) Returns aTriggerthat is active when the motor position is belowtarget + tolerancerotations.belowVelocityRPM(DoubleSupplier target, DoubleSupplier tolerance) Returns aTriggerthat is active when the motor velocity is belowtarget + toleranceRPM.checkAvgCurrent(DoubleSupplier expectedCurrent, DoubleSupplier tolerance) checkMaxCurrent(DoubleSupplier expectedCurrent) checkMinThresholdCurrent(DoubleSupplier expectedCurrent) Returns aCommandthat sets the mechanism to coast mode while active, then reverts to brake mode when the command ends.doubledegreesToRotations(DoubleSupplier degrees) Converts degrees to rotations (1 rotation = 360 degrees).Returns aCommandthat sets the mechanism to brake mode if it is currently in coast mode.protected StringReturns the name of the command currently scheduled on this subsystem, or"none"if no command is running.TalonFX[]Optional follower TalonFX motor controllers that mirror the leader.getMotor()The primary (leader) TalonFX motor controller.getName()Returns the human-readable name of this mechanism, as defined in itsMechanism.Config.doubleReturns the cached motor position in degrees.doubleReturns the cached motor position as a percentage of max rotations.doubleReturns the cached motor position in rotations.doubleReturns the cached stator current of the motor.doubleReturns the cached supply current of the motor.doubleReturns the last closed-loop setpoint (in rotations) sent to the motor by this class.doublegetTemp()Returns the cached temperature of the motor.doubleReturns the cached motor velocity in RPM.doubleReturns the last closed-loop velocity setpoint (in rotations per second) sent to the motor by this class.doubleReturns the cached voltage of the motor.booleanisAtRotations(DoubleSupplier target, DoubleSupplier tolerance) Returnstruewhen the motor position is withintoleranceoftarget(both in rotations).booleanReturnstrueif physical hardware is attached and motor commands should be sent.booleanisAtTargetPosition(DoubleSupplier tolerance) Returnstruewhen the motor is withintolerancerotations of the last commanded target position.voidReports the combined supply current draw of the leader motor and all followers to the battery logger.moveToDegrees(DoubleSupplier degrees) Returns aCommandthat continuously moves the mechanism to the specified angular position using Motion Magic Torque Current FOC control (requires Phoenix Pro).moveToPercentage(DoubleSupplier percent) Returns aCommandthat continuously moves the mechanism to the specified position using Motion Magic Torque Current FOC control (requires Phoenix Pro).moveToRotations(DoubleSupplier rotations) Returns aCommandthat continuously moves the mechanism to the specified position using Motion Magic Torque Current FOC control (requires Phoenix Pro).doublepercentToRotations(DoubleSupplier percent) Converts a percentage of the mechanism's maximum range into an absolute rotation count.voidperiodic()Called once per scheduler loop.doublerotationsToDegrees(DoubleSupplier rotations) Converts rotations to degrees (1 rotation = 360 degrees).doublerotationsToPercent(DoubleSupplier rotations) Converts an absolute rotation count into a percentage of the mechanism's maximum range.protected CommandrunCurrentLimits(DoubleSupplier supplyLimit, DoubleSupplier statorLimit) Returns aCommandthat applies new supply and stator current limits to the mechanism.runFocRotations(DoubleSupplier rotations) Returns aCommandthat continuously moves the mechanism to the specified position using Motion Magic Torque Current FOC control (requires Phoenix Pro).Returns aTriggerthat is active whenever this subsystem's current command is its default command.runPercentage(DoubleSupplier percent) Returns aCommandthat continuously applies an open-loop percent output to the mechanism using voltage compensation.runStop()Returns aCommandthat stops the mechanism and holds it stopped for its duration.runTorqueCurrentFoc(DoubleSupplier current) Returns aCommandthat continuously drives the mechanism at the specified torque current using FOC control (requires Phoenix Pro).runVelocity(DoubleSupplier velocityRPM) Returns aCommandthat continuously drives the mechanism at the specified velocity using closed-loop voltage control.runVelocityTcFocRPM(DoubleSupplier velocityRPM) Returns aCommandthat continuously drives the mechanism at the specified velocity using closed-loop Torque Current FOC control (requires Phoenix Pro).runVoltage(DoubleSupplier voltage) Returns aCommandthat continuously applies the specified voltage to the mechanism, bypassing any closed-loop control.runVoltageNoSoftLimit(DoubleSupplier voltage) Returns aCommandthat continuously applies the specified voltage to the mechanism, bypassing closed-loop control and ignoring software limit switches.voidsetBrakeMode(boolean isInBrake) Sets the motor's neutral mode to brake or coast and immediately applies the change to hardware.protected voidsetCurrentLimits(DoubleSupplier supplyLimit, DoubleSupplier statorLimit) Immediately applies new supply and stator current limits to the motor configuration.protected voidsetDynMMPositionFoc(DoubleSupplier rotations, DoubleSupplier velocity, DoubleSupplier acceleration, DoubleSupplier jerk) Closed-loop position control using Dynamic Motion Magic with Torque Current FOC (requires Phoenix Pro).protected voidsetDynMMPositionVoltage(DoubleSupplier rotations, DoubleSupplier velocity, DoubleSupplier acceleration, DoubleSupplier jerk) Closed-loop position control using Dynamic Motion Magic with voltage compensation.protected voidsetMMPosition(DoubleSupplier rotations) Closed-loop position control using Motion Magic with voltage compensation (slot 0).protected voidsetMMPosition(DoubleSupplier rotations, int slot) Closed-loop position control using Motion Magic with voltage compensation and an explicit PID/FF gain slot.protected voidsetMMPositionFoc(DoubleSupplier rotations) Closed-loop position control using Motion Magic with Torque Current FOC (requires Phoenix Pro).protected voidsetMMVelocityFOC(DoubleSupplier velocityRPS) Closed-loop velocity control using Motion Magic with Torque Current FOC (requires Phoenix Pro).protected voidsetMotorPosition(DoubleSupplier rotations) Sets the motor's internal position register to the specified value without moving the motor.protected voidsetPercentOutput(DoubleSupplier percent) Open-loop percent output control with voltage compensation.voidsetTorqueCurrentFoc(DoubleSupplier current) Applies a torque current setpoint using FOC control (requires Phoenix Pro).protected voidsetVelocity(DoubleSupplier velocityRPS) Closed-loop velocity control with voltage compensation.protected voidsetVelocityTCFOCrpm(DoubleSupplier velocityRPM) Closed-loop velocity control using Torque Current FOC with an RPM input (requires Phoenix Pro).protected voidsetVelocityTorqueCurrentFOC(DoubleSupplier velocityRPS) Closed-loop velocity control using Torque Current FOC (requires Phoenix Pro).protected voidsetVoltageOutput(DoubleSupplier voltage) Open-loop voltage control — applies the requested voltage directly without compensation scaling.protected voidOpen-loop voltage control that ignores software limit switches.voidCalled once per simulation loop.protected voidstop()Stops the motor output.protected voidSets the mechanism's reported position to zero (tares the motor encoder).voidtoggleReverseSoftLimit(boolean enabled) Enables or disables the reverse software limit switch and immediately applies the change.voidtoggleSupplyCurrentLimit(DoubleSupplier enabledLimit, boolean enabled) Enables or disables the supply current limit and immediately applies the change.voidtoggleTorqueCurrentLimit(DoubleSupplier enabledLimit, boolean enabled) Enables or disables a forward/reverse torque current limit and immediately applies the change.doubleReads the stator current directly from the motor hardware.doubleReads the supply current directly from the motor hardware.doubleReads the motor temperature directly from hardware.doubleReads the motor voltage directly from hardware.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem
defer, getCurrentCommand, getDefaultCommand, idle, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, startEnd, startRun
-
Field Details
-
motor
The primary (leader) TalonFX motor controller. -
followerMotors
Optional follower TalonFX motor controllers that mirror the leader. -
config
Configuration object holding motor IDs, Talon settings, and mechanism parameters.
-
-
Constructor Details
-
Mechanism
Creates a Mechanism and, ifMechanism.Config.isAttached()istrue, 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
Creates a Mechanism and explicitly overrides theattachedflag in the config.- Parameters:
config- the mechanism configurationattached-trueto enable hardware;falseto run in software-only mode
-
-
Method Details
-
periodic
public void periodic()Called once per scheduler loop. Concrete subclasses should override to implement their periodic state-machine logic, telemetry, and sensor updates. -
simulationPeriodic
public void simulationPeriodic()Called once per simulation loop. Concrete subclasses should override to update simulation state (e.g., physics model inputs).- Specified by:
simulationPeriodicin interfaceSubsystem
-
getName
Returns the human-readable name of this mechanism, as defined in itsMechanism.Config. -
isAttached
public boolean isAttached()Returnstrueif physical hardware is attached and motor commands should be sent.- Returns:
truewhen hardware is available
-
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
Returns the name of the command currently scheduled on this subsystem, or"none"if no command is running.- Returns:
- the current command name
-
runningDefaultCommand
Returns aTriggerthat is active whenever this subsystem's current command is its default command.- Returns:
- trigger that is
truewhile 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
Returns aTriggerthat is active when the motor is withintolerancerotations of the last commanded target position.- Parameters:
tolerance- maximum allowable error in rotations- Returns:
- trigger that is
truewhen position error is within tolerance
-
isAtTargetPosition
Returnstruewhen the motor is withintolerancerotations of the last commanded target position.- Parameters:
tolerance- maximum allowable error in rotations- Returns:
truewhen position error is within tolerance
-
atRotations
Returns aTriggerthat is active when the motor position is withintoleranceoftarget(both in rotations).- Parameters:
target- the desired position in rotationstolerance- maximum allowable error in rotations- Returns:
- trigger that is
truewhen position is within tolerance of target
-
isAtRotations
Returnstruewhen the motor position is withintoleranceoftarget(both in rotations).- Parameters:
target- the desired position in rotationstolerance- maximum allowable error in rotations- Returns:
truewhen position is within tolerance of target
-
belowRotations
Returns aTriggerthat is active when the motor position is belowtarget + tolerancerotations.- Parameters:
target- reference position in rotationstolerance- offset added to target to form the upper bound- Returns:
- trigger that is
truewhen position is below the threshold
-
aboveRotations
Returns aTriggerthat is active when the motor position is abovetarget - tolerancerotations.- Parameters:
target- reference position in rotationstolerance- offset subtracted from target to form the lower bound- Returns:
- trigger that is
truewhen position is above the threshold
-
atPercentage
Returns aTriggerthat is active when the motor position is withintoleranceoftarget(both as a percentage of max rotations).- Parameters:
target- the desired position as a percentage of max rotationstolerance- maximum allowable error as a percentage- Returns:
- trigger that is
truewhen position is within tolerance of target
-
belowPercentage
Returns aTriggerthat is active when the motor position is belowtarget + tolerance(as a percentage of max rotations).- Parameters:
target- reference position as a percentagetolerance- offset added to target to form the upper bound- Returns:
- trigger that is
truewhen position is below the threshold
-
abovePercentage
Returns aTriggerthat is active when the motor position is abovetarget - tolerance(as a percentage of max rotations).- Parameters:
target- reference position as a percentagetolerance- offset subtracted from target to form the lower bound- Returns:
- trigger that is
truewhen position is above the threshold
-
atDegrees
Returns aTriggerthat is active when the motor position is withintoleranceoftarget(both in degrees).- Parameters:
target- the desired position in degreestolerance- maximum allowable error in degrees- Returns:
- trigger that is
truewhen position is within tolerance of target
-
belowDegrees
Returns aTriggerthat is active when the motor position is belowtarget + tolerancedegrees.- Parameters:
target- reference position in degreestolerance- offset added to target to form the upper bound- Returns:
- trigger that is
truewhen position is below the threshold
-
aboveDegrees
Returns aTriggerthat is active when the motor position is abovetarget - tolerancedegrees.- Parameters:
target- reference position in degreestolerance- offset subtracted from target to form the lower bound- Returns:
- trigger that is
truewhen position is above the threshold
-
atVelocityRPM
- Parameters:
target- the desired velocity in RPMtolerance- maximum allowable error in RPM- Returns:
- trigger that is
truewhen velocity is within tolerance of target
-
belowVelocityRPM
Returns aTriggerthat is active when the motor velocity is belowtarget + toleranceRPM.- Parameters:
target- reference velocity in RPMtolerance- offset added to target to form the upper bound- Returns:
- trigger that is
truewhen velocity is below the threshold
-
aboveVelocityRPM
Returns aTriggerthat is active when the motor velocity is abovetarget - toleranceRPM.- Parameters:
target- reference velocity in RPMtolerance- offset subtracted from target to form the lower bound- Returns:
- trigger that is
truewhen velocity is above the threshold
-
atCurrent
- Parameters:
target- the desired stator current in ampstolerance- maximum allowable error in amps- Returns:
- trigger that is
truewhen stator current is within tolerance of target
-
belowCurrent
Returns aTriggerthat is active when the motor stator current is belowtarget + toleranceamps.- Parameters:
target- reference current in ampstolerance- offset added to target to form the upper bound- Returns:
- trigger that is
truewhen stator current is below the threshold
-
aboveCurrent
Returns aTriggerthat is active when the motor stator current is abovetarget - toleranceamps.- Parameters:
target- reference current in ampstolerance- offset subtracted from target to form the lower bound- Returns:
- trigger that is
truewhen stator current is above the threshold
-
updateStatorCurrent
public double updateStatorCurrent()Reads the stator current directly from the motor hardware.- Returns:
- motor stator current in amps, or
0if not attached
-
getStatorCurrent
public double getStatorCurrent()Returns the cached stator current of the motor.- Returns:
- motor stator current in amps
-
updateSupplyCurrent
public double updateSupplyCurrent()Reads the supply current directly from the motor hardware.- Returns:
- motor supply current in amps, or
0if not attached
-
getSupplyCurrent
public double getSupplyCurrent()Returns the cached supply current of the motor.- Returns:
- motor supply current in amps
-
updateVoltage
public double updateVoltage()Reads the motor voltage directly from hardware.- Returns:
- motor voltage in volts, or
0if not attached
-
getVoltage
public double getVoltage()Returns the cached voltage of the motor.- Returns:
- motor voltage in volts
-
updateTemp
public double updateTemp()Reads the motor temperature directly from hardware.- Returns:
- motor temperature in Celsius, or
0if not attached
-
getTemp
public double getTemp()Returns the cached temperature of the motor.- Returns:
- motor temperature in Celsius
-
percentToRotations
Converts a percentage of the mechanism's maximum range into an absolute rotation count.- Parameters:
percent- position as a percentage of max rotations (0–100)- Returns:
- the equivalent position in rotations
-
rotationsToPercent
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–100)
-
degreesToRotations
Converts degrees to rotations (1 rotation = 360 degrees).- Parameters:
degrees- angle in degrees- Returns:
- the equivalent position in rotations
-
rotationsToDegrees
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 cached motor position in rotations.- Returns:
- motor position in rotations
-
getPositionPercentage
public double getPositionPercentage()Returns the cached motor position as a percentage of max rotations.- Returns:
- motor position in percentage of max rotations (0–100)
-
getPositionDegrees
public double getPositionDegrees()Returns the cached motor position in degrees.- Returns:
- motor position in degrees
-
getVelocityRPM
public double getVelocityRPM()Returns the cached motor velocity in RPM.- Returns:
- motor velocity in revolutions per minute
-
runVelocity
Returns aCommandthat 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
Returns aCommandthat 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
Returns aCommandthat 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
Returns aCommandthat 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
Returns aCommandthat 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
Returns aCommandthat 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
Returns aCommandthat 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
Returns aCommandthat 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–100)- Returns:
- a command that moves the mechanism to the given percentage position
-
moveToDegrees
Returns aCommandthat 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
Returns aCommandthat 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
Returns aCommandthat stops the mechanism and holds it stopped for its duration.- Returns:
- a command that stops the mechanism
-
coastMode
Returns aCommandthat 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
Returns aCommandthat 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
Returns aCommandthat applies new supply and stator current limits to the mechanism.- Parameters:
supplyLimit- the new supply current limit in ampsstatorLimit- the new stator current limit in amps- Returns:
- a command that updates the current limits
-
setCurrentLimits
Immediately applies new supply and stator current limits to the motor configuration.- Parameters:
supplyLimit- the new supply current limit in ampsstatorLimit- 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
Sets the motor's internal position register to the specified value without moving the motor.- Parameters:
rotations- the position to write to the motor in rotations
-
setMMVelocityFOC
Closed-loop velocity control using Motion Magic with Torque Current FOC (requires Phoenix Pro).- Parameters:
velocityRPS- the target velocity in rotations per second
-
setVelocityTorqueCurrentFOC
Closed-loop velocity control using Torque Current FOC (requires Phoenix Pro).- Parameters:
velocityRPS- the target velocity in rotations per second
-
setVelocityTCFOCrpm
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
Closed-loop velocity control with voltage compensation.- Parameters:
velocityRPS- the target velocity in rotations per second
-
setMMPositionFoc
Closed-loop position control using Motion Magic with Torque Current FOC (requires Phoenix Pro).- Parameters:
rotations- the target position in rotations
-
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 rotationsvelocity- the cruise velocity in rotations per secondacceleration- the acceleration in rotations per second squaredjerk- 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 rotationsvelocity- the cruise velocity in rotations per secondacceleration- the acceleration in rotations per second squaredjerk- the jerk in rotations per second cubed
-
setMMPosition
Closed-loop position control using Motion Magic with voltage compensation (slot 0).- Parameters:
rotations- the target position in rotations
-
setMMPosition
Closed-loop position control using Motion Magic with voltage compensation and an explicit PID/FF gain slot.- Parameters:
rotations- the target position in rotationsslot- the gain slot to use (0, 1, or 2)
-
setPercentOutput
Open-loop percent output control with voltage compensation. The output voltage ispercent × voltageCompSaturation.- Parameters:
percent- fractional output between -1 and +1
-
setVoltageOutput
Open-loop voltage control — applies the requested voltage directly without compensation scaling.- Parameters:
voltage- the desired voltage in volts
-
setVoltageOutputNoSoftLimit
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
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-trueto set brake mode;falseto 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-trueto enable the reverse soft limit;falseto disable it
-
toggleTorqueCurrentLimit
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 whenenabledistrueenabled-trueto apply the limit;falseto remove it
-
toggleSupplyCurrentLimit
Enables or disables the supply current limit and immediately applies the change.- Parameters:
enabledLimit- the supply current limit in ampsenabled-trueto enable the limit;falseto disable it
-
applyCurrentLimit
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 ampsstatorLimit- the new stator current limit in amps
-
checkAvgCurrent
Returns aCommandthat measures the average stator current over its runtime and fires a warningAlertif the average deviates fromexpectedCurrentby more thantolerance.- Parameters:
expectedCurrent- the expected average stator current in ampstolerance- the maximum acceptable deviation in amps- Returns:
- a diagnostic command that checks average current
-
checkMaxCurrent
Returns aCommandthat tracks the peak stator current over its runtime and fires a warningAlertif the peak exceedsexpectedCurrent.- Parameters:
expectedCurrent- the maximum acceptable peak stator current in amps- Returns:
- a diagnostic command that checks peak current
-
checkMinThresholdCurrent
Returns aCommandthat tracks the peak stator current over its runtime and fires a warningAlertif the peak never reachesexpectedCurrent. 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
The primary (leader) TalonFX motor controller. -
getFollowerMotors
Optional follower TalonFX motor controllers that mirror the leader.
-