Class SpectrumCANcoder

java.lang.Object
frc.spectrumLib.hardware.SpectrumCANcoder

public class SpectrumCANcoder extends Object
Wraps a CTRE CANcoder and applies Spectrum-specific configuration. On construction the encoder is configured and the supplied TalonFX motor's feedback source is updated to use it.
  • Constructor Details

    • SpectrumCANcoder

      public SpectrumCANcoder(int CANcoderID, SpectrumCANcoderConfig config, TalonFX motor, Mechanism.Config mechConfig, SpectrumCANcoder.CANCoderFeedbackType feedbackSource)
      Creates and configures a SpectrumCANcoder, then updates the motor's feedback configuration.
      Parameters:
      CANcoderID - CAN device ID of the CANcoder
      config - Configuration object containing offset, inversion, and ratio values
      motor - The TalonFX whose feedback configuration will be updated
      mechConfig - The mechanism configuration that holds the TalonFX config to modify
      feedbackSource - How the TalonFX should read data from this CANcoder
  • Method Details

    • isAttached

      public boolean isAttached()
      Returns whether this CANcoder is configured as physically present on the robot.
      Returns:
      true if the CANcoder is attached
    • modifyMotorConfig

      public SpectrumCANcoder modifyMotorConfig(TalonFX motor, Mechanism.Config mechConfig)
      Updates the TalonFX feedback configuration to reference this CANcoder using the chosen feedback source type and the ratios defined in the config.
      Parameters:
      motor - The TalonFX motor to reconfigure
      mechConfig - The mechanism configuration whose stored TalonFX config is modified in place
      Returns:
      this instance, for chaining
    • canCoderResponseOK

      public boolean canCoderResponseOK(StatusCode response)
      Checks whether a CANcoder configuration response indicates success. Prints a warning via Telemetry if the response is not OK.
      Parameters:
      response - The StatusCode returned by the CANcoder configurator
      Returns:
      true if the response is OK, false otherwise
    • getCanCoder

      public CANcoder getCanCoder()
      The underlying CTRE CANcoder hardware object.