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
    • configOpenLoopRamps

      public void configOpenLoopRamps(double seconds)
      Sets the open-loop ramp period for duty cycle, voltage, and torque control.
      Parameters:
      seconds - time to ramp from neutral to full output
    • configClosedLoopRamps

      public void configClosedLoopRamps(double seconds)
      Sets the closed-loop ramp period for duty cycle, voltage, and torque control.
      Parameters:
      seconds - time to ramp from neutral to full output
    • 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
    • configSoftLimits

      public void configSoftLimits(DoubleParam forward, DoubleParam reverse)
      Enables both soft limits from params, in mechanism rotations. The config holds the params' defaults; the mechanism takes their values when it is built, after the params files are read, and keeps them until the robot reboots. Give each param bounds that keep every position the code writes into the motor (boot, homing) between the two limits.
      Parameters:
      forward - the forward limit
      reverse - the reverse 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(DoubleSupplier).
      Parameters:
      minRotation - the minimum position in rotations
      maxRotation - the maximum position in rotations
    • configPositionTrackingStop

      public void configPositionTrackingStop(double toleranceRotations, double debounceSeconds, boolean enabled)
      Watches the position loop: the mechanism stops once it has been more than toleranceRotations from its goal for debounceSeconds while enabled and connected. The goal is the final setpoint, not a Motion Magic profile's intermediate one, so the debounce must outlast the longest move.
      Parameters:
      toleranceRotations - largest error, in mechanism rotations
      debounceSeconds - how long it must stay out
      enabled - stop on a fault; false only logs it
    • configVelocityTrackingStop

      public void configVelocityTrackingStop(double toleranceRps, double debounceSeconds, boolean enabled)
      Watches the velocity loop, as configPositionTrackingStop(double, double, boolean) watches position. The debounce must outlast a spin-up from rest.
      Parameters:
      toleranceRps - largest error, in mechanism rotations per second
      debounceSeconds - how long it must stay out
      enabled - stop on a fault; false only logs it
    • 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.
    • 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

      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(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).
    • getTrackingTolerance

      public double getTrackingTolerance()
      Largest closed-loop error the tracking stop tolerates: rotations for a position loop, rotations per second for a velocity loop. NaN (the default) turns it off entirely.
    • getTrackingDebounceSeconds

      public double getTrackingDebounceSeconds()
    • isTrackingVelocity

      public boolean isTrackingVelocity()
      The tracking stop watches the velocity loop, not the position loop.
    • isTrackingStopEnabled

      public boolean isTrackingStopEnabled()
      Stop the mechanism on a tracking fault. Off, a configured tolerance only logs TrackingError and TrackingFault, to check the tolerance against matches first.
    • setTrackingStopEnabled

      public void setTrackingStopEnabled(boolean trackingStopEnabled)
      Stop the mechanism on a tracking fault. Off, a configured tolerance only logs TrackingError and TrackingFault, to check the tolerance against matches first.
    • getMmVelocityFOC

      public MotionMagicVelocityTorqueCurrentFOC getMmVelocityFOC()
    • getMmPositionFOC

      public MotionMagicTorqueCurrentFOC getMmPositionFOC()
    • getPositionTorqueFOC

      public PositionTorqueCurrentFOC getPositionTorqueFOC()
    • 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()
    • getPositionControl

      public PositionVoltage getPositionControl()
    • getVelocityTorqueCurrentFOC

      public VelocityTorqueCurrentFOC getVelocityTorqueCurrentFOC()
    • getTorqueCurrentFOC

      public TorqueCurrentFOC getTorqueCurrentFOC()
    • getPercentOutput

      public DutyCycleOut getPercentOutput()
      Percent (duty-cycle) output control. Prefer voltageControl in most cases.
    • getForwardSoftLimitParam

      public DoubleParam getForwardSoftLimitParam()
      Set by configSoftLimits(DoubleParam, DoubleParam); null when the soft limits are fixed in code.
    • getReverseSoftLimitParam

      public DoubleParam getReverseSoftLimitParam()