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

public static class Mechanism.Config extends Object
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 Details

    • talonConfig

      protected TalonFXConfiguration talonConfig
      Full TalonFX hardware configuration applied to the leader motor on startup.
  • Constructor Details

    • Config

      public Config(String name, int id, String canbus)
      Creates a base mechanism configuration with default Talon settings. Hardware limit switches are disabled by default.
      Parameters:
      name - human-readable name for this mechanism
      id - CAN device ID of the leader motor
      canbus - CAN bus name (e.g., "rio" or "canivore")
  • Method Details

    • applyTalonConfig

      public void applyTalonConfig(TalonFX talon)
      Applies the current TalonFXConfiguration to the given motor and reports a warning to the DriverStation if the apply fails.
      Parameters:
      talon - the TalonFX motor to configure
    • setFollowerConfigs

      public void setFollowerConfigs(Mechanism.FollowerConfig... followers)
      Sets the follower motor configurations.
      Parameters:
      followers - one or more Mechanism.FollowerConfig objects 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 of supplyLimit is used, so negative values are automatically corrected.
      Parameters:
      supplyLimit - the supply current limit in amps
      enabled - true to enable the limit
    • configStatorCurrentLimit

      public void configStatorCurrentLimit(double statorLimit, boolean enabled)
      Configures the stator current limit. The absolute value of statorLimit is used, so negative values are automatically corrected.
      Parameters:
      statorLimit - the stator current limit in amps
      enabled - true to 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 rotations
      enabled - true to enable the limit
    • configReverseSoftLimit

      public void configReverseSoftLimit(double threshold, boolean enabled)
      Configures the reverse software limit switch.
      Parameters:
      threshold - the position threshold in rotations
      enabled - true to 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 - true to 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 squared
      feedforward - 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 second
      acceleration - maximum acceleration in rotations per second squared
      jerk - 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.25 means 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 - true for brake mode; false for coast mode
    • configPIDGains

      public void configPIDGains(double kP, double kI, double kD)
      Configures PID gains in slot 0.
      Parameters:
      kP - proportional gain
      kI - integral gain
      kD - 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 gain
      kI - integral gain
      kD - 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 gain
      kA - acceleration feed-forward gain
      kG - 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 gain
      kA - acceleration feed-forward gain
      kG - gravity/load compensation gain
    • configFeedbackSensorSource

      public void configFeedbackSensorSource(FeedbackSensorSourceValue source)
      Configures the feedback sensor source using a rotorOffset of 0.
      Parameters:
      source - the feedback sensor source (e.g., remote CANcoder)
    • configFeedbackSensorSource

      public void configFeedbackSensorSource(FeedbackSensorSourceValue source, double offset)
      Configures the feedback sensor source and its rotational offset.
      Parameters:
      source - the feedback sensor source
      offset - the feedback rotor offset in rotations
    • configGravityType

      public void configGravityType(boolean isArm)
      Configures the gravity compensation type in slot 0.
      Parameters:
      isArm - true for GravityTypeValue.Arm_Cosine (rotating arm); false for GravityTypeValue.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 - true for GravityTypeValue.Arm_Cosine (rotating arm); false for GravityTypeValue.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 as Mechanism.percentToRotations(java.util.function.DoubleSupplier).
      Parameters:
      minRotation - the minimum position in rotations
      maxRotation - the maximum position in rotations
    • getName

      public String getName()
      Human-readable name for this mechanism (used in logging and alerts).
    • isAttached

      public boolean isAttached()
      Whether physical hardware is attached. Set to false to run in simulation-only mode.
    • setAttached

      public void setAttached(boolean attached)
      Whether physical hardware is attached. Set to false to run in simulation-only mode.
    • getId

      public CanDeviceId getId()
      CAN bus device ID and bus name for the leader motor.
    • getTalonConfig

      public TalonFXConfiguration getTalonConfig()
      Full TalonFX hardware configuration applied to the leader motor on startup.
    • setTalonConfig

      public void setTalonConfig(TalonFXConfiguration talonConfig)
      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 by Mechanism.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

      public Mechanism.FollowerConfig[] getFollowerConfigs()
      Configurations for follower motors. Empty by default (no followers).
    • getMmVelocityFOC

      public MotionMagicVelocityTorqueCurrentFOC getMmVelocityFOC()
    • getMmPositionFOC

      public MotionMagicTorqueCurrentFOC getMmPositionFOC()
    • getDynamicMMPositionFOC

      public DynamicMotionMagicTorqueCurrentFOC getDynamicMMPositionFOC()
    • getDynamicMotionMagicVoltage

      public DynamicMotionMagicVoltage getDynamicMotionMagicVoltage()
    • getMmVelocityVoltage

      public MotionMagicVelocityVoltage getMmVelocityVoltage()
    • getMmPositionVoltage

      public MotionMagicVoltage getMmPositionVoltage()
    • getMmPositionVoltageSlot

      public MotionMagicVoltage getMmPositionVoltageSlot()
    • getVoltageControl

      public VoltageOut getVoltageControl()
    • getVelocityControl

      public VelocityVoltage getVelocityControl()
    • getVelocityTorqueCurrentFOC

      public VelocityTorqueCurrentFOC getVelocityTorqueCurrentFOC()
    • getTorqueCurrentFOC

      public TorqueCurrentFOC getTorqueCurrentFOC()
    • getPercentOutput

      public DutyCycleOut getPercentOutput()
      Percent (duty-cycle) output control — prefer voltageControl in most cases.