37 typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>,
38 typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>,
39 typename = std::enable_if_t<std::disjunction_v<
40 std::is_same<hardware::CANcoder, EncoderT>,
41 std::is_same<hardware::CANdi, EncoderT>,
42 std::is_same<hardware::TalonFXS, EncoderT>
60 DriveMotorT _driveMotor;
61 SteerMotorT _steerMotor;
74 std::string_view canbusName,
78 _driveMotor{constants.DriveMotorId,
std::string{canbusName}},
79 _steerMotor{constants.SteerMotorId,
std::string{canbusName}},
80 _encoder{constants.EncoderId,
std::string{canbusName}}
89 driveConfigs.TorqueCurrent.PeakForwardTorqueCurrent = constants.
SlipCurrent;
90 driveConfigs.TorqueCurrent.PeakReverseTorqueCurrent = -constants.
SlipCurrent;
92 driveConfigs.CurrentLimits.StatorCurrentLimit = constants.
SlipCurrent;
93 driveConfigs.CurrentLimits.StatorCurrentLimitEnable =
true;
99 "Cannot use TalonFX_Integrated drive motor type on Talon FXS ID %d. TalonFX_Integrated is only supported on Talon FX.",
113 printf(
"Drive motor Talon FX ID %d only supports TalonFX_Integrated.",
GetDriveMotor().GetDeviceID());
120 response =
GetDriveMotor().GetConfigurator().Apply(driveConfigs);
121 if (response.IsOK())
break;
123 if (!response.IsOK()) {
124 printf(
"Talon ID %d failed config with error %s\n",
GetDriveMotor().GetDeviceID(), response.GetName());
136 "Cannot use TalonFX_Integrated steer motor type on Talon FXS ID %d. TalonFX_Integrated is only supported on Talon FX.",
168 steerConfigs.ExternalFeedback.FeedbackRemoteSensorID = constants.
EncoderId;
201 steerConfigs.ExternalFeedback.AbsoluteSensorOffset = constants.
EncoderOffset;
210 printf(
"Steer motor Talon FX ID %d only supports TalonFX_Integrated.",
GetSteerMotor().GetDeviceID());
214 steerConfigs.Feedback.FeedbackRemoteSensorID = constants.
EncoderId;
247 "Cannot use Pulse Width steer feedback type on Talon FX ID %d. Pulse Width is only supported on Talon FXS.\n",
255 steerConfigs.MotionMagic.MotionMagicExpo_kV = 0.12_V / 1_tps * constants.
SteerMotorGearRatio;
256 steerConfigs.MotionMagic.MotionMagicExpo_kA = 0.8_V / 1_tr_per_s_sq / constants.
SteerMotorGearRatio;
258 steerConfigs.ClosedLoopGeneral.ContinuousWrap =
true;
264 response =
GetSteerMotor().GetConfigurator().Apply(steerConfigs);
265 if (response.IsOK())
break;
267 if (!response.IsOK()) {
268 printf(
"Talon ID %d failed config with error %s\n",
GetSteerMotor().GetDeviceID(), response.GetName());
273 encoderConfigs.MagnetSensor.MagnetOffset = constants.
EncoderOffset;
274 encoderConfigs.MagnetSensor.SensorDirection = constants.
EncoderInverted
279 response =
GetEncoder().GetConfigurator().Apply(encoderConfigs);
280 if (response.IsOK())
break;
282 if (!response.IsOK()) {
283 printf(
"Encoder ID %d failed config with error %s\n",
GetEncoder().GetDeviceID(), response.GetName());
287 response =
GetEncoder().GetConfigurator().Apply(encoderConfigs.DigitalInputs);
288 if (response.IsOK())
break;
290 if (!response.IsOK()) {
291 printf(
"Encoder ID %d failed config with error %s\n",
GetEncoder().GetDeviceID(), response.GetName());
295 response =
GetEncoder().GetConfigurator().Apply(encoderConfigs.CustomParams);
296 if (response.IsOK())
break;
298 if (!response.IsOK()) {
299 printf(
"Encoder ID %d failed config with error %s\n",
GetEncoder().GetDeviceID(), response.GetName());
306 encoderConfigs.PWM1.AbsoluteSensorOffset = constants.
EncoderOffset;
310 response =
GetEncoder().GetConfigurator().Apply(encoderConfigs.PWM1);
311 if (response.IsOK())
break;
313 if (!response.IsOK()) {
314 printf(
"Encoder ID %d failed config with error %s\n",
GetEncoder().GetDeviceID(), response.GetName());
321 encoderConfigs.PWM2.AbsoluteSensorOffset = constants.
EncoderOffset;
325 response =
GetEncoder().GetConfigurator().Apply(encoderConfigs.PWM2);
326 if (response.IsOK())
break;
328 if (!response.IsOK()) {
329 printf(
"Encoder ID %d failed config with error %s\n",
GetEncoder().GetDeviceID(), response.GetName());
359 template <
typename DriveReq,
typename SteerReq>
360 void Apply(DriveReq &&driveRequest, SteerReq &&steerRequest)
362 return _module->
Apply(std::forward<DriveReq>(driveRequest), std::forward<SteerReq>(steerRequest));
Class for CANcoder, a CAN based magnetic encoder that provides absolute and relative position along w...
Definition CoreCANcoder.hpp:38
Class for CANdi, a CAN digital input device that detects when a digital signal is asserted or deasser...
Definition CoreCANdi.hpp:40
Class description for the Talon FXS motor controller.
Definition CoreTalonFXS.hpp:86
static constexpr int Leads_A_and_B
Third party brushed DC motor with two leads.
Definition SpnEnums.hpp:4916
static constexpr int Leads_B_and_C
Third party brushed DC motor with two leads.
Definition SpnEnums.hpp:4940
static constexpr int Leads_A_and_C
Third party brushed DC motor with two leads.
Definition SpnEnums.hpp:4928
static constexpr int SyncCANcoder
Requires Phoenix Pro; Talon will synchronize its commutation sensor position against another CANcoder...
Definition SpnEnums.hpp:4443
static constexpr int FusedCANdiPWM2
Requires Phoenix Pro; Talon will fuse a pulse-width encoder remotely attached to the Sensor Input 2 (...
Definition SpnEnums.hpp:4490
static constexpr int SyncCANdiPWM1
Requires Phoenix Pro; Talon will synchronize its internal rotor position against the pulse-width enco...
Definition SpnEnums.hpp:4509
static constexpr int RemoteCANdiPWM1
Use a pulse-width encoder remotely attached to the Sensor Input 1 (S1IN) on CANdi.
Definition SpnEnums.hpp:4460
static constexpr int SyncCANdiPWM2
Requires Phoenix Pro; Talon will synchronize its internal rotor position against the pulse-width enco...
Definition SpnEnums.hpp:4521
static constexpr int RemoteCANcoder
Use another CANcoder on the same CAN bus (this also requires setting FeedbackRemoteSensorID).
Definition SpnEnums.hpp:4402
static constexpr int FusedCANdiPWM1
Requires Phoenix Pro; Talon will fuse a pulse-width encoder remotely attached to the Sensor Input 1 (...
Definition SpnEnums.hpp:4482
static constexpr int FusedCANcoder
Requires Phoenix Pro; Talon will fuse another CANcoder's information with the commutation sensor,...
Definition SpnEnums.hpp:4431
static constexpr int RemoteCANdiPWM2
Use a pulse-width encoder remotely attached to the Sensor Input 2 (S2IN) on CANdi.
Definition SpnEnums.hpp:4467
static constexpr int PulseWidth
Use a pulse-width encoder directly attached to the Talon data port.
Definition SpnEnums.hpp:4453
static constexpr int RemoteCANcoder
Use another CANcoder on the same CAN bus (this also requires setting FeedbackRemoteSensorID).
Definition SpnEnums.hpp:2425
static constexpr int SyncCANdiPWM2
Requires Phoenix Pro; Talon will synchronize its internal rotor position against the pulse-width enco...
Definition SpnEnums.hpp:2534
static constexpr int RemoteCANdiPWM2
Use a pulse-width encoder remotely attached to the Sensor Input 2 (S2IN) on CANdi.
Definition SpnEnums.hpp:2480
static constexpr int SyncCANdiPWM1
Requires Phoenix Pro; Talon will synchronize its internal rotor position against the pulse-width enco...
Definition SpnEnums.hpp:2522
static constexpr int SyncCANcoder
Requires Phoenix Pro; Talon will synchronize its internal rotor position against another CANcoder,...
Definition SpnEnums.hpp:2466
static constexpr int RemoteCANdiPWM1
Use a pulse-width encoder remotely attached to the Sensor Input 1 (S1IN) on CANdi.
Definition SpnEnums.hpp:2473
static constexpr int FusedCANdiPWM1
Requires Phoenix Pro; Talon will fuse a pulse-width encoder remotely attached to the Sensor Input 1 (...
Definition SpnEnums.hpp:2495
static constexpr int FusedCANcoder
Requires Phoenix Pro; Talon will fuse another CANcoder's information with the internal rotor,...
Definition SpnEnums.hpp:2454
static constexpr int FusedCANdiPWM2
Requires Phoenix Pro; Talon will fuse a pulse-width encoder remotely attached to the Sensor Input 2 (...
Definition SpnEnums.hpp:2503
static constexpr int CounterClockwise_Positive
Positive motor output results in counter-clockwise motion.
Definition SpnEnums.hpp:2230
static constexpr int Clockwise_Positive
Positive motor output results in clockwise motion.
Definition SpnEnums.hpp:2234
static constexpr int NEO_JST
Third party NEO brushless three phase motor (~6000 RPM at 12V).
Definition SpnEnums.hpp:3894
static constexpr int NEO550_JST
Third party NEO550 brushless three phase motor (~11000 RPM at 12V).
Definition SpnEnums.hpp:3906
static constexpr int Brushed_DC
Third party brushed DC motor with two leads.
Definition SpnEnums.hpp:3882
static constexpr int Minion_JST
CTR Electronics Minion® brushless three phase motor.
Definition SpnEnums.hpp:3870
static constexpr int VORTEX_JST
Third party VORTEX brushless three phase motor.
Definition SpnEnums.hpp:3918
static constexpr int Brake
Definition SpnEnums.hpp:2308
static constexpr int CounterClockwise_Positive
Counter-clockwise motion reports positive rotation.
Definition SpnEnums.hpp:277
static constexpr int Clockwise_Positive
Clockwise motion reports positive rotation.
Definition SpnEnums.hpp:281
static constexpr int Aligned
The sensor direction is normally aligned with the motor.
Definition SpnEnums.hpp:4622
static constexpr int Opposed
The sensor direction is normally opposed to the motor.
Definition SpnEnums.hpp:4626
Swerve Module class that encapsulates a swerve module powered by CTR Electronics devices.
Definition SwerveModule.hpp:45
virtual void Apply(ModuleRequest const &moduleRequest)
Applies the desired ModuleRequest to this module.
Definition SwerveModule.hpp:346
virtual void ResetPosition()
Resets this module's drive motor position to 0 rotations.
Definition SwerveModule.hpp:419
SwerveModulePosition GetPosition(bool refresh)
Gets the state of this module and passes it back as a SwerveModulePosition object with latency compen...
Definition SwerveModule.hpp:374
SwerveModuleState GetTargetState() const
Get the target state of the module.
Definition SwerveModule.hpp:411
impl::SwerveModuleImpl * _module
The underlying swerve module instance.
Definition SwerveModule.hpp:57
SwerveModule(SwerveModuleConstants< typename DriveMotorT::Configuration, typename SteerMotorT::Configuration, typename EncoderT::Configuration > const &constants, std::string_view canbusName, impl::SwerveModuleImpl &module)
Construct a SwerveModule with the specified constants.
Definition SwerveModule.hpp:72
EncoderT & GetEncoder()
Gets this module's azimuth encoder reference.
Definition SwerveModule.hpp:478
ClosedLoopOutputType GetDriveClosedLoopOutputType() const
Gets the closed-loop output type to use for the drive motor.
Definition SwerveModule.hpp:429
void Apply(DriveReq &&driveRequest, SteerReq &&steerRequest)
Controls this module using the specified drive and steer control requests.
Definition SwerveModule.hpp:360
DriveMotorT & GetDriveMotor()
Gets this module's Drive Motor reference.
Definition SwerveModule.hpp:452
SwerveModulePosition GetCachedPosition() const
Gets the last cached swerve module position.
Definition SwerveModule.hpp:386
ClosedLoopOutputType GetSteerClosedLoopOutputType() const
Gets the closed-loop output type to use for the steer motor.
Definition SwerveModule.hpp:439
virtual ~SwerveModule()=default
static constexpr int kNumConfigAttempts
Number of times to attempt config applies.
Definition SwerveModule.hpp:54
SteerMotorT & GetSteerMotor()
Gets this module's Steer Motor reference.
Definition SwerveModule.hpp:465
SwerveModuleState GetCurrentState() const
Get the current state of the module.
Definition SwerveModule.hpp:399
Swerve Module class that encapsulates a swerve module powered by CTR Electronics devices.
Definition SwerveModuleImpl.hpp:60
SwerveModuleState GetCurrentState() const
Get the current state of the module.
Definition SwerveModuleImpl.hpp:352
ClosedLoopOutputType GetSteerClosedLoopOutputType() const
Gets the closed-loop output type to use for the steer motor.
Definition SwerveModuleImpl.hpp:390
SwerveModuleState GetTargetState() const
Get the target state of the module.
Definition SwerveModuleImpl.hpp:364
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:380
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:369
SwerveModulePosition GetCachedPosition() const
Gets the last cached swerve module position.
Definition SwerveModuleImpl.hpp:342
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
SteerRequestType
All possible control requests for the module steer motor.
Definition SwerveModuleImpl.hpp:24
DriveRequestType
All possible control requests for the module drive motor.
Definition SwerveModuleImpl.hpp:40
ClosedLoopOutputType
Supported closed-loop output types.
Definition SwerveModuleConstants.hpp:25
@ 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 MotionMagicExpoTorqueCurrentFOC.hpp:18
All constants for a swerve module.
Definition SwerveModuleConstants.hpp:154
DriveMotorArrangement DriveMotorType
Choose the motor used for the drive motor.
Definition SwerveModuleConstants.hpp:264
bool DriveMotorInverted
True if the drive motor is inverted.
Definition SwerveModuleConstants.hpp:186
configs::Slot0Configs SteerMotorGains
The steer motor closed-loop gains.
Definition SwerveModuleConstants.hpp:228
SteerFeedbackType FeedbackSource
Choose how the feedback sensors should be configured.
Definition SwerveModuleConstants.hpp:284
EncoderConfigsT EncoderInitialConfigs
The initial configs used to configure the azimuth encoder of the swerve module.
Definition SwerveModuleConstants.hpp:347
units::angle::turn_t EncoderOffset
Offset of the azimuth encoder.
Definition SwerveModuleConstants.hpp:172
SteerMotorConfigsT SteerMotorInitialConfigs
The initial configs used to configure the steer motor of the swerve module.
Definition SwerveModuleConstants.hpp:331
units::current::ampere_t SlipCurrent
The maximum amount of stator current the drive motors can apply without slippage.
Definition SwerveModuleConstants.hpp:250
DriveMotorConfigsT DriveMotorInitialConfigs
The initial configs used to configure the drive motor of the swerve module.
Definition SwerveModuleConstants.hpp:306
bool EncoderInverted
True if the azimuth encoder is inverted from the azimuth.
Definition SwerveModuleConstants.hpp:198
bool SteerMotorInverted
True if the steer motor is inverted from the azimuth.
Definition SwerveModuleConstants.hpp:192
int EncoderId
CAN ID of the absolute encoder used for azimuth.
Definition SwerveModuleConstants.hpp:168
units::dimensionless::scalar_t SteerMotorGearRatio
Gear ratio between the steer motor and the azimuth encoder.
Definition SwerveModuleConstants.hpp:207
SteerMotorArrangement SteerMotorType
Choose the motor used for the steer motor.
Definition SwerveModuleConstants.hpp:271
configs::Slot0Configs DriveMotorGains
The drive motor closed-loop gains.
Definition SwerveModuleConstants.hpp:237
Contains everything the swerve module needs to apply a request.
Definition SwerveModuleImpl.hpp:65