Class Mechanism
- All Implemented Interfaces:
Subsystem
- Direct Known Subclasses:
FuelIntake, Hood, IndexerBed, IndexerTower, IntakeExtension, IntakeExtension.IntakeExtensionRight, Launcher
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(...).
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 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.all()Every mechanism constructed so far, in construction order, e.g.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) doubleclampToSoftLimits(double rotations) The nearest position the motor can reach under the soft limits it booted with (each one only while enabled).voidThe operator's override: releases the tracking stop.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.This loop's motor readings as an AdvantageKit input.doubleSame asgetLatencyCompensatedPositionRotations()in degrees.doubleReturns 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.getMotor()The primary (leader) TalonFX motor controller.getName()Returns the human-readable name of this mechanism, as defined in itsMechanism.Config.doubleReturns the motor position in degrees as of this loop.doubleSame asgetPositionDegrees().doubleReturns the motor position as a percentage of max rotations as of this loop.doubleReturns the motor position in rotations as of this loop.doubleReturns the stator current of the motor as of this loop.doubleReturns the supply current of the motor as of this loop.doubleReturns the last closed-loop setpoint (in rotations) sent to the motor by this class.doublegetTemp()Returns the motor temperature as of this loop.doubleReturns the motor velocity in RPM as of this loop.doubleReturns the last closed-loop velocity setpoint (in rotations per second) sent to the motor by this class.doubleReturns the applied motor voltage as of this loop.booleanThe leader's position bounds its travel, so a reboot that restarts it matters.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.booleanReturnstruewhen the leader motor is attached and its status frames are arriving over CAN.booleanThe 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.booleanA position write (setMotorPosition(DoubleSupplier)) went out and the readings do not show it yet, so they are still measured from the old zero.booleanThis 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 orclearTrackingStop().voidReports the combined supply current draw of the leader motor and all followers to the battery logger.protected voidlogDiagnostics(String prefix) Logs voltage, stator and supply current, temperature and connection underprefix/..., at 10 Hz.protected voidlogDiagnostics(String prefix, boolean dashboard) AslogDiagnostics(String), optionally also publishing the values to the dashboard.protected booleanThe leader's reset input this loop, after refreshing it.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.protected voidRefreshes every status signal this mechanism reads, once per robot loop, in one Phoenix call.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.protected voidsetPosition(DoubleSupplier rotations) Closed-loop position control with voltage compensation.protected voidsetPositionFocWithVelocity(DoubleSupplier rotations, DoubleSupplier velocityRPS) Closed-loop position control usingPositionTorqueCurrentFOCwith an explicit velocity feedforward.protected voidsetPositionWithVelocity(DoubleSupplier rotations, DoubleSupplier velocityRPS) Closed-loop position control with voltage compensation and an explicit velocity feedforward.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 voidsetVelocityRPM(DoubleSupplier velocityRPM) Closed-loop velocity control with voltage compensation, taking RPM.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.protected voidOpen-loop voltage control that ignores software limit switches.voidDesktop simulation only: what a brownout does to the leader, its position back to 0 and a reset reported next loop.voidCalled once per simulation loop.booleanWhether a soft-limit param changed since this mechanism was built.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.protected voidRefreshes the motor inputs for this loop.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface 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
-
all
-
periodic
-
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
-
isMotorConnected
public boolean isMotorConnected()Returnstruewhen 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:
trueif 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
Returns the name of the command currently scheduled on this subsystem, or"none"if no command is running.- Returns:
- the current command name
-
runningDefaultCommand
-
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
-
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 onerefreshAllfor 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:
truewhile 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:
trueif 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:
truewhile 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:
trueuntil 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:
trueon 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 orclearTrackingStop(). 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:
truewhile 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 fromperiodic()so the inputs are recorded every loop even when nothing reads them; subclasses that overrideperiodic()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
Logs voltage, stator and supply current, temperature and connection underprefix/..., at 10 Hz. Subclasses call this fromperiodic()instead of logging these five values themselves. The keys are built on the first call.- Parameters:
prefix- log key prefix, e.g."Hood"
-
logDiagnostics
AslogDiagnostics(String), optionally also publishing the values to the dashboard.- Parameters:
prefix- log key prefix, e.g."Turret"dashboard-trueto publish throughTelemetry.logDash(String, double)
-
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 to 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 to 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 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
0if not attached
-
getLatencyCompensatedPositionDegrees
public double getLatencyCompensatedPositionDegrees()Same asgetLatencyCompensatedPositionRotations()in degrees.- Returns:
- latency-compensated motor position in degrees, or
0if 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 asgetPositionDegrees(). The per-loop signal refresh is keyed on the robot loop counter rather than the scheduler, so a caller that runs beforeCommandScheduler.run()(Vision, inRobot.robotPeriodic()) already gets this loop's sample. Kept so existing callers need not change.- Returns:
- motor position in degrees, or
0if not attached
-
getVelocityRPM
public double getVelocityRPM()Returns the motor velocity in RPM as of this loop.- 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 to 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
-
coastMode
-
ensureBrakeMode
-
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.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
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
-
setVelocityRPM
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
Closed-loop position control with voltage compensation.- Parameters:
rotations- the target position in rotations
-
setPositionWithVelocity
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 rotationsvelocityRPS- the velocity feedforward in mechanism 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
-
setPositionFocWithVelocity
Closed-loop position control usingPositionTorqueCurrentFOCwith 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 rotationsvelocityRPS- 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 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. It 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
-
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. -
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. SeeMotorInputs.
-