22 class CANcoderConfiguration;
23 class CANdiConfiguration;
24 class TalonFXConfiguration;
25 class TalonFXSConfiguration;
45 std::derived_from<hardware::traits::CommonTalon> DriveMotorT,
46 std::derived_from<hardware::traits::CommonTalon> SteerMotorT,
49 requires std::same_as<EncoderT, hardware::CANcoder> ||
50 std::same_as<EncoderT, hardware::CANdi> ||
51 std::same_as<EncoderT, hardware::TalonFXS>
67 DriveMotorT _driveMotor;
68 SteerMotorT _steerMotor;
85 _driveMotor{constants.DriveMotorId, canbus},
86 _steerMotor{constants.SteerMotorId, canbus},
87 _encoder{constants.EncoderId, canbus}
96 driveConfigs.TorqueCurrent.PeakForwardTorqueCurrent = constants.
SlipCurrent;
97 driveConfigs.TorqueCurrent.PeakReverseTorqueCurrent = -constants.
SlipCurrent;
99 driveConfigs.CurrentLimits.StatorCurrentLimit = constants.
SlipCurrent;
100 driveConfigs.CurrentLimits.StatorCurrentLimitEnable =
true;
106 "Cannot use TalonFX_Integrated drive motor type on Talon FXS ID %d. TalonFX_Integrated is only supported on Talon FX.",
120 printf(
"Drive motor Talon FX ID %d only supports TalonFX_Integrated.",
GetDriveMotor().GetDeviceID());
127 response =
GetDriveMotor().GetConfigurator().Apply(driveConfigs);
128 if (response.IsOK())
break;
130 if (!response.IsOK()) {
131 printf(
"Talon ID %d failed config with error %s\n",
GetDriveMotor().GetDeviceID(), response.GetName());
143 "Cannot use TalonFX_Integrated steer motor type on Talon FXS ID %d. TalonFX_Integrated is only supported on Talon FX.",
175 steerConfigs.ExternalFeedback.FeedbackRemoteSensorID = constants.
EncoderId;
208 steerConfigs.ExternalFeedback.AbsoluteSensorOffset = constants.
EncoderOffset;
217 printf(
"Steer motor Talon FX ID %d only supports TalonFX_Integrated.",
GetSteerMotor().GetDeviceID());
221 steerConfigs.Feedback.FeedbackRemoteSensorID = constants.
EncoderId;
254 "Cannot use Pulse Width steer feedback type on Talon FX ID %d. Pulse Width is only supported on Talon FXS.\n",
262 steerConfigs.MotionMagic.MotionMagicExpo_kV = 0.12_V / 1_tps * constants.
SteerMotorGearRatio;
263 steerConfigs.MotionMagic.MotionMagicExpo_kA = 0.8_V / 1_tr_per_s_sq / constants.
SteerMotorGearRatio;
265 steerConfigs.ClosedLoopGeneral.ContinuousWrap =
true;
271 response =
GetSteerMotor().GetConfigurator().Apply(steerConfigs);
272 if (response.IsOK())
break;
274 if (!response.IsOK()) {
275 printf(
"Talon ID %d failed config with error %s\n",
GetSteerMotor().GetDeviceID(), response.GetName());
280 encoderConfigs.MagnetSensor.MagnetOffset = constants.
EncoderOffset;
281 encoderConfigs.MagnetSensor.SensorDirection = constants.
EncoderInverted
286 response =
GetEncoder().GetConfigurator().Apply(encoderConfigs);
287 if (response.IsOK())
break;
289 if (!response.IsOK()) {
290 printf(
"Encoder ID %d failed config with error %s\n",
GetEncoder().GetDeviceID(), response.GetName());
294 response =
GetEncoder().GetConfigurator().Apply(encoderConfigs.DigitalInputs);
295 if (response.IsOK())
break;
297 if (!response.IsOK()) {
298 printf(
"Encoder ID %d failed config with error %s\n",
GetEncoder().GetDeviceID(), response.GetName());
302 response =
GetEncoder().GetConfigurator().Apply(encoderConfigs.CustomParams);
303 if (response.IsOK())
break;
305 if (!response.IsOK()) {
306 printf(
"Encoder ID %d failed config with error %s\n",
GetEncoder().GetDeviceID(), response.GetName());
313 encoderConfigs.PWM1.AbsoluteSensorOffset = constants.
EncoderOffset;
317 response =
GetEncoder().GetConfigurator().Apply(encoderConfigs.PWM1);
318 if (response.IsOK())
break;
320 if (!response.IsOK()) {
321 printf(
"Encoder ID %d failed config with error %s\n",
GetEncoder().GetDeviceID(), response.GetName());
328 encoderConfigs.PWM2.AbsoluteSensorOffset = constants.
EncoderOffset;
332 response =
GetEncoder().GetConfigurator().Apply(encoderConfigs.PWM2);
333 if (response.IsOK())
break;
335 if (!response.IsOK()) {
336 printf(
"Encoder ID %d failed config with error %s\n",
GetEncoder().GetDeviceID(), response.GetName());
367 std::derived_from<controls::ControlRequest> DriveReq,
368 std::derived_from<controls::ControlRequest> SteerReq
370 void Apply(DriveReq &&driveRequest, SteerReq &&steerRequest)
372 return _module->
Apply(std::forward<DriveReq>(driveRequest), std::forward<SteerReq>(steerRequest));
Class for getting information about an available CAN bus.
Definition CANBus.hpp:19
Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along w...
Definition CoreCANcoder.hpp:40
Class for CTR Electronics' CANdi™ branded device, a device that integrates digital signals into the e...
Definition CoreCANdi.hpp:45
Class description for the Talon FXS motor controller.
Definition CoreTalonFXS.hpp:133
Swerve Module class that encapsulates a swerve module powered by CTR Electronics devices.
Definition SwerveModule.hpp:52
virtual void Apply(ModuleRequest const &moduleRequest)
Applies the desired ModuleRequest to this module.
Definition SwerveModule.hpp:353
SwerveModulePosition GetCachedPosition() const
Gets the last cached swerve module position.
Definition SwerveModule.hpp:396
virtual ~SwerveModule()=default
SteerMotorT & GetSteerMotor()
Gets this module's Steer Motor reference.
Definition SwerveModule.hpp:487
ClosedLoopOutputType GetSteerClosedLoopOutputType() const
Gets the closed-loop output type to use for the steer motor.
Definition SwerveModule.hpp:449
impl::SwerveModuleImpl * _module
The underlying swerve module instance.
Definition SwerveModule.hpp:64
SteerMotorT const & GetSteerMotor() const
Gets this module's Steer Motor reference.
Definition SwerveModule.hpp:499
EncoderT const & GetEncoder() const
Gets this module's azimuth encoder reference.
Definition SwerveModule.hpp:524
void Apply(DriveReq &&driveRequest, SteerReq &&steerRequest)
Controls this module using the specified drive and steer control requests.
Definition SwerveModule.hpp:370
SwerveModuleState GetCurrentState() const
Get the current state of the module.
Definition SwerveModule.hpp:409
ClosedLoopOutputType GetDriveClosedLoopOutputType() const
Gets the closed-loop output type to use for the drive motor.
Definition SwerveModule.hpp:439
EncoderT & GetEncoder()
Gets this module's azimuth encoder reference.
Definition SwerveModule.hpp:512
SwerveModuleState GetTargetState() const
Get the target state of the module.
Definition SwerveModule.hpp:421
SwerveModule(SwerveModuleConstants< typename DriveMotorT::Configuration, typename SteerMotorT::Configuration, typename EncoderT::Configuration > const &constants, CANBus canbus, impl::SwerveModuleImpl &module)
Construct a SwerveModule with the specified constants.
Definition SwerveModule.hpp:79
SwerveModulePosition GetPosition(bool refresh)
Gets the state of this module and passes it back as a SwerveModulePosition object with latency compen...
Definition SwerveModule.hpp:384
DriveMotorT & GetDriveMotor()
Gets this module's Drive Motor reference.
Definition SwerveModule.hpp:462
DriveMotorT const & GetDriveMotor() const
Gets this module's Drive Motor reference.
Definition SwerveModule.hpp:474
virtual void ResetPosition()
Resets this module's drive motor position to 0 rotations.
Definition SwerveModule.hpp:429
static constexpr int kNumConfigAttempts
Number of times to attempt config applies.
Definition SwerveModule.hpp:61
Swerve Module class that encapsulates a swerve module powered by CTR Electronics devices.
Definition SwerveModuleImpl.hpp:61
SwerveModuleState GetCurrentState() const
Get the current state of the module.
Definition SwerveModuleImpl.hpp:361
ClosedLoopOutputType GetSteerClosedLoopOutputType() const
Gets the closed-loop output type to use for the steer motor.
Definition SwerveModuleImpl.hpp:399
SwerveModuleState GetTargetState() const
Get the target state of the module.
Definition SwerveModuleImpl.hpp:373
void Apply(ModuleRequest const &moduleRequest)
Applies the desired ModuleRequest to this module.
ClosedLoopOutputType GetDriveClosedLoopOutputType() const
Gets the closed-loop output type to use for the drive motor.
Definition SwerveModuleImpl.hpp:389
SwerveModulePosition GetPosition(bool refresh)
Gets the state of this module and passes it back as a SwerveModulePosition object with latency compen...
void ResetPosition()
Resets this module's drive motor position to 0 rotations.
Definition SwerveModuleImpl.hpp:378
SwerveModulePosition GetCachedPosition() const
Gets the last cached swerve module position.
Definition SwerveModuleImpl.hpp:351
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
SteerRequestType
All possible control requests for the module steer motor.
Definition SwerveModuleImpl.hpp:25
DriveRequestType
All possible control requests for the module drive motor.
Definition SwerveModuleImpl.hpp:41
ClosedLoopOutputType
Supported closed-loop output types.
Definition SwerveModuleConstants.hpp:22
@ TalonFXS_Brushed_AC
Brushed motor connected to a Talon FXS on terminals A and C.
@ TalonFXS_Brushed_AB
Brushed motor connected to a Talon FXS on terminals A and B.
@ TalonFX_Integrated
Talon FX integrated brushless motor.
@ TalonFXS_Brushed_BC
Brushed motor connected to a Talon FXS on terminals B and C.
@ TalonFXS_NEO550_JST
Third party NEO550 brushless motor connected to a Talon FXS over JST.
@ TalonFXS_NEO_JST
Third party NEO brushless motor connected to a Talon FXS over JST.
@ TalonFXS_VORTEX_JST
Third party VORTEX brushless motor connected to a Talon FXS over JST.
@ TalonFXS_Minion_JST
CTR Electronics Minion® brushless motor connected to a Talon FXS over JST.
@ FusedCANcoder
Requires Pro; Use signals::FeedbackSensorSourceValue::FusedCANcoder for the steer motor.
@ SyncCANdiPWM2
Requires Pro; Use signals::FeedbackSensorSourceValue::SyncCANdiPWM2 for the steer motor.
@ SyncCANdiPWM1
Requires Pro; Use signals::FeedbackSensorSourceValue::SyncCANdiPWM1 for the steer motor.
@ RemoteCANdiPWM2
Use signals::FeedbackSensorSourceValue::RemoteCANdiPWM2 for the steer motor.
@ FusedCANdiPWM2
Requires Pro; Use signals::FeedbackSensorSourceValue::FusedCANdiPWM2 for the steer motor.
@ FusedCANdiPWM1
Requires Pro; Use signals::FeedbackSensorSourceValue::FusedCANdiPWM1 for the steer motor.
@ RemoteCANdiPWM1
Use signals::FeedbackSensorSourceValue::RemoteCANdiPWM1 for the steer motor.
@ SyncCANcoder
Requires Pro; Use signals::FeedbackSensorSourceValue::SyncCANcoder for the steer motor.
@ TalonFXS_PulseWidth
Use signals::ExternalFeedbackSensorSourceValue::PulseWidth for the steer motor.
@ RemoteCANcoder
Use signals::FeedbackSensorSourceValue::RemoteCANcoder for the steer motor.
@ TalonFX_Integrated
Talon FX integrated brushless motor.
@ TalonFXS_NEO_JST
Third party NEO brushless motor connected to a Talon FXS over JST.
@ TalonFXS_VORTEX_JST
Third party VORTEX brushless motor connected to a Talon FXS over JST.
Definition motor_constants.h:14
static constexpr int Leads_A_and_B
Third party brushed DC motor with two leads.
Definition SpnEnums.hpp:3700
static constexpr int Leads_B_and_C
Third party brushed DC motor with two leads.
Definition SpnEnums.hpp:3724
static constexpr int Leads_A_and_C
Third party brushed DC motor with two leads.
Definition SpnEnums.hpp:3712
static constexpr int SyncCANcoder
Requires Phoenix Pro; Talon will synchronize its commutation sensor position against another CANcoder...
Definition SpnEnums.hpp:3325
static constexpr int FusedCANdiPWM2
Requires Phoenix Pro; Talon will fuse a pulse-width encoder remotely attached to the Sensor Input 2 (...
Definition SpnEnums.hpp:3374
static constexpr int SyncCANdiPWM1
Requires Phoenix Pro; Talon will synchronize its internal rotor position against the pulse-width enco...
Definition SpnEnums.hpp:3393
static constexpr int RemoteCANdiPWM1
Use a pulse-width encoder remotely attached to the Sensor Input 1 (S1IN) on CANdi™ (this also require...
Definition SpnEnums.hpp:3343
static constexpr int SyncCANdiPWM2
Requires Phoenix Pro; Talon will synchronize its internal rotor position against the pulse-width enco...
Definition SpnEnums.hpp:3405
static constexpr int RemoteCANcoder
Use another CANcoder on the same CAN bus (this also requires setting FeedbackRemoteSensorID).
Definition SpnEnums.hpp:3284
static constexpr int FusedCANdiPWM1
Requires Phoenix Pro; Talon will fuse a pulse-width encoder remotely attached to the Sensor Input 1 (...
Definition SpnEnums.hpp:3366
static constexpr int FusedCANcoder
Requires Phoenix Pro; Talon will fuse another CANcoder's information with the commutation sensor,...
Definition SpnEnums.hpp:3313
static constexpr int RemoteCANdiPWM2
Use a pulse-width encoder remotely attached to the Sensor Input 2 (S2IN) on CANdi™ (this also require...
Definition SpnEnums.hpp:3351
static constexpr int PulseWidth
Use a pulse-width encoder directly attached to the Talon data port.
Definition SpnEnums.hpp:3335
static constexpr int RemoteCANcoder
Use another CANcoder on the same CAN bus (this also requires setting FeedbackRemoteSensorID).
Definition SpnEnums.hpp:1699
static constexpr int SyncCANdiPWM2
Requires Phoenix Pro; Talon will synchronize its internal rotor position against the pulse-width enco...
Definition SpnEnums.hpp:1811
static constexpr int RemoteCANdiPWM2
Use a pulse-width encoder remotely attached to the Sensor Input 2 (S2IN) on the CTR Electronics' CANd...
Definition SpnEnums.hpp:1756
static constexpr int SyncCANdiPWM1
Requires Phoenix Pro; Talon will synchronize its internal rotor position against the pulse-width enco...
Definition SpnEnums.hpp:1799
static constexpr int SyncCANcoder
Requires Phoenix Pro; Talon will synchronize its internal rotor position against another CANcoder,...
Definition SpnEnums.hpp:1740
static constexpr int RemoteCANdiPWM1
Use a pulse-width encoder remotely attached to the Sensor Input 1 (S1IN) on the CTR Electronics' CANd...
Definition SpnEnums.hpp:1748
static constexpr int FusedCANdiPWM1
Requires Phoenix Pro; Talon will fuse a pulse-width encoder remotely attached to the Sensor Input 1 (...
Definition SpnEnums.hpp:1772
static constexpr int FusedCANcoder
Requires Phoenix Pro; Talon will fuse another CANcoder's information with the internal rotor,...
Definition SpnEnums.hpp:1728
static constexpr int FusedCANdiPWM2
Requires Phoenix Pro; Talon will fuse a pulse-width encoder remotely attached to the Sensor Input 2 (...
Definition SpnEnums.hpp:1780
static constexpr int CounterClockwise_Positive
Positive motor output results in counter-clockwise motion.
Definition SpnEnums.hpp:1554
static constexpr int Clockwise_Positive
Positive motor output results in clockwise motion.
Definition SpnEnums.hpp:1558
static constexpr int NEO_JST
Third party NEO brushless three phase motor (~6000 RPM at 12V).
Definition SpnEnums.hpp:2883
static constexpr int NEO550_JST
Third party NEO550 brushless three phase motor (~11000 RPM at 12V).
Definition SpnEnums.hpp:2895
static constexpr int Brushed_DC
Third party brushed DC motor with two leads.
Definition SpnEnums.hpp:2871
static constexpr int Minion_JST
CTR Electronics Minion® brushless three phase motor.
Definition SpnEnums.hpp:2859
static constexpr int VORTEX_JST
Third party VORTEX brushless three phase motor.
Definition SpnEnums.hpp:2907
static constexpr int Brake
Definition SpnEnums.hpp:1607
static constexpr int CounterClockwise_Positive
Counter-clockwise motion reports positive rotation.
Definition SpnEnums.hpp:201
static constexpr int Clockwise_Positive
Clockwise motion reports positive rotation.
Definition SpnEnums.hpp:205
static constexpr int Aligned
The sensor direction is normally aligned with the motor.
Definition SpnEnums.hpp:3481
static constexpr int Opposed
The sensor direction is normally opposed to the motor.
Definition SpnEnums.hpp:3485
All constants for a swerve module.
Definition SwerveModuleConstants.hpp:148
bool DriveMotorInverted
True if the drive motor is inverted.
Definition SwerveModuleConstants.hpp:180
SteerMotorArrangement SteerMotorType
Choose the motor used for the steer motor.
Definition SwerveModuleConstants.hpp:265
DriveMotorConfigsT DriveMotorInitialConfigs
The initial configs used to configure the drive motor of the swerve module.
Definition SwerveModuleConstants.hpp:299
units::current::ampere_t SlipCurrent
The maximum amount of stator current the drive motors can apply without slippage.
Definition SwerveModuleConstants.hpp:244
units::dimensionless::scalar_t SteerMotorGearRatio
Gear ratio between the steer motor and the azimuth encoder.
Definition SwerveModuleConstants.hpp:201
configs::Slot0Configs DriveMotorGains
The drive motor closed-loop gains.
Definition SwerveModuleConstants.hpp:231
configs::Slot0Configs SteerMotorGains
The steer motor closed-loop gains.
Definition SwerveModuleConstants.hpp:222
SteerFeedbackType FeedbackSource
Choose how the feedback sensors should be configured.
Definition SwerveModuleConstants.hpp:278
int EncoderId
CAN ID of the absolute encoder used for azimuth.
Definition SwerveModuleConstants.hpp:162
DriveMotorArrangement DriveMotorType
Choose the motor used for the drive motor.
Definition SwerveModuleConstants.hpp:258
bool EncoderInverted
True if the azimuth encoder is inverted from the azimuth.
Definition SwerveModuleConstants.hpp:192
SteerMotorConfigsT SteerMotorInitialConfigs
The initial configs used to configure the steer motor of the swerve module.
Definition SwerveModuleConstants.hpp:322
units::angle::turn_t EncoderOffset
Offset of the azimuth encoder.
Definition SwerveModuleConstants.hpp:166
EncoderConfigsT EncoderInitialConfigs
The initial configs used to configure the azimuth encoder of the swerve module.
Definition SwerveModuleConstants.hpp:338
bool SteerMotorInverted
True if the steer motor is inverted from the azimuth.
Definition SwerveModuleConstants.hpp:186
Contains everything the swerve module needs to apply a request.
Definition SwerveModuleImpl.hpp:66