Class Mechanism.Config
java.lang.Object
frc.spectrumLib.mechanism.Mechanism.Config
- Direct Known Subclasses:
FuelIntake.FuelIntakeConfig, Hood.HoodConfig, IndexerBed.IndexerBedConfig, IndexerTower.IndexerTowerConfig, IntakeExtension.IntakeExtensionConfig, IntakeExtension.IntakeExtensionRight.RightConfig, Launcher.LauncherConfig
- Enclosing class:
Mechanism
Configuration for a
Mechanism, 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.).
Subclass this in each concrete mechanism and call the config*() helpers in the
constructor to set mechanism-specific parameters before passing the config to the Mechanism constructor.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TalonFXConfigurationFull TalonFX hardware configuration applied to the leader motor on startup. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyTalonConfig(TalonFX talon) Applies the currentTalonFXConfigurationto the given motor and reports a warning to the DriverStation if the apply fails.voidConfigures the motor output as clockwise positive (inverted relative to the default).voidconfigClosedLoopRamps(double seconds) Sets the closed-loop ramp period for duty cycle, voltage, and torque control.voidconfigContinuousWrap(boolean enabled) Enables or disables continuous position wrap-around for closed-loop control.voidConfigures the motor output as counter-clockwise positive (default for most mechanisms when viewed from the shaft end).voidConfigures the feedback sensor source using a rotorOffset of0.voidconfigFeedbackSensorSource(FeedbackSensorSourceValue source, double offset) Configures the feedback sensor source and its rotational offset.voidconfigFeedForwardGains(double kS, double kV, double kA, double kG) Configures feed-forward gains in slot 0.voidconfigFeedForwardGains(int slot, double kS, double kV, double kA, double kG) Configures feed-forward gains in the specified slot.voidconfigForwardSoftLimit(double threshold, boolean enabled) Configures the forward software limit switch.voidconfigForwardTorqueCurrentLimit(double currentLimit) Sets the peak forward torque current limit.voidconfigForwardVoltageLimit(double voltageLimit) Sets the peak forward output voltage.voidconfigGearRatio(double gearRatio) Configures the sensor-to-mechanism gear ratio.voidconfigGravityType(boolean isArm) Configures the gravity compensation type in slot 0.voidconfigGravityType(int slot, boolean isArm) Configures the gravity compensation type in the specified slot.voidconfigLowerSupplyCurrentLimit(double currentLimit) Sets the lower supply current limit, used to reduce dissipation after the upper limit has been triggered.voidconfigLowerSupplyCurrentTime(double time) Sets the time window for the lower supply current limit.protected voidconfigMinMaxRotations(double minRotation, double maxRotation) Sets the minimum and maximum rotation limits for the mechanism.voidconfigMotionMagic(double cruiseVelocity, double acceleration, double jerk) Configures the Motion Magic cruise velocity, acceleration, and jerk limits.voidconfigMotionMagicPosition(double feedforward) Configures the feed-forward term for Motion Magic position control requests.voidconfigMotionMagicVelocity(double acceleration, double feedforward) Configures optional Motion Magic velocity parameters (acceleration and feed-forward) for both FOC and voltage velocity control requests.voidconfigNeutralBrakeMode(boolean isInBrake) Sets the motor neutral mode to brake or coast.voidconfigNeutralDeadband(double deadband) Sets the duty-cycle neutral deadband.voidconfigOpenLoopRamps(double seconds) Sets the open-loop ramp period for duty cycle, voltage, and torque control.voidconfigPeakOutput(double forward, double reverse) Sets the peak forward and reverse duty-cycle output limits.voidconfigPIDGains(double kP, double kI, double kD) Configures PID gains in slot 0.voidconfigPIDGains(int slot, double kP, double kI, double kD) Configures PID gains in the specified slot.voidconfigPositionTrackingStop(double toleranceRotations, double debounceSeconds, boolean enabled) Watches the position loop: the mechanism stops once it has been more thantoleranceRotationsfrom its goal fordebounceSecondswhile enabled and connected.voidconfigReverseSoftLimit(double threshold, boolean enabled) Configures the reverse software limit switch.voidconfigReverseTorqueCurrentLimit(double currentLimit) Sets the peak reverse torque current limit.voidconfigReverseVoltageLimit(double voltageLimit) Sets the peak reverse output voltage.voidconfigSoftLimits(DoubleParam forward, DoubleParam reverse) Enables both soft limits from params, in mechanism rotations.voidconfigStatorCurrentLimit(double statorLimit, boolean enabled) Configures the stator current limit.voidconfigSupplyCurrentLimit(double supplyLimit, boolean enabled) Configures the supply current limit.voidconfigVelocityTrackingStop(double toleranceRps, double debounceSeconds, boolean enabled) Watches the velocity loop, asconfigPositionTrackingStop(double, double, boolean)watches position.voidconfigVoltageCompensation(double voltageCompSaturation) Sets the voltage compensation saturation voltage used by percent-output control.Configurations for follower motors.Set byconfigSoftLimits(DoubleParam, DoubleParam); null when the soft limits are fixed in code.doubleReturns the currently configured sensor-to-mechanism gear ratio.getId()CAN bus device ID and bus name for the leader motor.doubleMaximum mechanism position in rotations (used for range calculations).doubleMinimum mechanism position in rotations (used for range calculations).getName()Human-readable name for this mechanism (used in logging and alerts).intTotal number of motors (leader + followers).Percent (duty-cycle) output control.Full TalonFX hardware configuration applied to the leader motor on startup.doubledoubleLargest closed-loop error the tracking stop tolerates: rotations for a position loop, rotations per second for a velocity loop.doubleVoltage compensation saturation value used byMechanism.setPercentOutput(DoubleSupplier).booleanWhether physical hardware is attached.booleanPublish the leader's output signals (duty cycle, motor voltage, torque current) at the control rate and log its applied voltage on every loop instead of at 10 Hz.booleanStop the mechanism on a tracking fault.booleanThe tracking stop watches the velocity loop, not the position loop.voidsetAttached(boolean attached) Whether physical hardware is attached.voidsetFastOutputLogging(boolean fastOutputLogging) Publish the leader's output signals (duty cycle, motor voltage, torque current) at the control rate and log its applied voltage on every loop instead of at 10 Hz.voidsetFollowerConfigs(Mechanism.FollowerConfig... followers) Sets the follower motor configurations.voidsetTalonConfig(TalonFXConfiguration talonConfig) Full TalonFX hardware configuration applied to the leader motor on startup.voidsetTrackingStopEnabled(boolean trackingStopEnabled) Stop the mechanism on a tracking fault.
-
Field Details
-
talonConfig
Full TalonFX hardware configuration applied to the leader motor on startup.
-
-
Constructor Details
-
Config
Creates a base mechanism configuration with default Talon settings. Hardware limit switches are disabled by default.- Parameters:
name- human-readable name for this mechanismid- CAN device ID of the leader motorcanbus- CAN bus name (e.g.,"rio"or"canivore")
-
-
Method Details
-
applyTalonConfig
Applies the currentTalonFXConfigurationto the given motor and reports a warning to the DriverStation if the apply fails.- Parameters:
talon- the TalonFX motor to configure
-
setFollowerConfigs
Sets the follower motor configurations.- Parameters:
followers- one or moreMechanism.FollowerConfigobjects describing follower motors
-
configVoltageCompensation
public void configVoltageCompensation(double voltageCompSaturation) Sets the voltage compensation saturation voltage used by percent-output control.- Parameters:
voltageCompSaturation- the saturation voltage in volts (typically 12.0)
-
configCounterClockwise_Positive
public void configCounterClockwise_Positive()Configures the motor output as counter-clockwise positive (default for most mechanisms when viewed from the shaft end). -
configClockwise_Positive
public void configClockwise_Positive()Configures the motor output as clockwise positive (inverted relative to the default). -
configForwardVoltageLimit
public void configForwardVoltageLimit(double voltageLimit) Sets the peak forward output voltage.- Parameters:
voltageLimit- maximum forward voltage in volts
-
configReverseVoltageLimit
public void configReverseVoltageLimit(double voltageLimit) Sets the peak reverse output voltage.- Parameters:
voltageLimit- maximum reverse voltage in volts
-
configSupplyCurrentLimit
public void configSupplyCurrentLimit(double supplyLimit, boolean enabled) Configures the supply current limit. The absolute value ofsupplyLimitis used, so negative values are automatically corrected.- Parameters:
supplyLimit- the supply current limit in ampsenabled-trueto enable the limit
-
configStatorCurrentLimit
public void configStatorCurrentLimit(double statorLimit, boolean enabled) Configures the stator current limit. The absolute value ofstatorLimitis used, so negative values are automatically corrected.- Parameters:
statorLimit- the stator current limit in ampsenabled-trueto enable the limit
-
configForwardTorqueCurrentLimit
public void configForwardTorqueCurrentLimit(double currentLimit) Sets the peak forward torque current limit. The absolute value is used so negative inputs are corrected automatically.- Parameters:
currentLimit- peak forward torque current in amps
-
configOpenLoopRamps
public void configOpenLoopRamps(double seconds) Sets the open-loop ramp period for duty cycle, voltage, and torque control.- Parameters:
seconds- time to ramp from neutral to full output
-
configClosedLoopRamps
public void configClosedLoopRamps(double seconds) Sets the closed-loop ramp period for duty cycle, voltage, and torque control.- Parameters:
seconds- time to ramp from neutral to full output
-
configReverseTorqueCurrentLimit
public void configReverseTorqueCurrentLimit(double currentLimit) Sets the peak reverse torque current limit. The value is forced negative so positive inputs are corrected automatically.- Parameters:
currentLimit- peak reverse torque current in amps (sign is corrected if positive)
-
configLowerSupplyCurrentLimit
public void configLowerSupplyCurrentLimit(double currentLimit) Sets the lower supply current limit, used to reduce dissipation after the upper limit has been triggered.- Parameters:
currentLimit- the lower supply current limit in amps
-
configLowerSupplyCurrentTime
public void configLowerSupplyCurrentTime(double time) Sets the time window for the lower supply current limit.- Parameters:
time- the time in seconds
-
configNeutralDeadband
public void configNeutralDeadband(double deadband) Sets the duty-cycle neutral deadband. Outputs below this magnitude are treated as zero.- Parameters:
deadband- deadband as a fraction of full output (e.g.,0.001)
-
configPeakOutput
public void configPeakOutput(double forward, double reverse) Sets the peak forward and reverse duty-cycle output limits.- Parameters:
forward- maximum forward output (0 to 1)reverse- maximum reverse output (-1 to 0)
-
configForwardSoftLimit
public void configForwardSoftLimit(double threshold, boolean enabled) Configures the forward software limit switch.- Parameters:
threshold- the position threshold in rotationsenabled-trueto enable the limit
-
configReverseSoftLimit
public void configReverseSoftLimit(double threshold, boolean enabled) Configures the reverse software limit switch.- Parameters:
threshold- the position threshold in rotationsenabled-trueto enable the limit
-
configSoftLimits
Enables both soft limits from params, in mechanism rotations. The config holds the params' defaults; the mechanism takes their values when it is built, after the params files are read, and keeps them until the robot reboots. Give each param bounds that keep every position the code writes into the motor (boot, homing) between the two limits.- Parameters:
forward- the forward limitreverse- the reverse limit
-
configContinuousWrap
public void configContinuousWrap(boolean enabled) Enables or disables continuous position wrap-around for closed-loop control. Useful for mechanisms that rotate continuously (e.g., swerve azimuth).- Parameters:
enabled-trueto enable continuous wrap
-
configMotionMagicVelocity
public void configMotionMagicVelocity(double acceleration, double feedforward) Configures optional Motion Magic velocity parameters (acceleration and feed-forward) for both FOC and voltage velocity control requests.- Parameters:
acceleration- the velocity acceleration in rotations per second squaredfeedforward- the feed-forward term applied during velocity control
-
configMotionMagicPosition
public void configMotionMagicPosition(double feedforward) Configures the feed-forward term for Motion Magic position control requests.- Parameters:
feedforward- the feed-forward term to apply during position control
-
configMotionMagic
public void configMotionMagic(double cruiseVelocity, double acceleration, double jerk) Configures the Motion Magic cruise velocity, acceleration, and jerk limits.- Parameters:
cruiseVelocity- maximum cruise velocity in rotations per secondacceleration- maximum acceleration in rotations per second squaredjerk- maximum jerk in rotations per second cubed
-
configGearRatio
public void configGearRatio(double gearRatio) Configures the sensor-to-mechanism gear ratio. This is the ratio of rotor rotations to one full mechanism output rotation (or sensor rotations if a remote sensor is used).- Parameters:
gearRatio- the gear ratio (e.g.,11.25means 11.25 rotor turns per output rotation)
-
getGearRatio
public double getGearRatio()Returns the currently configured sensor-to-mechanism gear ratio.- Returns:
- the gear ratio
-
configNeutralBrakeMode
public void configNeutralBrakeMode(boolean isInBrake) Sets the motor neutral mode to brake or coast.- Parameters:
isInBrake-truefor brake mode;falsefor coast mode
-
configPIDGains
public void configPIDGains(double kP, double kI, double kD) Configures PID gains in slot 0.- Parameters:
kP- proportional gainkI- integral gainkD- derivative gain
-
configPIDGains
public void configPIDGains(int slot, double kP, double kI, double kD) Configures PID gains in the specified slot.- Parameters:
slot- the gain slot (0, 1, or 2)kP- proportional gainkI- integral gainkD- derivative gain
-
configFeedForwardGains
public void configFeedForwardGains(double kS, double kV, double kA, double kG) Configures feed-forward gains in slot 0.- Parameters:
kS- static friction compensation (volts or amps)kV- velocity feed-forward gainkA- acceleration feed-forward gainkG- gravity/load compensation gain
-
configFeedForwardGains
public void configFeedForwardGains(int slot, double kS, double kV, double kA, double kG) Configures feed-forward gains in the specified slot.- Parameters:
slot- the gain slot (0, 1, or 2)kS- static friction compensation (volts or amps)kV- velocity feed-forward gainkA- acceleration feed-forward gainkG- gravity/load compensation gain
-
configFeedbackSensorSource
Configures the feedback sensor source using a rotorOffset of0.- Parameters:
source- the feedback sensor source (e.g., remote CANcoder)
-
configFeedbackSensorSource
Configures the feedback sensor source and its rotational offset.- Parameters:
source- the feedback sensor sourceoffset- the feedback rotor offset in rotations
-
configGravityType
public void configGravityType(boolean isArm) Configures the gravity compensation type in slot 0.- Parameters:
isArm-trueforGravityTypeValue.Arm_Cosine(rotating arm);falseforGravityTypeValue.Elevator_Static(elevator)
-
configGravityType
public void configGravityType(int slot, boolean isArm) Configures the gravity compensation type in the specified slot.- Parameters:
slot- the gain slot (0, 1, or 2)isArm-trueforGravityTypeValue.Arm_Cosine(rotating arm);falseforGravityTypeValue.Elevator_Static(elevator)
-
configMinMaxRotations
protected void configMinMaxRotations(double minRotation, double maxRotation) Sets the minimum and maximum rotation limits for the mechanism. These bounds are used by unit-conversion helpers such asMechanism.percentToRotations(DoubleSupplier).- Parameters:
minRotation- the minimum position in rotationsmaxRotation- the maximum position in rotations
-
configPositionTrackingStop
public void configPositionTrackingStop(double toleranceRotations, double debounceSeconds, boolean enabled) Watches the position loop: the mechanism stops once it has been more thantoleranceRotationsfrom its goal fordebounceSecondswhile enabled and connected. The goal is the final setpoint, not a Motion Magic profile's intermediate one, so the debounce must outlast the longest move.- Parameters:
toleranceRotations- largest error, in mechanism rotationsdebounceSeconds- how long it must stay outenabled- stop on a fault;falseonly logs it
-
configVelocityTrackingStop
public void configVelocityTrackingStop(double toleranceRps, double debounceSeconds, boolean enabled) Watches the velocity loop, asconfigPositionTrackingStop(double, double, boolean)watches position. The debounce must outlast a spin-up from rest.- Parameters:
toleranceRps- largest error, in mechanism rotations per seconddebounceSeconds- how long it must stay outenabled- stop on a fault;falseonly logs it
-
getName
Human-readable name for this mechanism (used in logging and alerts). -
isAttached
public boolean isAttached()Whether physical hardware is attached. Set tofalseto run in simulation-only mode. -
setAttached
public void setAttached(boolean attached) Whether physical hardware is attached. Set tofalseto run in simulation-only mode. -
isFastOutputLogging
public boolean isFastOutputLogging()Publish the leader's output signals (duty cycle, motor voltage, torque current) at the control rate and log its applied voltage on every loop instead of at 10 Hz. Set it on the mechanisms whose feedforward is fit from logs: kS and kV survive a 10 Hz voltage, kA does not, because the acceleration it multiplies is gone between one sample and the next. Costs one status frame at 100 Hz on this motor and one double per loop in the log; the followers are untouched. -
setFastOutputLogging
public void setFastOutputLogging(boolean fastOutputLogging) Publish the leader's output signals (duty cycle, motor voltage, torque current) at the control rate and log its applied voltage on every loop instead of at 10 Hz. Set it on the mechanisms whose feedforward is fit from logs: kS and kV survive a 10 Hz voltage, kA does not, because the acceleration it multiplies is gone between one sample and the next. Costs one status frame at 100 Hz on this motor and one double per loop in the log; the followers are untouched. -
getId
CAN bus device ID and bus name for the leader motor. -
getTalonConfig
Full TalonFX hardware configuration applied to the leader motor on startup. -
setTalonConfig
Full TalonFX hardware configuration applied to the leader motor on startup. -
getNumMotors
public int getNumMotors()Total number of motors (leader + followers). -
getVoltageCompSaturation
public double getVoltageCompSaturation()Voltage compensation saturation value used byMechanism.setPercentOutput(DoubleSupplier). Defaults to 12 V. -
getMinRotations
public double getMinRotations()Minimum mechanism position in rotations (used for range calculations). -
getMaxRotations
public double getMaxRotations()Maximum mechanism position in rotations (used for range calculations). -
getFollowerConfigs
Configurations for follower motors. Empty by default (no followers). -
getTrackingTolerance
public double getTrackingTolerance()Largest closed-loop error the tracking stop tolerates: rotations for a position loop, rotations per second for a velocity loop. NaN (the default) turns it off entirely. -
getTrackingDebounceSeconds
public double getTrackingDebounceSeconds() -
isTrackingVelocity
public boolean isTrackingVelocity()The tracking stop watches the velocity loop, not the position loop. -
isTrackingStopEnabled
public boolean isTrackingStopEnabled()Stop the mechanism on a tracking fault. Off, a configured tolerance only logsTrackingErrorandTrackingFault, to check the tolerance against matches first. -
setTrackingStopEnabled
public void setTrackingStopEnabled(boolean trackingStopEnabled) Stop the mechanism on a tracking fault. Off, a configured tolerance only logsTrackingErrorandTrackingFault, to check the tolerance against matches first. -
getMmVelocityFOC
-
getMmPositionFOC
-
getPositionTorqueFOC
-
getDynamicMMPositionFOC
-
getDynamicMotionMagicVoltage
-
getMmVelocityVoltage
-
getMmPositionVoltage
-
getMmPositionVoltageSlot
-
getVoltageControl
-
getVelocityControl
-
getPositionControl
-
getVelocityTorqueCurrentFOC
-
getTorqueCurrentFOC
-
getPercentOutput
Percent (duty-cycle) output control. PrefervoltageControlin most cases. -
getForwardSoftLimitParam
Set byconfigSoftLimits(DoubleParam, DoubleParam); null when the soft limits are fixed in code. -
getReverseSoftLimitParam
-