Package frc.spectrumLib.hardware
Class SpectrumCANcoder
java.lang.Object
frc.spectrumLib.hardware.SpectrumCANcoder
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSelects how the TalonFX reads position data from the remote CANcoder. -
Constructor Summary
ConstructorsConstructorDescriptionSpectrumCANcoder(int CANcoderID, SpectrumCANcoderConfig config, TalonFX motor, Mechanism.Config mechConfig, SpectrumCANcoder.CANCoderFeedbackType feedbackSource) Creates and configures a SpectrumCANcoder, then updates the motor's feedback configuration. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanCoderResponseOK(StatusCode response) Checks whether a CANcoder configuration response indicates success.The underlying CTRE CANcoder hardware object.booleanReturns whether this CANcoder is configured as physically present on the robot.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.
-
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 CANcoderconfig- Configuration object containing offset, inversion, and ratio valuesmotor- The TalonFX whose feedback configuration will be updatedmechConfig- The mechanism configuration that holds the TalonFX config to modifyfeedbackSource- 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:
trueif the CANcoder is attached
-
modifyMotorConfig
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 reconfiguremechConfig- The mechanism configuration whose stored TalonFX config is modified in place- Returns:
- this instance, for chaining
-
canCoderResponseOK
Checks whether a CANcoder configuration response indicates success. Prints a warning viaTelemetryif the response is not OK.- Parameters:
response- TheStatusCodereturned by the CANcoder configurator- Returns:
trueif the response is OK,falseotherwise
-
getCanCoder
The underlying CTRE CANcoder hardware object.
-