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
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 Details

  • Constructor Details

    • Config

      public Config(String name, int id, String canbus)
      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

      public void applyTalonConfig(TalonFX talon)
      Applies the current TalonFXConfiguration to the given motor, reporting a Driver Station warning if the apply fails.
    • setFollowerConfigs

      public void setFollowerConfigs(Mechanism.FollowerConfig... followers)
    • 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 second
      acceleration - in rotations per second squared
      jerk - 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 2
      kS - static friction compensation, in volts or amps depending on the control mode
    • configFeedbackSensorSource

      public void configFeedbackSensorSource(FeedbackSensorSourceValue source)
      Configures the feedback sensor source with a rotor offset of 0.
    • configFeedbackSensorSource

      public void configFeedbackSensorSource(FeedbackSensorSourceValue source, double offset)
      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 for GravityTypeValue.Arm_Cosine on a rotating arm, false for GravityTypeValue.Elevator_Static on 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 2
      isArm - true for GravityTypeValue.Arm_Cosine on a rotating arm, false for GravityTypeValue.Elevator_Static on an elevator
    • configMinMaxRotations

      protected void configMinMaxRotations(double minRotation, double maxRotation)
      Sets the rotation limits the percentage helpers such as Mechanism.percentToRotations(java.util.function.DoubleSupplier) convert against.
    • getName

      public String 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

      public CanDeviceId getId()
    • getTalonConfig

      public TalonFXConfiguration getTalonConfig()
      Applied to the leader motor on startup.
    • setTalonConfig

      public void setTalonConfig(TalonFXConfiguration talonConfig)
      Applied to the leader motor on startup.
    • getNumMotors

      public int getNumMotors()
      Leader plus followers.
    • getVoltageCompSaturation

      public double getVoltageCompSaturation()
    • 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

      public Mechanism.FollowerConfig[] getFollowerConfigs()
      Empty when the mechanism runs on the leader alone.
    • 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 output control. Prefer voltageControl in most cases.