49 std::derived_from<hardware::traits::CommonTalon> DriveMotorT,
50 std::derived_from<hardware::traits::CommonTalon> SteerMotorT,
53 requires std::same_as<EncoderT, hardware::CANcoder> ||
54 std::same_as<EncoderT, hardware::CANdi> ||
55 std::same_as<EncoderT, hardware::TalonFXS>
76 DriveMotorT _driveMotor;
77 SteerMotorT _steerMotor;
90 _driveMotor{constants.DriveMotorId, canbus},
91 _steerMotor{constants.SteerMotorId, canbus},
92 _encoder{constants.EncoderId, canbus}
101 driveConfigs.TorqueCurrent.PeakForwardTorqueCurrent = constants.
SlipCurrent;
102 driveConfigs.TorqueCurrent.PeakReverseTorqueCurrent = -constants.
SlipCurrent;
104 driveConfigs.CurrentLimits.StatorCurrentLimit = constants.
SlipCurrent;
105 driveConfigs.CurrentLimits.StatorCurrentLimitEnable =
true;
108 driveConfigs.ExternalFeedback.RotorToSensorRatio = 1.0;
109 driveConfigs.ExternalFeedback.SensorToMechanismRatio = 1.0;
114 "Cannot use TalonFX_Integrated drive motor type on Talon FXS ID %d. TalonFX_Integrated is only supported on Talon FX.",
127 driveConfigs.Feedback.RotorToSensorRatio = 1.0;
128 driveConfigs.Feedback.SensorToMechanismRatio = 1.0;
131 printf(
"Drive motor Talon FX ID %d only supports TalonFX_Integrated.",
GetDriveMotor().GetDeviceID());
139 response =
GetDriveMotor().GetConfigurator().Apply(driveConfigs);
140 if (response.
IsOK())
break;
142 if (!response.
IsOK()) {
143 printf(
"Talon ID %d failed config with error %s\n",
GetDriveMotor().GetDeviceID(), response.
GetName());
155 "Cannot use TalonFX_Integrated steer motor type on Talon FXS ID %d. TalonFX_Integrated is only supported on Talon FX.",
187 steerConfigs.ExternalFeedback.FeedbackRemoteSensorID = constants.
EncoderId;
220 steerConfigs.ExternalFeedback.AbsoluteSensorOffset = constants.
EncoderOffset;
227 steerConfigs.ExternalFeedback.SensorToMechanismRatio = 1.0;
230 printf(
"Steer motor Talon FX ID %d only supports TalonFX_Integrated.",
GetSteerMotor().GetDeviceID());
234 steerConfigs.Feedback.FeedbackRemoteSensorID = constants.
EncoderId;
267 "Cannot use Pulse Width steer feedback type on Talon FX ID %d. Pulse Width is only supported on Talon FXS.\n",
273 steerConfigs.Feedback.SensorToMechanismRatio = 1.0;
276 steerConfigs.MotionMagic.MotionMagicExpo_kV = 0.12_V / 1_tps * constants.
SteerMotorGearRatio;
277 steerConfigs.MotionMagic.MotionMagicExpo_kA = 1.2_V / 1_tr_per_s_sq / constants.
SteerMotorGearRatio;
279 steerConfigs.ClosedLoopGeneral.ContinuousWrap =
true;
285 response =
GetSteerMotor().GetConfigurator().Apply(steerConfigs);
286 if (response.
IsOK())
break;
288 if (!response.
IsOK()) {
289 printf(
"Talon ID %d failed config with error %s\n",
GetSteerMotor().GetDeviceID(), response.
GetName());
294 encoderConfigs.MagnetSensor.MagnetOffset = constants.
EncoderOffset;
295 encoderConfigs.MagnetSensor.SensorDirection = constants.
EncoderInverted
300 response =
GetEncoder().GetConfigurator().Apply(encoderConfigs);
301 if (response.
IsOK())
break;
303 if (!response.
IsOK()) {
304 printf(
"Encoder ID %d failed config with error %s\n",
GetEncoder().GetDeviceID(), response.
GetName());
308 response =
GetEncoder().GetConfigurator().Apply(encoderConfigs.DigitalInputs);
309 if (response.
IsOK())
break;
311 if (!response.
IsOK()) {
312 printf(
"Encoder ID %d failed config with error %s\n",
GetEncoder().GetDeviceID(), response.
GetName());
316 response =
GetEncoder().GetConfigurator().Apply(encoderConfigs.CustomParams);
317 if (response.
IsOK())
break;
319 if (!response.
IsOK()) {
320 printf(
"Encoder ID %d failed config with error %s\n",
GetEncoder().GetDeviceID(), response.
GetName());
327 encoderConfigs.PWM1.AbsoluteSensorOffset = constants.
EncoderOffset;
331 response =
GetEncoder().GetConfigurator().Apply(encoderConfigs.PWM1);
332 if (response.
IsOK())
break;
334 if (!response.
IsOK()) {
335 printf(
"Encoder ID %d failed config with error %s\n",
GetEncoder().GetDeviceID(), response.
GetName());
342 encoderConfigs.PWM2.AbsoluteSensorOffset = constants.
EncoderOffset;
346 response =
GetEncoder().GetConfigurator().Apply(encoderConfigs.PWM2);
347 if (response.
IsOK())
break;
349 if (!response.
IsOK()) {
350 printf(
"Encoder ID %d failed config with error %s\n",
GetEncoder().GetDeviceID(), response.
GetName());
369 return _module->Apply(moduleRequest);
381 std::derived_from<controls::ControlRequest> DriveReq,
382 std::derived_from<controls::ControlRequest> SteerReq
384 void Apply(DriveReq &&driveRequest, SteerReq &&steerRequest)
386 return _module->Apply(std::forward<DriveReq>(driveRequest), std::forward<SteerReq>(steerRequest));
400 return _module->GetPosition(refresh);
412 return _module->GetCachedPosition();
425 return _module->GetCurrentVelocity();
437 return _module->GetTargetVelocity();
445 return _module->ResetPosition();
455 return _module->GetDriveClosedLoopOutputType();
465 return _module->GetSteerClosedLoopOutputType();
Class for getting information about an available CAN bus.
Definition CANBus.hpp:142
All configurations for the hardware::CANcoder.
Definition CoreCANcoder.hpp:37
All configurations for the hardware::CANdi.
Definition CoreCANdi.hpp:42
All configurations for the hardware::TalonFX.
Definition CoreTalonFX.hpp:156
All configurations for the hardware::TalonFXS.
Definition CoreTalonFXS.hpp:131
Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along w...
Definition CANcoder.hpp:27
Class for CTR Electronics' CANdi™ branded device, a device that integrates digital signals into the e...
Definition CANdi.hpp:26
Class description for the Talon FX integrated motor controller.
Definition TalonFX.hpp:27
Class description for the Talon FXS motor controller.
Definition TalonFXS.hpp:27
impl::SwerveModuleImpl::ModuleRequest ModuleRequest
Contains everything the swerve module needs to apply a request.
Definition SwerveModule.hpp:61
virtual void Apply(ModuleRequest const &moduleRequest)
Applies the desired ModuleRequest to this module.
Definition SwerveModule.hpp:367
SwerveModulePosition GetCachedPosition() const
Gets the last cached swerve module position.
Definition SwerveModule.hpp:410
virtual ~SwerveModule()=default
SteerMotorT & GetSteerMotor()
Gets this module's Steer Motor reference.
Definition SwerveModule.hpp:501
ClosedLoopOutputType GetSteerClosedLoopOutputType() const
Gets the closed-loop output type to use for the steer motor.
Definition SwerveModule.hpp:463
impl::SwerveModuleImpl * _module
The underlying swerve module instance.
Definition SwerveModule.hpp:73
SwerveModuleConstants< typename DriveMotorT::Configuration, typename SteerMotorT::Configuration, typename EncoderT::Configuration > Constants
All constants for a swerve module.
Definition SwerveModule.hpp:66
SteerMotorT const & GetSteerMotor() const
Gets this module's Steer Motor reference.
Definition SwerveModule.hpp:513
EncoderT const & GetEncoder() const
Gets this module's azimuth encoder reference.
Definition SwerveModule.hpp:538
void Apply(DriveReq &&driveRequest, SteerReq &&steerRequest)
Controls this module using the specified drive and steer control requests.
Definition SwerveModule.hpp:384
SwerveModuleVelocity GetTargetVelocity() const
Get the target velocity of the module.
Definition SwerveModule.hpp:435
ClosedLoopOutputType GetDriveClosedLoopOutputType() const
Gets the closed-loop output type to use for the drive motor.
Definition SwerveModule.hpp:453
EncoderT & GetEncoder()
Gets this module's azimuth encoder reference.
Definition SwerveModule.hpp:526
SwerveModulePosition GetPosition(bool refresh)
Gets the state of this module and passes it back as a SwerveModulePosition object with latency compen...
Definition SwerveModule.hpp:398
DriveMotorT & GetDriveMotor()
Gets this module's Drive Motor reference.
Definition SwerveModule.hpp:476
DriveMotorT const & GetDriveMotor() const
Gets this module's Drive Motor reference.
Definition SwerveModule.hpp:488
SwerveModule(Constants const &constants, CANBus canbus, impl::SwerveModuleImpl &module)
Construct a SwerveModule with the specified constants.
Definition SwerveModule.hpp:88
SwerveModuleVelocity GetCurrentVelocity() const
Get the current velocity of the module.
Definition SwerveModule.hpp:423
virtual void ResetPosition()
Resets this module's drive motor position to 0 rotations.
Definition SwerveModule.hpp:443
static constexpr int kNumConfigAttempts
Number of times to attempt config applies.
Definition SwerveModule.hpp:70
Swerve Module class that encapsulates a swerve module powered by CTR Electronics devices.
Definition SwerveModuleImpl.hpp:61
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
constexpr const char * GetName() const
Gets the name of this StatusCode.
Definition StatusCodes.h:867
constexpr bool IsOK() const
Definition StatusCodes.h:860
Definition ExternalFeedbackConfigs.hpp:21
Definition ExternalFeedbackConfigs.hpp:17
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
Definition SwerveModule.hpp:28
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.
Definition SwerveModuleConstants.hpp:77
@ TalonFXS_Brushed_AB
Brushed motor connected to a Talon FXS on terminals A and B.
Definition SwerveModuleConstants.hpp:73
@ TalonFX_Integrated
Talon FX integrated brushless motor.
Definition SwerveModuleConstants.hpp:53
@ TalonFXS_Brushed_BC
Brushed motor connected to a Talon FXS on terminals B and C.
Definition SwerveModuleConstants.hpp:81
@ TalonFXS_NEO550_JST
Third party NEO550 brushless motor connected to a Talon FXS over JST.
Definition SwerveModuleConstants.hpp:69
@ TalonFXS_NEO_JST
Third party NEO brushless motor connected to a Talon FXS over JST.
Definition SwerveModuleConstants.hpp:61
@ TalonFXS_VORTEX_JST
Third party VORTEX brushless motor connected to a Talon FXS over JST.
Definition SwerveModuleConstants.hpp:65
@ TalonFXS_Minion_JST
CTR Electronics Minion® brushless motor connected to a Talon FXS over JST.
Definition SwerveModuleConstants.hpp:57
@ FusedCANcoder
Requires Pro; Use signals::FeedbackSensorSourceValue::FusedCANcoder for the steer motor.
Definition SwerveModuleConstants.hpp:92
@ SyncCANdiPWM2
Requires Pro; Use signals::FeedbackSensorSourceValue::SyncCANdiPWM2 for the steer motor.
Definition SwerveModuleConstants.hpp:122
@ SyncCANdiPWM1
Requires Pro; Use signals::FeedbackSensorSourceValue::SyncCANdiPWM1 for the steer motor.
Definition SwerveModuleConstants.hpp:117
@ RemoteCANdiPWM2
Use signals::FeedbackSensorSourceValue::RemoteCANdiPWM2 for the steer motor.
Definition SwerveModuleConstants.hpp:132
@ FusedCANdiPWM2
Requires Pro; Use signals::FeedbackSensorSourceValue::FusedCANdiPWM2 for the steer motor.
Definition SwerveModuleConstants.hpp:112
@ FusedCANdiPWM1
Requires Pro; Use signals::FeedbackSensorSourceValue::FusedCANdiPWM1 for the steer motor.
Definition SwerveModuleConstants.hpp:107
@ RemoteCANdiPWM1
Use signals::FeedbackSensorSourceValue::RemoteCANdiPWM1 for the steer motor.
Definition SwerveModuleConstants.hpp:127
@ SyncCANcoder
Requires Pro; Use signals::FeedbackSensorSourceValue::SyncCANcoder for the steer motor.
Definition SwerveModuleConstants.hpp:97
@ TalonFXS_PulseWidth
Use signals::ExternalFeedbackSensorSourceValue::PulseWidth for the steer motor.
Definition SwerveModuleConstants.hpp:137
@ RemoteCANcoder
Use signals::FeedbackSensorSourceValue::RemoteCANcoder for the steer motor.
Definition SwerveModuleConstants.hpp:102
@ TalonFX_Integrated
Talon FX integrated brushless motor.
Definition SwerveModuleConstants.hpp:35
@ TalonFXS_NEO_JST
Third party NEO brushless motor connected to a Talon FXS over JST.
Definition SwerveModuleConstants.hpp:39
@ TalonFXS_VORTEX_JST
Third party VORTEX brushless motor connected to a Talon FXS over JST.
Definition SwerveModuleConstants.hpp:43
Definition ExternalFeedbackConfigs.hpp:16
Definition motor_constants.h:14
static constexpr int Leads_A_and_B
Third party brushed DC motor with two leads.
Definition SpnEnums.hpp:3535
static constexpr int Leads_B_and_C
Third party brushed DC motor with two leads.
Definition SpnEnums.hpp:3559
static constexpr int Leads_A_and_C
Third party brushed DC motor with two leads.
Definition SpnEnums.hpp:3547
static constexpr int SyncCANcoder
Requires Phoenix Pro; Talon will synchronize its commutation sensor position against another CANcoder...
Definition SpnEnums.hpp:3176
static constexpr int FusedCANdiPWM2
Requires Phoenix Pro; Talon will fuse a pulse-width encoder remotely attached to the Sensor Input 2 (...
Definition SpnEnums.hpp:3225
static constexpr int SyncCANdiPWM1
Requires Phoenix Pro; Talon will synchronize its internal rotor position against the pulse-width enco...
Definition SpnEnums.hpp:3244
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:3194
static constexpr int SyncCANdiPWM2
Requires Phoenix Pro; Talon will synchronize its internal rotor position against the pulse-width enco...
Definition SpnEnums.hpp:3256
static constexpr int RemoteCANcoder
Use another CANcoder on the same CAN bus (this also requires setting FeedbackRemoteSensorID).
Definition SpnEnums.hpp:3135
static constexpr int FusedCANdiPWM1
Requires Phoenix Pro; Talon will fuse a pulse-width encoder remotely attached to the Sensor Input 1 (...
Definition SpnEnums.hpp:3217
static constexpr int FusedCANcoder
Requires Phoenix Pro; Talon will fuse another CANcoder's information with the commutation sensor,...
Definition SpnEnums.hpp:3164
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:3202
static constexpr int PulseWidth
Use a pulse-width encoder directly attached to the Talon data port.
Definition SpnEnums.hpp:3186
static constexpr int RemoteCANcoder
Use another CANcoder on the same CAN bus (this also requires setting FeedbackRemoteSensorID).
Definition SpnEnums.hpp:1592
static constexpr int SyncCANdiPWM2
Requires Phoenix Pro; Talon will synchronize its internal rotor position against the pulse-width enco...
Definition SpnEnums.hpp:1704
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:1649
static constexpr int SyncCANdiPWM1
Requires Phoenix Pro; Talon will synchronize its internal rotor position against the pulse-width enco...
Definition SpnEnums.hpp:1692
static constexpr int SyncCANcoder
Requires Phoenix Pro; Talon will synchronize its internal rotor position against another CANcoder,...
Definition SpnEnums.hpp:1633
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:1641
static constexpr int FusedCANdiPWM1
Requires Phoenix Pro; Talon will fuse a pulse-width encoder remotely attached to the Sensor Input 1 (...
Definition SpnEnums.hpp:1665
static constexpr int FusedCANcoder
Requires Phoenix Pro; Talon will fuse another CANcoder's information with the internal rotor,...
Definition SpnEnums.hpp:1621
static constexpr int FusedCANdiPWM2
Requires Phoenix Pro; Talon will fuse a pulse-width encoder remotely attached to the Sensor Input 2 (...
Definition SpnEnums.hpp:1673
static constexpr int CounterClockwise_Positive
Positive motor output results in counter-clockwise motion.
Definition SpnEnums.hpp:1455
static constexpr int Clockwise_Positive
Positive motor output results in clockwise motion.
Definition SpnEnums.hpp:1459
static constexpr int NEO_JST
Third party NEO brushless three phase motor (~6000 RPM at 12V).
Definition SpnEnums.hpp:2754
static constexpr int NEO550_JST
Third party NEO550 brushless three phase motor (~11000 RPM at 12V).
Definition SpnEnums.hpp:2766
static constexpr int Brushed_DC
Third party brushed DC motor with two leads.
Definition SpnEnums.hpp:2742
static constexpr int Minion_JST
CTR Electronics Minion® brushless three phase motor.
Definition SpnEnums.hpp:2730
static constexpr int VORTEX_JST
Third party VORTEX brushless three phase motor.
Definition SpnEnums.hpp:2778
static constexpr int Brake
Definition SpnEnums.hpp:1504
static constexpr int CounterClockwise_Positive
Counter-clockwise motion reports positive rotation.
Definition SpnEnums.hpp:190
static constexpr int Clockwise_Positive
Clockwise motion reports positive rotation.
Definition SpnEnums.hpp:194
static constexpr int Aligned
The sensor direction is normally aligned with the motor.
Definition SpnEnums.hpp:3328
static constexpr int Opposed
The sensor direction is normally opposed to the motor.
Definition SpnEnums.hpp:3332
All constants for a swerve module.
Definition SwerveModuleConstants.hpp:152
bool DriveMotorInverted
True if the drive motor is inverted.
Definition SwerveModuleConstants.hpp:184
wpi::units::scalar_t SteerMotorGearRatio
Gear ratio between the steer motor and the azimuth encoder.
Definition SwerveModuleConstants.hpp:205
SteerMotorArrangement SteerMotorType
Choose the motor used for the steer motor.
Definition SwerveModuleConstants.hpp:270
DriveMotorConfigsT DriveMotorInitialConfigs
The initial configs used to configure the drive motor of the swerve module.
Definition SwerveModuleConstants.hpp:306
configs::Slot0Configs DriveMotorGains
The drive motor closed-loop gains.
Definition SwerveModuleConstants.hpp:235
wpi::units::ampere_t SlipCurrent
The maximum amount of stator current the drive motors can apply without slippage.
Definition SwerveModuleConstants.hpp:248
configs::Slot0Configs SteerMotorGains
The steer motor closed-loop gains.
Definition SwerveModuleConstants.hpp:226
SteerFeedbackType FeedbackSource
Choose how the feedback sensors should be configured.
Definition SwerveModuleConstants.hpp:283
int EncoderId
CAN ID of the absolute encoder used for azimuth.
Definition SwerveModuleConstants.hpp:166
DriveMotorArrangement DriveMotorType
Choose the motor used for the drive motor.
Definition SwerveModuleConstants.hpp:263
bool EncoderInverted
True if the azimuth encoder is inverted from the azimuth.
Definition SwerveModuleConstants.hpp:196
SteerMotorConfigsT SteerMotorInitialConfigs
The initial configs used to configure the steer motor of the swerve module.
Definition SwerveModuleConstants.hpp:330
EncoderConfigsT EncoderInitialConfigs
The initial configs used to configure the azimuth encoder of the swerve module.
Definition SwerveModuleConstants.hpp:346
wpi::units::turn_t EncoderOffset
Offset of the azimuth encoder.
Definition SwerveModuleConstants.hpp:170
bool SteerMotorInverted
True if the steer motor is inverted from the azimuth.
Definition SwerveModuleConstants.hpp:190
Contains everything the swerve module needs to apply a request.
Definition SwerveModuleImpl.hpp:66