35 typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, DriveMotorT>>,
36 typename = std::enable_if_t<std::is_base_of_v<hardware::traits::CommonTalon, SteerMotorT>>,
37 typename = std::enable_if_t<std::is_base_of_v<hardware::ParentDevice, EncoderT>>
54 DriveMotorT _driveMotor;
55 SteerMotorT _steerMotor;
67 typename DriveMotorConfigsT,
68 typename SteerMotorConfigsT,
69 typename EncoderConfigsT,
70 typename = std::enable_if_t<std::is_base_of_v<configs::ParentConfiguration, DriveMotorConfigsT>>,
71 typename = std::enable_if_t<std::is_base_of_v<configs::ParentConfiguration, SteerMotorConfigsT>>,
72 typename = std::enable_if_t<std::is_base_of_v<configs::ParentConfiguration, EncoderConfigsT>>
76 std::string_view canbusName,
80 _driveMotor{constants.DriveMotorId,
std::string{canbusName}},
81 _steerMotor{constants.SteerMotorId,
std::string{canbusName}},
82 _encoder{constants.EncoderId,
std::string{canbusName}}
90 driveConfigs.TorqueCurrent.PeakForwardTorqueCurrent = constants.
SlipCurrent;
91 driveConfigs.TorqueCurrent.PeakReverseTorqueCurrent = -constants.
SlipCurrent;
92 driveConfigs.CurrentLimits.StatorCurrentLimit = constants.
SlipCurrent;
93 driveConfigs.CurrentLimits.StatorCurrentLimitEnable =
true;
98 response =
GetDriveMotor().GetConfigurator().Apply(driveConfigs);
99 if (response.IsOK())
break;
101 if (!response.IsOK()) {
102 printf(
"Talon ID %d failed config with error %s\n",
GetDriveMotor().GetDeviceID(), response.GetName());
110 steerConfigs.Feedback.FeedbackRemoteSensorID = constants.
EncoderId;
124 steerConfigs.MotionMagic.MotionMagicExpo_kV = 0.12_V / 1_tps * constants.
SteerMotorGearRatio;
125 steerConfigs.MotionMagic.MotionMagicExpo_kA = 0.8_V / 1_tr_per_s_sq / constants.
SteerMotorGearRatio;
127 steerConfigs.ClosedLoopGeneral.ContinuousWrap =
true;
133 response =
GetSteerMotor().GetConfigurator().Apply(steerConfigs);
134 if (response.IsOK())
break;
136 if (!response.IsOK()) {
137 printf(
"Talon ID %d failed config with error %s\n",
GetSteerMotor().GetDeviceID(), response.GetName());
146 response =
GetEncoder().GetConfigurator().Apply(encoderConfigs);
147 if (response.IsOK())
break;
149 if (!response.IsOK()) {
150 printf(
"Encoder ID %d failed config with error %s\n",
GetEncoder().GetDeviceID(), response.GetName());
174 template <
typename DriveReq,
typename SteerReq>
175 void Apply(DriveReq &&driveRequest, SteerReq &&steerRequest)
177 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
MagnetSensorConfigs MagnetSensor
Configs that affect the magnet sensor and how to interpret it.
Definition CoreCANcoder.hpp:65
units::angle::turn_t MagnetOffset
This offset is added to the reported position, allowing the application to trim the zero position.
Definition Configs.hpp:79
signals::SensorDirectionValue SensorDirection
Direction of the sensor to determine positive rotation, as seen facing the LED side of the CANcoder.
Definition Configs.hpp:67
static constexpr int RemoteCANcoder
Use another CANcoder on the same CAN bus (this also requires setting FeedbackRemoteSensorID).
Definition SpnEnums.hpp:2324
static constexpr int SyncCANcoder
Requires Phoenix Pro; Talon will synchronize its internal rotor position against another CANcoder,...
Definition SpnEnums.hpp:2365
static constexpr int FusedCANcoder
Requires Phoenix Pro; Talon will fuse another CANcoder's information with the internal rotor,...
Definition SpnEnums.hpp:2353
static constexpr int CounterClockwise_Positive
Positive motor output results in clockwise motion.
Definition SpnEnums.hpp:2129
static constexpr int Clockwise_Positive
Positive motor output results in counter-clockwise motion.
Definition SpnEnums.hpp:2133
static constexpr int Brake
Definition SpnEnums.hpp:2207
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
Swerve Module class that encapsulates a swerve module powered by CTR Electronics devices.
Definition SwerveModule.hpp:39
virtual void Apply(ModuleRequest const &moduleRequest)
Applies the desired ModuleRequest to this module.
Definition SwerveModule.hpp:161
virtual void ResetPosition()
Resets this module's drive motor position to 0 rotations.
Definition SwerveModule.hpp:234
SwerveModulePosition GetPosition(bool refresh)
Gets the state of this module and passes it back as a SwerveModulePosition object with latency compen...
Definition SwerveModule.hpp:189
SwerveModuleState GetTargetState() const
Get the target state of the module.
Definition SwerveModule.hpp:226
impl::SwerveModuleImpl * _module
The underlying swerve module instance.
Definition SwerveModule.hpp:51
SwerveModule(SwerveModuleConstants< DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT > const &constants, std::string_view canbusName, impl::SwerveModuleImpl &module)
Construct a SwerveModule with the specified constants.
Definition SwerveModule.hpp:74
EncoderT & GetEncoder()
Gets this module's azimuth encoder reference.
Definition SwerveModule.hpp:293
ClosedLoopOutputType GetDriveClosedLoopOutputType() const
Gets the closed-loop output type to use for the drive motor.
Definition SwerveModule.hpp:244
void Apply(DriveReq &&driveRequest, SteerReq &&steerRequest)
Controls this module using the specified drive and steer control requests.
Definition SwerveModule.hpp:175
DriveMotorT & GetDriveMotor()
Gets this module's Drive Motor reference.
Definition SwerveModule.hpp:267
SwerveModulePosition GetCachedPosition() const
Gets the last cached swerve module position.
Definition SwerveModule.hpp:201
ClosedLoopOutputType GetSteerClosedLoopOutputType() const
Gets the closed-loop output type to use for the steer motor.
Definition SwerveModule.hpp:254
virtual ~SwerveModule()=default
static constexpr int kNumConfigAttempts
Number of times to attempt config applies.
Definition SwerveModule.hpp:48
SteerMotorT & GetSteerMotor()
Gets this module's Steer Motor reference.
Definition SwerveModule.hpp:280
SwerveModuleState GetCurrentState() const
Get the current state of the module.
Definition SwerveModule.hpp:214
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:336
ClosedLoopOutputType GetSteerClosedLoopOutputType() const
Gets the closed-loop output type to use for the steer motor.
Definition SwerveModuleImpl.hpp:374
SwerveModuleState GetTargetState() const
Get the target state of the module.
Definition SwerveModuleImpl.hpp:348
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:364
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:353
SwerveModulePosition GetCachedPosition() const
Gets the last cached swerve module position.
Definition SwerveModuleImpl.hpp:326
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:23
@ FusedCANcoder
Requires Pro; Use signals::FeedbackSensorSourceValue::FusedCANcoder for the steer motor.
@ SyncCANcoder
Requires Pro; Use signals::FeedbackSensorSourceValue::SyncCANcoder for the steer motor.
@ RemoteCANcoder
Use signals::FeedbackSensorSourceValue::RemoteCANcoder for the steer motor.
Definition MotionMagicExpoTorqueCurrentFOC.hpp:18
All constants for a swerve module.
Definition SwerveModuleConstants.hpp:117
bool DriveMotorInverted
True if the drive motor is inverted.
Definition SwerveModuleConstants.hpp:149
configs::Slot0Configs SteerMotorGains
The steer motor closed-loop gains.
Definition SwerveModuleConstants.hpp:191
SteerFeedbackType FeedbackSource
Choose how the feedback sensors should be configured.
Definition SwerveModuleConstants.hpp:247
EncoderConfigsT EncoderInitialConfigs
The initial configs used to configure the azimuth encoder of the swerve module.
Definition SwerveModuleConstants.hpp:310
units::angle::turn_t EncoderOffset
Offset of the azimuth encoder.
Definition SwerveModuleConstants.hpp:135
SteerMotorConfigsT SteerMotorInitialConfigs
The initial configs used to configure the steer motor of the swerve module.
Definition SwerveModuleConstants.hpp:294
units::current::ampere_t SlipCurrent
The maximum amount of stator current the drive motors can apply without slippage.
Definition SwerveModuleConstants.hpp:213
DriveMotorConfigsT DriveMotorInitialConfigs
The initial configs used to configure the drive motor of the swerve module.
Definition SwerveModuleConstants.hpp:269
bool EncoderInverted
True if the azimuth encoder is inverted from the azimuth.
Definition SwerveModuleConstants.hpp:161
bool SteerMotorInverted
True if the steer motor is inverted from the azimuth.
Definition SwerveModuleConstants.hpp:155
int EncoderId
CAN ID of the absolute encoder used for azimuth.
Definition SwerveModuleConstants.hpp:131
units::dimensionless::scalar_t SteerMotorGearRatio
Gear ratio between the steer motor and the azimuth encoder.
Definition SwerveModuleConstants.hpp:170
configs::Slot0Configs DriveMotorGains
The drive motor closed-loop gains.
Definition SwerveModuleConstants.hpp:200
Contains everything the swerve module needs to apply a request.
Definition SwerveModuleImpl.hpp:65