CTRE Phoenix 6 C++ 25.3.0
Loading...
Searching...
No Matches
SwerveModule.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7#pragma once
8
14
15namespace ctre {
16namespace phoenix6 {
17namespace swerve {
18
21
22/**
23 * \brief Swerve Module class that encapsulates a swerve module powered by
24 * CTR Electronics devices.
25 *
26 * This class handles the hardware devices and configures them for
27 * swerve module operation using the Phoenix 6 API.
28 *
29 * This class constructs hardware devices internally, so the user
30 * only specifies the constants (IDs, PID gains, gear ratios, etc).
31 * Getters for these hardware devices are available.
32 */
33template <
34 typename DriveMotorT,
35 typename SteerMotorT,
36 typename EncoderT,
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>
43 >>
44>
46public:
47 /**
48 * \brief Contains everything the swerve module needs to apply a request.
49 */
51
52protected:
53 /** \brief Number of times to attempt config applies. */
54 static constexpr int kNumConfigAttempts = 2;
55
56 /** \brief The underlying swerve module instance. */
58
59private:
60 DriveMotorT _driveMotor;
61 SteerMotorT _steerMotor;
62 EncoderT _encoder;
63
64public:
65 /**
66 * \brief Construct a SwerveModule with the specified constants.
67 *
68 * \param constants Constants used to construct the module
69 * \param canbusName The name of the CAN bus this module is on
70 * \param module The impl#SwerveModuleImpl to use
71 */
74 std::string_view canbusName,
76 ) :
77 _module{&module},
78 _driveMotor{constants.DriveMotorId, std::string{canbusName}},
79 _steerMotor{constants.SteerMotorId, std::string{canbusName}},
80 _encoder{constants.EncoderId, std::string{canbusName}}
81 {
83
84 typename DriveMotorT::Configuration driveConfigs = constants.DriveMotorInitialConfigs;
85 driveConfigs.MotorOutput.NeutralMode = signals::NeutralModeValue::Brake;
86
87 driveConfigs.Slot0 = constants.DriveMotorGains;
88 if constexpr (!std::is_same_v<configs::TalonFXSConfiguration, decltype(driveConfigs)>) {
89 driveConfigs.TorqueCurrent.PeakForwardTorqueCurrent = constants.SlipCurrent;
90 driveConfigs.TorqueCurrent.PeakReverseTorqueCurrent = -constants.SlipCurrent;
91 }
92 driveConfigs.CurrentLimits.StatorCurrentLimit = constants.SlipCurrent;
93 driveConfigs.CurrentLimits.StatorCurrentLimitEnable = true;
94
95 if constexpr (std::is_same_v<configs::TalonFXSConfiguration, decltype(driveConfigs)>) {
96 switch (constants.DriveMotorType) {
98 printf(
99 "Cannot use TalonFX_Integrated drive motor type on Talon FXS ID %d. TalonFX_Integrated is only supported on Talon FX.",
100 GetDriveMotor().GetDeviceID()
101 );
102 break;
103
105 driveConfigs.Commutation.MotorArrangement = signals::MotorArrangementValue::NEO_JST;
106 break;
108 driveConfigs.Commutation.MotorArrangement = signals::MotorArrangementValue::VORTEX_JST;
109 break;
110 }
111 } else {
113 printf("Drive motor Talon FX ID %d only supports TalonFX_Integrated.", GetDriveMotor().GetDeviceID());
114 }
115 }
116
117 driveConfigs.MotorOutput.Inverted = constants.DriveMotorInverted ? signals::InvertedValue::Clockwise_Positive
119 for (int i = 0; i < kNumConfigAttempts; ++i) {
120 response = GetDriveMotor().GetConfigurator().Apply(driveConfigs);
121 if (response.IsOK()) break;
122 }
123 if (!response.IsOK()) {
124 printf("Talon ID %d failed config with error %s\n", GetDriveMotor().GetDeviceID(), response.GetName());
125 }
126
127 typename SteerMotorT::Configuration steerConfigs = constants.SteerMotorInitialConfigs;
128 steerConfigs.MotorOutput.NeutralMode = signals::NeutralModeValue::Brake;
129
130 steerConfigs.Slot0 = constants.SteerMotorGains;
131
132 if constexpr (std::is_same_v<configs::TalonFXSConfiguration, decltype(steerConfigs)>) {
133 switch (constants.SteerMotorType) {
135 printf(
136 "Cannot use TalonFX_Integrated steer motor type on Talon FXS ID %d. TalonFX_Integrated is only supported on Talon FX.",
137 GetSteerMotor().GetDeviceID()
138 );
139 break;
140
142 steerConfigs.Commutation.MotorArrangement = signals::MotorArrangementValue::Minion_JST;
143 break;
145 steerConfigs.Commutation.MotorArrangement = signals::MotorArrangementValue::NEO_JST;
146 break;
148 steerConfigs.Commutation.MotorArrangement = signals::MotorArrangementValue::VORTEX_JST;
149 break;
151 steerConfigs.Commutation.MotorArrangement = signals::MotorArrangementValue::NEO550_JST;
152 break;
154 steerConfigs.Commutation.MotorArrangement = signals::MotorArrangementValue::Brushed_DC;
155 steerConfigs.Commutation.BrushedMotorWiring = signals::BrushedMotorWiringValue::Leads_A_and_B;
156 break;
158 steerConfigs.Commutation.MotorArrangement = signals::MotorArrangementValue::Brushed_DC;
159 steerConfigs.Commutation.BrushedMotorWiring = signals::BrushedMotorWiringValue::Leads_A_and_C;
160 break;
162 steerConfigs.Commutation.MotorArrangement = signals::MotorArrangementValue::Brushed_DC;
163 steerConfigs.Commutation.BrushedMotorWiring = signals::BrushedMotorWiringValue::Leads_B_and_C;
164 break;
165 }
166
167 /* Modify configuration to use remote encoder setting */
168 steerConfigs.ExternalFeedback.FeedbackRemoteSensorID = constants.EncoderId;
169 switch (constants.FeedbackSource) {
171 steerConfigs.ExternalFeedback.ExternalFeedbackSensorSource = signals::ExternalFeedbackSensorSourceValue::FusedCANcoder;
172 break;
174 steerConfigs.ExternalFeedback.ExternalFeedbackSensorSource = signals::ExternalFeedbackSensorSourceValue::SyncCANcoder;
175 break;
177 steerConfigs.ExternalFeedback.ExternalFeedbackSensorSource = signals::ExternalFeedbackSensorSourceValue::RemoteCANcoder;
178 break;
179
181 steerConfigs.ExternalFeedback.ExternalFeedbackSensorSource = signals::ExternalFeedbackSensorSourceValue::FusedCANdiPWM1;
182 break;
184 steerConfigs.ExternalFeedback.ExternalFeedbackSensorSource = signals::ExternalFeedbackSensorSourceValue::FusedCANdiPWM2;
185 break;
187 steerConfigs.ExternalFeedback.ExternalFeedbackSensorSource = signals::ExternalFeedbackSensorSourceValue::SyncCANdiPWM1;
188 break;
190 steerConfigs.ExternalFeedback.ExternalFeedbackSensorSource = signals::ExternalFeedbackSensorSourceValue::SyncCANdiPWM2;
191 break;
193 steerConfigs.ExternalFeedback.ExternalFeedbackSensorSource = signals::ExternalFeedbackSensorSourceValue::RemoteCANdiPWM1;
194 break;
196 steerConfigs.ExternalFeedback.ExternalFeedbackSensorSource = signals::ExternalFeedbackSensorSourceValue::RemoteCANdiPWM2;
197 break;
198
200 steerConfigs.ExternalFeedback.ExternalFeedbackSensorSource = signals::ExternalFeedbackSensorSourceValue::PulseWidth;
201 steerConfigs.ExternalFeedback.AbsoluteSensorOffset = constants.EncoderOffset;
202 steerConfigs.ExternalFeedback.SensorPhase = constants.EncoderInverted
205 break;
206 }
207 steerConfigs.ExternalFeedback.RotorToSensorRatio = constants.SteerMotorGearRatio;
208 } else {
210 printf("Steer motor Talon FX ID %d only supports TalonFX_Integrated.", GetSteerMotor().GetDeviceID());
211 }
212
213 /* Modify configuration to use remote encoder setting */
214 steerConfigs.Feedback.FeedbackRemoteSensorID = constants.EncoderId;
215 switch (constants.FeedbackSource) {
217 steerConfigs.Feedback.FeedbackSensorSource = signals::FeedbackSensorSourceValue::FusedCANcoder;
218 break;
220 steerConfigs.Feedback.FeedbackSensorSource = signals::FeedbackSensorSourceValue::SyncCANcoder;
221 break;
223 steerConfigs.Feedback.FeedbackSensorSource = signals::FeedbackSensorSourceValue::RemoteCANcoder;
224 break;
225
227 steerConfigs.Feedback.FeedbackSensorSource = signals::FeedbackSensorSourceValue::FusedCANdiPWM1;
228 break;
230 steerConfigs.Feedback.FeedbackSensorSource = signals::FeedbackSensorSourceValue::FusedCANdiPWM2;
231 break;
233 steerConfigs.Feedback.FeedbackSensorSource = signals::FeedbackSensorSourceValue::SyncCANdiPWM1;
234 break;
236 steerConfigs.Feedback.FeedbackSensorSource = signals::FeedbackSensorSourceValue::SyncCANdiPWM2;
237 break;
239 steerConfigs.Feedback.FeedbackSensorSource = signals::FeedbackSensorSourceValue::RemoteCANdiPWM1;
240 break;
242 steerConfigs.Feedback.FeedbackSensorSource = signals::FeedbackSensorSourceValue::RemoteCANdiPWM2;
243 break;
244
246 printf(
247 "Cannot use Pulse Width steer feedback type on Talon FX ID %d. Pulse Width is only supported on Talon FXS.\n",
248 GetSteerMotor().GetDeviceID()
249 );
250 break;
251 }
252 steerConfigs.Feedback.RotorToSensorRatio = constants.SteerMotorGearRatio;
253 }
254
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;
257
258 steerConfigs.ClosedLoopGeneral.ContinuousWrap = true; // Enable continuous wrap for swerve modules
259
260 steerConfigs.MotorOutput.Inverted = constants.SteerMotorInverted
263 for (int i = 0; i < kNumConfigAttempts; ++i) {
264 response = GetSteerMotor().GetConfigurator().Apply(steerConfigs);
265 if (response.IsOK()) break;
266 }
267 if (!response.IsOK()) {
268 printf("Talon ID %d failed config with error %s\n", GetSteerMotor().GetDeviceID(), response.GetName());
269 }
270
271 typename EncoderT::Configuration encoderConfigs = constants.EncoderInitialConfigs;
272 if constexpr (std::is_same_v<configs::CANcoderConfiguration, decltype(encoderConfigs)>) {
273 encoderConfigs.MagnetSensor.MagnetOffset = constants.EncoderOffset;
274 encoderConfigs.MagnetSensor.SensorDirection = constants.EncoderInverted
277
278 for (int i = 0; i < kNumConfigAttempts; ++i) {
279 response = GetEncoder().GetConfigurator().Apply(encoderConfigs);
280 if (response.IsOK()) break;
281 }
282 if (!response.IsOK()) {
283 printf("Encoder ID %d failed config with error %s\n", GetEncoder().GetDeviceID(), response.GetName());
284 }
285 } else if constexpr (std::is_same_v<configs::CANdiConfiguration, decltype(encoderConfigs)>) {
286 for (int i = 0; i < kNumConfigAttempts; ++i) {
287 response = GetEncoder().GetConfigurator().Apply(encoderConfigs.DigitalInputs);
288 if (response.IsOK()) break;
289 }
290 if (!response.IsOK()) {
291 printf("Encoder ID %d failed config with error %s\n", GetEncoder().GetDeviceID(), response.GetName());
292 }
293
294 for (int i = 0; i < kNumConfigAttempts; ++i) {
295 response = GetEncoder().GetConfigurator().Apply(encoderConfigs.CustomParams);
296 if (response.IsOK()) break;
297 }
298 if (!response.IsOK()) {
299 printf("Encoder ID %d failed config with error %s\n", GetEncoder().GetDeviceID(), response.GetName());
300 }
301
302 switch (constants.FeedbackSource) {
306 encoderConfigs.PWM1.AbsoluteSensorOffset = constants.EncoderOffset;
307 encoderConfigs.PWM1.SensorDirection = constants.EncoderInverted;
308
309 for (int i = 0; i < kNumConfigAttempts; ++i) {
310 response = GetEncoder().GetConfigurator().Apply(encoderConfigs.PWM1);
311 if (response.IsOK()) break;
312 }
313 if (!response.IsOK()) {
314 printf("Encoder ID %d failed config with error %s\n", GetEncoder().GetDeviceID(), response.GetName());
315 }
316 break;
317
321 encoderConfigs.PWM2.AbsoluteSensorOffset = constants.EncoderOffset;
322 encoderConfigs.PWM2.SensorDirection = constants.EncoderInverted;
323
324 for (int i = 0; i < kNumConfigAttempts; ++i) {
325 response = GetEncoder().GetConfigurator().Apply(encoderConfigs.PWM2);
326 if (response.IsOK()) break;
327 }
328 if (!response.IsOK()) {
329 printf("Encoder ID %d failed config with error %s\n", GetEncoder().GetDeviceID(), response.GetName());
330 }
331 break;
332
333 default:
334 break;
335 }
336 }
337 }
338
339 virtual ~SwerveModule() = default;
340
341 /**
342 * \brief Applies the desired ModuleRequest to this module.
343 *
344 * \param moduleRequest The request to apply to this module
345 */
346 virtual void Apply(ModuleRequest const &moduleRequest)
347 {
348 return _module->Apply(moduleRequest);
349 }
350
351 /**
352 * \brief Controls this module using the specified drive and steer control requests.
353 *
354 * This is intended only to be used for characterization of the robot; do not use this for normal use.
355 *
356 * \param driveRequest The control request to apply to the drive motor
357 * \param steerRequest The control request to apply to the steer motor
358 */
359 template <typename DriveReq, typename SteerReq>
360 void Apply(DriveReq &&driveRequest, SteerReq &&steerRequest)
361 {
362 return _module->Apply(std::forward<DriveReq>(driveRequest), std::forward<SteerReq>(steerRequest));
363 }
364
365 /**
366 * \brief Gets the state of this module and passes it back as a
367 * SwerveModulePosition object with latency compensated values.
368 *
369 * This function is blocking when it performs a refresh.
370 *
371 * \param refresh True if the signals should be refreshed
372 * \returns SwerveModulePosition containing this module's state.
373 */
374 SwerveModulePosition GetPosition(bool refresh)
375 {
376 return _module->GetPosition(refresh);
377 }
378
379 /**
380 * \brief Gets the last cached swerve module position.
381 * This differs from #GetPosition in that it will not
382 * perform any latency compensation or refresh the signals.
383 *
384 * \returns Last cached SwerveModulePosition
385 */
386 SwerveModulePosition GetCachedPosition() const
387 {
388 return _module->GetCachedPosition();
389 }
390
391 /**
392 * \brief Get the current state of the module.
393 *
394 * This is typically used for telemetry, as the SwerveModulePosition
395 * is used for odometry.
396 *
397 * \returns Current state of the module
398 */
399 SwerveModuleState GetCurrentState() const
400 {
401 return _module->GetCurrentState();
402 }
403
404 /**
405 * \brief Get the target state of the module.
406 *
407 * This is typically used for telemetry.
408 *
409 * \returns Target state of the module
410 */
411 SwerveModuleState GetTargetState() const
412 {
413 return _module->GetTargetState();
414 }
415
416 /**
417 * \brief Resets this module's drive motor position to 0 rotations.
418 */
419 virtual void ResetPosition()
420 {
421 return _module->ResetPosition();
422 }
423
424 /**
425 * \brief Gets the closed-loop output type to use for the drive motor.
426 *
427 * \returns Drive motor closed-loop output type
428 */
433
434 /**
435 * \brief Gets the closed-loop output type to use for the steer motor.
436 *
437 * \returns Steer motor closed-loop output type
438 */
443
444 /**
445 * \brief Gets this module's Drive Motor reference.
446 *
447 * This should be used only to access signals and change configurations that the
448 * swerve drivetrain does not configure itself.
449 *
450 * \returns This module's Drive Motor reference
451 */
452 DriveMotorT &GetDriveMotor()
453 {
454 return _driveMotor;
455 }
456
457 /**
458 * \brief Gets this module's Steer Motor reference.
459 *
460 * This should be used only to access signals and change configurations that the
461 * swerve drivetrain does not configure itself.
462 *
463 * \returns This module's Steer Motor reference
464 */
465 SteerMotorT &GetSteerMotor()
466 {
467 return _steerMotor;
468 }
469
470 /**
471 * \brief Gets this module's azimuth encoder reference.
472 *
473 * This should be used only to access signals and change configurations that the
474 * swerve drivetrain does not configure itself.
475 *
476 * \returns This module's azimuth encoder reference
477 */
478 EncoderT &GetEncoder()
479 {
480 return _encoder;
481 }
482};
483
484}
485}
486}
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
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
Definition span.hpp:401
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