Package frc.spectrumLib.mechanism
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).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.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.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.voidconfigStatorCurrentLimit(double statorLimit, boolean enabled) Configures the stator current limit.voidconfigSupplyCurrentLimit(double supplyLimit, boolean enabled) Configures the supply current limit.voidconfigVoltageCompensation(double voltageCompSaturation) Sets the voltage compensation saturation voltage used by percent-output control.Configurations for follower motors.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 — prefervoltageControlin most cases.Full TalonFX hardware configuration applied to the leader motor on startup.doubleVoltage compensation saturation value used byMechanism.setPercentOutput(java.util.function.DoubleSupplier).booleanWhether physical hardware is attached.voidsetAttached(boolean attached) Whether physical hardware is attached.voidsetFollowerConfigs(Mechanism.FollowerConfig... followers) Sets the follower motor configurations.voidsetTalonConfig(TalonFXConfiguration talonConfig) Full TalonFX hardware configuration applied to the leader motor on startup.
-
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
-
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
-
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(java.util.function.DoubleSupplier).- Parameters:
minRotation- the minimum position in rotationsmaxRotation- the maximum position in rotations
-
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. -
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(java.util.function.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). -
getMmVelocityFOC
-
getMmPositionFOC
-
getDynamicMMPositionFOC
-
getDynamicMotionMagicVoltage
-
getMmVelocityVoltage
-
getMmPositionVoltage
-
getMmPositionVoltageSlot
-
getVoltageControl
-
getVelocityControl
-
getVelocityTorqueCurrentFOC
-
getTorqueCurrentFOC
-
getPercentOutput
Percent (duty-cycle) output control — prefervoltageControlin most cases.
-