Class TalonFXConfig

java.lang.Object
com.stuypulse.robot.util.talonfx.config.TalonFXConfig

public class TalonFXConfig extends Object
Wrapper class for configuring TalonFX motors
  • Field Details

    • configuration

      private final com.ctre.phoenix6.configs.TalonFXConfiguration configuration
    • slot0Configs

      private final com.ctre.phoenix6.configs.Slot0Configs slot0Configs
    • slot1Configs

      private final com.ctre.phoenix6.configs.Slot1Configs slot1Configs
    • slot2Configs

      private final com.ctre.phoenix6.configs.Slot2Configs slot2Configs
    • motorOutputConfigs

      private final com.ctre.phoenix6.configs.MotorOutputConfigs motorOutputConfigs
    • closedLoopRampsConfigs

      private final com.ctre.phoenix6.configs.ClosedLoopRampsConfigs closedLoopRampsConfigs
    • openLoopRampsConfigs

      private final com.ctre.phoenix6.configs.OpenLoopRampsConfigs openLoopRampsConfigs
    • currentLimitsConfigs

      private final com.ctre.phoenix6.configs.CurrentLimitsConfigs currentLimitsConfigs
    • feedbackConfigs

      private final com.ctre.phoenix6.configs.FeedbackConfigs feedbackConfigs
    • motionMagicConfigs

      private final com.ctre.phoenix6.configs.MotionMagicConfigs motionMagicConfigs
    • softwareLimitSwitchConfigs

      private final com.ctre.phoenix6.configs.SoftwareLimitSwitchConfigs softwareLimitSwitchConfigs
    • closedLoopGeneralConfigs

      private final com.ctre.phoenix6.configs.ClosedLoopGeneralConfigs closedLoopGeneralConfigs
    • voltageConfigs

      private final com.ctre.phoenix6.configs.VoltageConfigs voltageConfigs
    • torqueCurrentConfigs

      private final com.ctre.phoenix6.configs.TorqueCurrentConfigs torqueCurrentConfigs
    • lastKP

      private final double[] lastKP
    • lastKI

      private final double[] lastKI
    • lastKD

      private final double[] lastKD
    • lastKS

      private final double[] lastKS
    • lastKV

      private final double[] lastKV
    • lastKA

      private final double[] lastKA
  • Constructor Details

  • Method Details

    • configure

      public void configure(com.ctre.phoenix6.hardware.TalonFX motor)
    • getConfiguration

      public com.ctre.phoenix6.configs.TalonFXConfiguration 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

      public TalonFXConfig withPIDConstants(double kP, double kI, double kD, int slot)
    • withFFConstants

      public TalonFXConfig withFFConstants(double kS, double kV, double kA, int slot)
    • withFFConstants

      public TalonFXConfig withFFConstants(double kS, double kV, double kA, double kG, int slot)
    • withStaticFeedforwardSign

      public TalonFXConfig withStaticFeedforwardSign(com.ctre.phoenix6.signals.StaticFeedforwardSignValue staticFeedforwardSign, int slot)
    • withGravityType

      public TalonFXConfig withGravityType(com.ctre.phoenix6.signals.GravityTypeValue gravityType)
    • 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, see GainSchedBehaviorValue.
      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, see GainSchedBehaviorValue.
      threshold - The position closed-loop error threshold for gain scheduling.
      slot - Slot to apply gains scheduling behavior to.
      Returns:
      Itself for method-chaining.
    • withInvertedValue

      public TalonFXConfig withInvertedValue(com.ctre.phoenix6.signals.InvertedValue invertedValue)
    • withNeutralMode

      public TalonFXConfig withNeutralMode(com.ctre.phoenix6.signals.NeutralModeValue neutralMode)
    • withVelocityTimeFilter

      public TalonFXConfig withVelocityTimeFilter(double filterTimeSeconds)
      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

      public TalonFXConfig withVelocityTimeFilter(org.wpilib.units.measure.Time filterTime)
      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

      public TalonFXConfig withRampRate(double rampRateSeconds)
      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

      public TalonFXConfig withRampRate(org.wpilib.units.measure.Time rampRate)
      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

      public TalonFXConfig withLowerLimitSupplyCurrent(double currentLowerLimitAmps, double timeSeconds)
      Modifies this configuration's supply current lower limit.
      Parameters:
      currentLowerLimitAmps - The amount of supply current in amperes allowed after the regular CurrentLimitsConfigs.SupplyCurrentLimit is active for longer than the time parameter.
      timeSeconds - The amount of time in seconds that the regular CurrentLimitsConfigs.SupplyCurrentLimit can 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 regular CurrentLimitsConfigs.SupplyCurrentLimit is active for longer than the time parameter.
      time - The amount of time that the regular CurrentLimitsConfigs.SupplyCurrentLimit can be active before lowring it to the currentLowerLimit parameter.
      Returns:
    • withSupplyCurrentLimit

      public TalonFXConfig withSupplyCurrentLimit(double currentLimitAmps)
      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

      public TalonFXConfig withSupplyCurrentLimit(org.wpilib.units.measure.Current currentLimit)
      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

      public TalonFXConfig withSupplyCurrentLimitEnabled(boolean enabled)
    • withStatorCurrentLimit

      public TalonFXConfig withStatorCurrentLimit(double currentLimitAmps)
      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

      public TalonFXConfig withStatorCurrentLimit(org.wpilib.units.measure.Current currentLimit)
      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

      public TalonFXConfig withStatorCurrentLimitEnabled(boolean enabled)
    • 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

      public TalonFXConfig withVoltageLimits(double peakForwardVolts, double peakReverseVolts)
      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

      public TalonFXConfig withSensorToMechanismRatio(double sensorToMechanismRatio)