Class TalonFXConfig
java.lang.Object
com.stuypulse.robot.util.talonfx.config.TalonFXConfig
Wrapper class for configuring TalonFX motors
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final com.ctre.phoenix6.configs.ClosedLoopGeneralConfigsprivate final com.ctre.phoenix6.configs.ClosedLoopRampsConfigsprivate final com.ctre.phoenix6.configs.TalonFXConfigurationprivate final com.ctre.phoenix6.configs.CurrentLimitsConfigsprivate final com.ctre.phoenix6.configs.FeedbackConfigsprivate final double[]private final double[]private final double[]private final double[]private final double[]private final double[]private final com.ctre.phoenix6.configs.MotionMagicConfigsprivate final com.ctre.phoenix6.configs.MotorOutputConfigsprivate final com.ctre.phoenix6.configs.OpenLoopRampsConfigsprivate final com.ctre.phoenix6.configs.Slot0Configsprivate final com.ctre.phoenix6.configs.Slot1Configsprivate final com.ctre.phoenix6.configs.Slot2Configsprivate final com.ctre.phoenix6.configs.SoftwareLimitSwitchConfigsprivate final com.ctre.phoenix6.configs.TorqueCurrentConfigsprivate final com.ctre.phoenix6.configs.VoltageConfigs -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconfigure(com.ctre.phoenix6.hardware.TalonFX motor) com.ctre.phoenix6.configs.TalonFXConfigurationvoidupdateGainsConfig(com.ctre.phoenix6.hardware.TalonFX motor, int slot, double kP, double kI, double kD, double kS, double kV, double kA) withFFConstants(double kS, double kV, double kA, double kG, int slot) withFFConstants(double kS, double kV, double kA, int slot) withGainSchedBehavior(com.ctre.phoenix6.signals.GainSchedBehaviorValue value, double thresholdRotations, int slot) Modifies this configuration's GainSchedErrorThreshold parameter, which is the position closed-loop error threshold to apply gains scheduling.withGainSchedBehavior(com.ctre.phoenix6.signals.GainSchedBehaviorValue value, org.wpilib.units.measure.Angle threshold, int slot) Modifies this configuration's GainSchedErrorThreshold parameter, which is the position closed-loop error threshold to apply gains scheduling.withGravityType(com.ctre.phoenix6.signals.GravityTypeValue gravityType) withInvertedValue(com.ctre.phoenix6.signals.InvertedValue invertedValue) withLowerLimitSupplyCurrent(double currentLowerLimitAmps, double timeSeconds) Modifies this configuration's supply current lower limit.withLowerLimitSupplyCurrent(org.wpilib.units.measure.Current currentLowerLimit, org.wpilib.units.measure.Time time) Modifies this configuration's supply current lower limit.withMotionProfile(double maxVelocityRotPerSec, double maxAccelerationRotPerSecSquared) Modifies this configuration's motion magic profile.withMotionProfile(org.wpilib.units.measure.AngularVelocity maxVelocity, org.wpilib.units.measure.AngularAcceleration maxAcceleration) Modifies this configuration's motion magic profile.withNeutralMode(com.ctre.phoenix6.signals.NeutralModeValue neutralMode) withPIDConstants(double kP, double kI, double kD, int slot) withRampRate(double rampRateSeconds) Modifies this configuration's open and closed loop ramp periods for the following control types: DutyCycle TorqueCurrent VoltagewithRampRate(org.wpilib.units.measure.Time rampRate) Modifies this configuration's open and closed loop ramp periods for the following control types: DutyCycle TorqueCurrent VoltagewithRemoteSensor(int ID, com.ctre.phoenix6.signals.FeedbackSensorSourceValue source, double rotorToSensorRatio) withSensorToMechanismRatio(double sensorToMechanismRatio) withSoftLimits(boolean forwardEnable, boolean reverseEnable, double forwardThresholdRotations, double reverseThresholdRotations) Modifies this configuration's software limit switch.withSoftLimits(boolean forwardEnable, boolean reverseEnable, org.wpilib.units.measure.Angle forwardThreshold, org.wpilib.units.measure.Angle reverseThreshold) Modifies this configuration's software limit switch.withStaticFeedforwardSign(com.ctre.phoenix6.signals.StaticFeedforwardSignValue staticFeedforwardSign, int slot) withStatorCurrentLimit(double currentLimitAmps) Modifies this configuration's stator current limit and enables it.withStatorCurrentLimit(org.wpilib.units.measure.Current currentLimit) Modifies this configuration's stator current limit and enables it.withStatorCurrentLimitEnabled(boolean enabled) withSupplyCurrentLimit(double currentLimitAmps) Modifies this configuration's supply current limit and enables it.withSupplyCurrentLimit(org.wpilib.units.measure.Current currentLimit) Modifies this configuration's supply current limit and enables it.withSupplyCurrentLimitEnabled(boolean enabled) withTorqueCurrentLimits(double peakForwardTorqueCurrentAmps, double peakReverseTorqueCurrentAmps, double neutralToleranceAmps) Modifies this configuration's torque current limits.withTorqueCurrentLimits(org.wpilib.units.measure.Current peakForwardTorqueCurrent, org.wpilib.units.measure.Current peakReverseTorqueCurrent, org.wpilib.units.measure.Current neutralTolerance) Modifies this configuration's torque current limits.withVelocityTimeFilter(double filterTimeSeconds) Modifies this configuration's velocity filter's time constant.withVelocityTimeFilter(org.wpilib.units.measure.Time filterTime) Modifies this configuration's velocity filter's time constant.withVoltageLimits(double peakForwardVolts, double peakReverseVolts) Modifies this configuration's voltage limits.withVoltageLimits(org.wpilib.units.measure.Voltage peakForwardVoltage, org.wpilib.units.measure.Voltage peakReverseVoltage) Modifies this configuration's voltage limits.
-
Field Details
-
configuration
-
slot0Configs
-
slot1Configs
-
slot2Configs
-
motorOutputConfigs
-
closedLoopRampsConfigs
-
openLoopRampsConfigs
-
currentLimitsConfigs
-
feedbackConfigs
-
motionMagicConfigs
-
softwareLimitSwitchConfigs
-
closedLoopGeneralConfigs
-
voltageConfigs
-
torqueCurrentConfigs
-
lastKP
-
lastKI
-
lastKD
-
lastKS
-
lastKV
-
lastKA
-
-
Constructor Details
-
TalonFXConfig
public TalonFXConfig()
-
-
Method Details
-
configure
-
getConfiguration
-
updateGainsConfig
public void updateGainsConfig(com.ctre.phoenix6.hardware.TalonFX motor, int slot, double kP, double kI, double kD, double kS, double kV, double kA) -
withPIDConstants
-
withFFConstants
-
withFFConstants
-
withStaticFeedforwardSign
public TalonFXConfig withStaticFeedforwardSign(com.ctre.phoenix6.signals.StaticFeedforwardSignValue staticFeedforwardSign, int slot) -
withGravityType
-
withGainSchedBehavior
public TalonFXConfig withGainSchedBehavior(com.ctre.phoenix6.signals.GainSchedBehaviorValue value, double thresholdRotations, int slot) Modifies this configuration's GainSchedErrorThreshold parameter, which is the position closed-loop error threshold to apply gains scheduling.- Parameters:
value- Gains scheduling behavior, seeGainSchedBehaviorValue.thresholdRotations- The position closed-loop error threshold for gain scheduling in rotations.slot- Slot to apply gains scheduling behavior to.- Returns:
- Itself for method-chaining.
-
withGainSchedBehavior
public TalonFXConfig withGainSchedBehavior(com.ctre.phoenix6.signals.GainSchedBehaviorValue value, org.wpilib.units.measure.Angle threshold, int slot) Modifies this configuration's GainSchedErrorThreshold parameter, which is the position closed-loop error threshold to apply gains scheduling.- Parameters:
value- Gains scheduling behavior, seeGainSchedBehaviorValue.threshold- The position closed-loop error threshold for gain scheduling.slot- Slot to apply gains scheduling behavior to.- Returns:
- Itself for method-chaining.
-
withInvertedValue
-
withNeutralMode
-
withVelocityTimeFilter
Modifies this configuration's velocity filter's time constant.- Parameters:
filterTimeSeconds- The configurable time constant in seconds of the Kalman velocity filter.- Returns:
- Itself for easier method-chaining
-
withVelocityTimeFilter
Modifies this configuration's velocity filter's time constant.- Parameters:
filterTime- The configurable time constant of the Kalman velocity filter.- Returns:
- Itself for easier method-chaining
-
withRampRate
Modifies this configuration's open and closed loop ramp periods for the following control types:- DutyCycle
- TorqueCurrent
- Voltage
- Parameters:
rampRateSeconds- Seconds for the motor to reach peak output from 0- Returns:
- Itself for method-chaining
-
withRampRate
Modifies this configuration's open and closed loop ramp periods for the following control types:- DutyCycle
- TorqueCurrent
- Voltage
- Parameters:
rampRate- Time for the motor to reach peak output from 0- Returns:
- Itself for easy method chaining
-
withLowerLimitSupplyCurrent
Modifies this configuration's supply current lower limit.- Parameters:
currentLowerLimitAmps- The amount of supply current in amperes allowed after the regularCurrentLimitsConfigs.SupplyCurrentLimitis active for longer than the time parameter.timeSeconds- The amount of time in seconds that the regularCurrentLimitsConfigs.SupplyCurrentLimitcan be active before lowring it to the currentLowerLimit parameter.- Returns:
-
withLowerLimitSupplyCurrent
public TalonFXConfig withLowerLimitSupplyCurrent(org.wpilib.units.measure.Current currentLowerLimit, org.wpilib.units.measure.Time time) Modifies this configuration's supply current lower limit.- Parameters:
currentLowerLimit- The amount of supply current allowed after the regularCurrentLimitsConfigs.SupplyCurrentLimitis active for longer than the time parameter.time- The amount of time that the regularCurrentLimitsConfigs.SupplyCurrentLimitcan be active before lowring it to the currentLowerLimit parameter.- Returns:
-
withSupplyCurrentLimit
Modifies this configuration's supply current limit and enables it.- Parameters:
currentLimitAmps- Maximum allowed current in amperes drawn from the battery.- Returns:
- Itself for easier method-chaining.
-
withSupplyCurrentLimit
Modifies this configuration's supply current limit and enables it.- Parameters:
currentLimit- Maximum allowed current drawn from the battery.- Returns:
- Itself for easier method-chaining.
-
withSupplyCurrentLimitEnabled
-
withStatorCurrentLimit
Modifies this configuration's stator current limit and enables it.- Parameters:
currentLimitAmps- Amount of current in amperes allowed in the motor (motoring and regen current).- Returns:
- Itself for easier method chaining.
-
withStatorCurrentLimit
Modifies this configuration's stator current limit and enables it.- Parameters:
currentLimit- Amount of current allowed in the motor (motoring and regen current).- Returns:
- Itself for easier method chaining.
-
withStatorCurrentLimitEnabled
-
withTorqueCurrentLimits
public TalonFXConfig withTorqueCurrentLimits(double peakForwardTorqueCurrentAmps, double peakReverseTorqueCurrentAmps, double neutralToleranceAmps) Modifies this configuration's torque current limits. Limits apply during torque current control modes.- Parameters:
peakForwardTorqueCurrentAmps- Maximum forward torque current output in amperes.peakReverseTorqueCurrentAmps- Maximum reverse torque current output in amperes.neutralToleranceAmps- Current range in amperes where requested torque current will result in zero bridge output.- Returns:
- Itself for easier method-chaining.
-
withTorqueCurrentLimits
public TalonFXConfig withTorqueCurrentLimits(org.wpilib.units.measure.Current peakForwardTorqueCurrent, org.wpilib.units.measure.Current peakReverseTorqueCurrent, org.wpilib.units.measure.Current neutralTolerance) Modifies this configuration's torque current limits. Limits apply during torque current control modes.- Parameters:
peakForwardTorqueCurrent- Maximum forward torque current output.peakReverseTorqueCurrent- Maximum reverse torque current output.neutralTolerance- Current range where requested torque current will result in zero bridge output.- Returns:
- Itself for easier method-chaining.
-
withVoltageLimits
Modifies this configuration's voltage limits. Limits apply during voltage control modes.- Parameters:
peakForwardVolts- Maximum forward voltage output in volts.peakReverseVolts- Maximum reverse voltage output in volts.- Returns:
- Itself for easier method chaining.
-
withVoltageLimits
public TalonFXConfig withVoltageLimits(org.wpilib.units.measure.Voltage peakForwardVoltage, org.wpilib.units.measure.Voltage peakReverseVoltage) Modifies this configuration's voltage limits. Limits apply during voltage control modes.- Parameters:
peakForwardVoltage- Maximum forward voltage output.peakReverseVoltage- Maximum reverse voltage output.- Returns:
- Itself for easier method chaining.
-
withSoftLimits
public TalonFXConfig withSoftLimits(boolean forwardEnable, boolean reverseEnable, double forwardThresholdRotations, double reverseThresholdRotations) Modifies this configuration's software limit switch.- Parameters:
forwardEnable- Whether to set the motor output to neutral if its position exceeds the forward threshold.reverseEnable- Whether to set the motor output to neutral if its position exceeds the reverse threshold.forwardThresholdRotations- The threshold angle in rotations for the application of the forward limit.reverseThresholdRotations- The threshold angle in rotations for the application of the reverse limit.- Returns:
- Itself for easier method-chaining.
-
withSoftLimits
public TalonFXConfig withSoftLimits(boolean forwardEnable, boolean reverseEnable, org.wpilib.units.measure.Angle forwardThreshold, org.wpilib.units.measure.Angle reverseThreshold) Modifies this configuration's software limit switch.- Parameters:
forwardEnable- Whether to set the motor output to neutral if its position exceeds the forward threshold.reverseEnable- Whether to set the motor output to neutral if its position exceeds the reverse threshold.forwardThreshold- The threshold angle for the application of the forward limit.reverseThreshold- The threshold angle for the application of the reverse limit.- Returns:
- Itself for easier method-chaining.
-
withMotionProfile
public TalonFXConfig withMotionProfile(double maxVelocityRotPerSec, double maxAccelerationRotPerSecSquared) Modifies this configuration's motion magic profile.- Parameters:
maxVelocityRotPerSec- Maximum/cruise velocity of the motion profile in rotations per second.maxAccelerationRotPerSecSquared- Maximum acceleration of the motion profile in rotations per second squared.- Returns:
- Itself for method-chaining.
-
withMotionProfile
public TalonFXConfig withMotionProfile(org.wpilib.units.measure.AngularVelocity maxVelocity, org.wpilib.units.measure.AngularAcceleration maxAcceleration) Modifies this configuration's motion magic profile.- Parameters:
maxVelocity- Maximum/cruise velocity of the motion profile.maxAcceleration- Maximum acceleration of the motion profile.- Returns:
- Itself for method-chaining.
-
withRemoteSensor
public TalonFXConfig withRemoteSensor(int ID, com.ctre.phoenix6.signals.FeedbackSensorSourceValue source, double rotorToSensorRatio) -
withSensorToMechanismRatio
-