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
TalonFX hardware configuration, the control request objects, and the mechanism-level
parameters (gear ratio, soft limits, PID/FF gains, Motion Magic profile, current limits).
Subclass this per mechanism, call the config*() helpers in the subclass
constructor, and pass the result to the Mechanism constructor.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TalonFXConfigurationApplied to the leader motor on startup. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyTalonConfig(TalonFX talon) Applies the currentTalonFXConfigurationto the given motor, reporting a Driver Station warning if the apply fails.voidvoidconfigClosedLoopRamps(double seconds) Sets the closed-loop ramp period, in seconds, for duty cycle, voltage and torque.voidconfigContinuousWrap(boolean enabled) Enables or disables continuous wrap-around in closed-loop control, for a mechanism that turns indefinitely such as a swerve azimuth.voidCounter-clockwise positive, which is the right default for most mechanisms when read from the shaft end.voidconfigCurrentLimits(double supplyLimit, double statorLimit, double lowerSupplyLimit, double lowerSupplyTime) Sets the current limits as a group: the supply limit with its lower limit and lower-limit time, the stator limit, and both torque limits at the stator value.voidConfigures the feedback sensor source with a rotor offset of 0.voidconfigFeedbackSensorSource(FeedbackSensorSourceValue source, double offset) Configures the feedback sensor source and its rotor offset, in rotations.voidconfigFeedForwardGains(double kS, double kV, double kA, double kG) Configures the feed-forward gains in slot 0.voidconfigFeedForwardGains(int slot, double kS, double kV, double kA, double kG) Configures the feed-forward gains in a gain slot.voidconfigForwardSoftLimit(double threshold, boolean enabled) Configures the forward software limit, with the threshold in rotations.voidconfigForwardTorqueCurrentLimit(double currentLimit) Sets the peak forward torque current limit, in amps, from the absolute value of the argument, so a negative limit is corrected rather than rejected.voidconfigForwardVoltageLimit(double voltageLimit) Sets the peak forward output voltage, in volts.voidconfigGearRatio(double gearRatio) Sets the sensor-to-mechanism gear ratio, counted in sensor turns per mechanism output turn, so 11.25 means 11.25 sensor turns per output rotation.voidconfigGravityType(boolean isArm) Configures the gravity compensation type in slot 0.voidconfigGravityType(int slot, boolean isArm) Configures the gravity compensation type in a gain slot.voidconfigLowerSupplyCurrentLimit(double currentLimit) Sets the lower supply current limit, in amps, that applies once the upper one trips.voidconfigLowerSupplyCurrentTime(double time) Sets how long the upper supply limit holds, in seconds, before dropping to the lower.protected voidconfigMinMaxRotations(double minRotation, double maxRotation) Sets the rotation limits the percentage helpers such asMechanism.percentToRotations(java.util.function.DoubleSupplier)convert against.voidconfigMotionMagic(double cruiseVelocity, double acceleration, double jerk) Sets the Motion Magic trajectory limits.voidconfigMotionMagicPosition(double feedforward) Sets the feed-forward term on every Motion Magic position request.voidconfigMotionMagicVelocity(double acceleration, double feedforward) Sets the Motion Magic acceleration and feed-forward on both the FOC and the voltage velocity requests.voidconfigNeutralBrakeMode(boolean isInBrake) Sets brake mode when isInBrake is true, coast when it is false.voidconfigNeutralDeadband(double deadband) Sets the duty-cycle neutral deadband as a fraction of full output, so outputs below that magnitude are treated as zero.voidconfigOpenLoopRamps(double seconds) Sets the open-loop ramp period, in seconds, for duty cycle, voltage and torque.voidconfigPeakOutput(double forward, double reverse) Sets the peak duty-cycle output limits.voidconfigPIDGains(double kP, double kI, double kD) Configures the PID gains in slot 0.voidconfigPIDGains(int slot, double kP, double kI, double kD) Configures the PID gains in a gain slot.voidconfigReverseSoftLimit(double threshold, boolean enabled) Configures the reverse software limit, with the threshold in rotations.voidconfigReverseTorqueCurrentLimit(double currentLimit) Sets the peak reverse torque current limit, in amps.voidconfigReverseVoltageLimit(double voltageLimit) Sets the peak reverse output voltage, in volts.voidconfigStatorCurrentLimit(double statorLimit, boolean enabled) Configures the stator current limit, in amps, from the absolute value of the argument, so a negative limit is corrected rather than rejected.voidconfigSupplyCurrentLimit(double supplyLimit, boolean enabled) Configures the supply current limit, in amps, from the absolute value of the argument, so a negative limit is corrected rather than rejected.voidconfigVoltageCompensation(double voltageCompSaturation) Empty when the mechanism runs on the leader alone.doubleThe configured sensor-to-mechanism gear ratio.getId()doubleTop of the mechanism's range, in rotations, for the percentage helpers.doubleBottom of the mechanism's range, in rotations, for the percentage helpers.getName()Name for this mechanism, used in log keys and alerts.intLeader plus followers.Percent output control.Applied to the leader motor on startup.doubleSaturation forMechanism.setPercentOutput(java.util.function.DoubleSupplier), 12 V by default.booleanFalse builds no hardware, which is how the sim runs a real mechanism config.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.voidsetAttached(boolean attached) False builds no hardware, which is how the sim runs a real mechanism config.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) voidsetTalonConfig(TalonFXConfiguration talonConfig) Applied to the leader motor on startup.
-
Field Details
-
talonConfig
Applied to the leader motor on startup.
-
-
Constructor Details
-
Config
Leaves the Talon settings at their defaults, with the hardware limit switches disabled.- Parameters:
canbus- CAN bus name, such as"rio"or"canivore"
-
-
Method Details
-
applyTalonConfig
Applies the currentTalonFXConfigurationto the given motor, reporting a Driver Station warning if the apply fails. -
setFollowerConfigs
-
configVoltageCompensation
public void configVoltageCompensation(double voltageCompSaturation) -
configCounterClockwise_Positive
public void configCounterClockwise_Positive()Counter-clockwise positive, which is the right default for most mechanisms when read from the shaft end. -
configClockwise_Positive
public void configClockwise_Positive() -
configForwardVoltageLimit
public void configForwardVoltageLimit(double voltageLimit) Sets the peak forward output voltage, in volts. -
configReverseVoltageLimit
public void configReverseVoltageLimit(double voltageLimit) Sets the peak reverse output voltage, in volts. -
configCurrentLimits
public void configCurrentLimits(double supplyLimit, double statorLimit, double lowerSupplyLimit, double lowerSupplyTime) Sets the current limits as a group: the supply limit with its lower limit and lower-limit time, the stator limit, and both torque limits at the stator value.- Parameters:
statorLimit- stator current limit in amps, also used for both torque limits
-
configSupplyCurrentLimit
public void configSupplyCurrentLimit(double supplyLimit, boolean enabled) Configures the supply current limit, in amps, from the absolute value of the argument, so a negative limit is corrected rather than rejected. -
configStatorCurrentLimit
public void configStatorCurrentLimit(double statorLimit, boolean enabled) Configures the stator current limit, in amps, from the absolute value of the argument, so a negative limit is corrected rather than rejected. -
configForwardTorqueCurrentLimit
public void configForwardTorqueCurrentLimit(double currentLimit) Sets the peak forward torque current limit, in amps, from the absolute value of the argument, so a negative limit is corrected rather than rejected. -
configOpenLoopRamps
public void configOpenLoopRamps(double seconds) Sets the open-loop ramp period, in seconds, for duty cycle, voltage and torque. -
configClosedLoopRamps
public void configClosedLoopRamps(double seconds) Sets the closed-loop ramp period, in seconds, for duty cycle, voltage and torque. -
configReverseTorqueCurrentLimit
public void configReverseTorqueCurrentLimit(double currentLimit) Sets the peak reverse torque current limit, in amps. The stored value is forced negative, so a positive argument is corrected rather than rejected. -
configLowerSupplyCurrentLimit
public void configLowerSupplyCurrentLimit(double currentLimit) Sets the lower supply current limit, in amps, that applies once the upper one trips. -
configLowerSupplyCurrentTime
public void configLowerSupplyCurrentTime(double time) Sets how long the upper supply limit holds, in seconds, before dropping to the lower. -
configNeutralDeadband
public void configNeutralDeadband(double deadband) Sets the duty-cycle neutral deadband as a fraction of full output, so outputs below that magnitude are treated as zero. -
configPeakOutput
public void configPeakOutput(double forward, double reverse) Sets the peak duty-cycle output limits.- Parameters:
forward- maximum forward output, [0, 1]reverse- maximum reverse output, [-1, 0]
-
configForwardSoftLimit
public void configForwardSoftLimit(double threshold, boolean enabled) Configures the forward software limit, with the threshold in rotations. -
configReverseSoftLimit
public void configReverseSoftLimit(double threshold, boolean enabled) Configures the reverse software limit, with the threshold in rotations. -
configContinuousWrap
public void configContinuousWrap(boolean enabled) Enables or disables continuous wrap-around in closed-loop control, for a mechanism that turns indefinitely such as a swerve azimuth. -
configMotionMagicVelocity
public void configMotionMagicVelocity(double acceleration, double feedforward) Sets the Motion Magic acceleration and feed-forward on both the FOC and the voltage velocity requests.- Parameters:
acceleration- in rotations per second squared
-
configMotionMagicPosition
public void configMotionMagicPosition(double feedforward) Sets the feed-forward term on every Motion Magic position request. -
configMotionMagic
public void configMotionMagic(double cruiseVelocity, double acceleration, double jerk) Sets the Motion Magic trajectory limits.- Parameters:
cruiseVelocity- in rotations per secondacceleration- in rotations per second squaredjerk- in rotations per second cubed
-
configGearRatio
public void configGearRatio(double gearRatio) Sets the sensor-to-mechanism gear ratio, counted in sensor turns per mechanism output turn, so 11.25 means 11.25 sensor turns per output rotation. -
getGearRatio
public double getGearRatio()The configured sensor-to-mechanism gear ratio. -
configNeutralBrakeMode
public void configNeutralBrakeMode(boolean isInBrake) Sets brake mode when isInBrake is true, coast when it is false. -
configPIDGains
public void configPIDGains(double kP, double kI, double kD) Configures the PID gains in slot 0. -
configPIDGains
public void configPIDGains(int slot, double kP, double kI, double kD) Configures the PID gains in a gain slot.- Parameters:
slot- the gain slot, 0, 1 or 2
-
configFeedForwardGains
public void configFeedForwardGains(double kS, double kV, double kA, double kG) Configures the feed-forward gains in slot 0.- Parameters:
kS- static friction compensation, in volts or amps depending on the control mode
-
configFeedForwardGains
public void configFeedForwardGains(int slot, double kS, double kV, double kA, double kG) Configures the feed-forward gains in a gain slot.- Parameters:
slot- the gain slot, 0, 1 or 2kS- static friction compensation, in volts or amps depending on the control mode
-
configFeedbackSensorSource
Configures the feedback sensor source with a rotor offset of 0. -
configFeedbackSensorSource
Configures the feedback sensor source and its rotor offset, in rotations. -
configGravityType
public void configGravityType(boolean isArm) Configures the gravity compensation type in slot 0.- Parameters:
isArm- true forGravityTypeValue.Arm_Cosineon a rotating arm, false forGravityTypeValue.Elevator_Staticon an elevator
-
configGravityType
public void configGravityType(int slot, boolean isArm) Configures the gravity compensation type in a gain slot.- Parameters:
slot- the gain slot, 0, 1 or 2isArm- true forGravityTypeValue.Arm_Cosineon a rotating arm, false forGravityTypeValue.Elevator_Staticon an elevator
-
configMinMaxRotations
protected void configMinMaxRotations(double minRotation, double maxRotation) Sets the rotation limits the percentage helpers such asMechanism.percentToRotations(java.util.function.DoubleSupplier)convert against. -
getName
Name for this mechanism, used in log keys and alerts. -
isAttached
public boolean isAttached()False builds no hardware, which is how the sim runs a real mechanism config. -
setAttached
public void setAttached(boolean attached) False builds no hardware, which is how the sim runs a real mechanism config. -
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
-
getTalonConfig
Applied to the leader motor on startup. -
setTalonConfig
Applied to the leader motor on startup. -
getNumMotors
public int getNumMotors()Leader plus followers. -
getVoltageCompSaturation
public double getVoltageCompSaturation()Saturation forMechanism.setPercentOutput(java.util.function.DoubleSupplier), 12 V by default. -
getMinRotations
public double getMinRotations()Bottom of the mechanism's range, in rotations, for the percentage helpers. -
getMaxRotations
public double getMaxRotations()Top of the mechanism's range, in rotations, for the percentage helpers. -
getFollowerConfigs
Empty when the mechanism runs on the leader alone. -
getMmVelocityFOC
-
getMmPositionFOC
-
getPositionTorqueFOC
-
getDynamicMMPositionFOC
-
getDynamicMotionMagicVoltage
-
getMmVelocityVoltage
-
getMmPositionVoltage
-
getMmPositionVoltageSlot
-
getVoltageControl
-
getVelocityControl
-
getPositionControl
-
getVelocityTorqueCurrentFOC
-
getTorqueCurrentFOC
-
getPercentOutput
Percent output control. PrefervoltageControlin most cases.
-