13#include <wpi/units/force.hpp>
14#include <wpi/units/torque.hpp>
130 this->Velocity = std::move(newVelocity);
148 this->WheelForceFeedforwardX = newWheelForceFeedforwardX;
165 this->WheelForceFeedforwardY = newWheelForceFeedforwardY;
179 this->DriveRequest = newDriveRequest;
192 this->SteerRequest = newSteerRequest;
207 this->UpdatePeriod = newUpdatePeriod;
232 this->EnableFOC = newEnableFOC;
238 std::unique_ptr<hardware::traits::CommonTalon> _driveMotor;
239 std::unique_ptr<hardware::traits::CommonTalon> _steerMotor;
252 struct ModuleSupplem;
253 mutable std::unique_ptr<ModuleSupplem> _moduleSupplem;
258 using turns_per_meter = wpi::units::compound_unit<wpi::units::turns, wpi::units::inverse<wpi::units::meters>>;
259 using turns_per_meter_t = wpi::units::unit_t<turns_per_meter>;
261 turns_per_meter_t kDriveRotationsPerMeter;
262 wpi::units::meter_t kDriveNmPerWheelN;
263 wpi::units::scalar_t kCouplingRatioDriveRotorToEncoder;
264 wpi::units::meters_per_second_t kSpeedAt12Volts;
266 SwerveModulePosition _currentPosition;
267 SwerveModuleVelocity _targetVelocity;
277 std::derived_from<configs::ParentConfiguration> DriveMotorConfigsT,
278 std::derived_from<configs::ParentConfiguration> SteerMotorConfigsT,
279 std::derived_from<configs::ParentConfiguration> EncoderConfigsT
304 std::derived_from<controls::ControlRequest> DriveReq,
305 std::derived_from<controls::ControlRequest> SteerReq
307 void Apply(DriveReq &&driveRequest, SteerReq &&steerRequest)
309 if (_driveMotorFOC) {
310 _driveMotorFOC->SetControl(driveRequest.WithUpdateFreqHz(0_Hz));
312 _driveMotor->SetControl(driveRequest.WithUpdateFreqHz(0_Hz));
315 if (_steerMotorFOC) {
316 _steerMotorFOC->SetControl(steerRequest.WithUpdateFreqHz(0_Hz));
318 _steerMotor->SetControl(steerRequest.WithUpdateFreqHz(0_Hz));
361 return SwerveModuleVelocity{_driveVelocity.GetValue() / kDriveRotationsPerMeter, {_steerPosition.GetValue()}};
379 _driveMotor->SetPosition(0_tr);
389 return kDriveClosedLoopOutput;
399 return kSteerClosedLoopOutput;
407 struct MotorTorqueFeedforwards {
408 wpi::units::newton_meter_t torque;
409 wpi::units::ampere_t torqueCurrent;
410 wpi::units::volt_t voltage;
413 wpi::units::turns_per_second_t ApplyVelocityCorrections(wpi::units::turns_per_second_t velocity, wpi::units::turn_t targetAngle)
const;
414 MotorTorqueFeedforwards CalculateMotorTorqueFeedforwards(
415 wpi::units::newton_t wheelForceFeedforwardX,
416 wpi::units::newton_t wheelForceFeedforwardY
421 std::array<BaseStatusSignal *, 4> GetSignals()
423 return std::array<BaseStatusSignal *, 4>{&_drivePosition, &_driveVelocity, &_steerPosition, &_steerVelocity};
427 return _encoderPosition;
Class for getting information about an available CAN bus.
Definition CANBus.hpp:19
Represents a status signal with data of type T, and operations available to retrieve information abou...
Definition StatusSignal.hpp:563
Contains everything common between Talon motor controllers that support FOC (requires Phoenix Pro).
Definition CommonTalonWithFOC.hpp:28
ctre::phoenix::StatusCode ConfigNeutralMode(signals::NeutralModeValue neutralMode, wpi::units::second_t timeoutSeconds)
Configures the neutral mode to use for the module's drive motor.
SwerveModuleImpl(SwerveModuleConstants< DriveMotorConfigsT, SteerMotorConfigsT, EncoderConfigsT > const &constants, CANBus canbus)
Construct a SwerveModuleImpl with the specified constants.
ClosedLoopOutputType GetSteerClosedLoopOutputType() const
Gets the closed-loop output type to use for the steer motor.
Definition SwerveModuleImpl.hpp:397
friend class SwerveDrivetrainImpl
Definition SwerveModuleImpl.hpp:419
SwerveModuleVelocity GetTargetVelocity() const
Get the target velocity of the module.
Definition SwerveModuleImpl.hpp:371
void Apply(ModuleRequest const &moduleRequest)
Applies the desired ModuleRequest to this module.
SwerveModuleVelocity GetCurrentVelocity() const
Get the current velocity of the module.
Definition SwerveModuleImpl.hpp:359
void Apply(DriveReq &&driveRequest, SteerReq &&steerRequest)
Controls this module using the specified drive and steer control requests.
Definition SwerveModuleImpl.hpp:307
ClosedLoopOutputType GetDriveClosedLoopOutputType() const
Gets the closed-loop output type to use for the drive motor.
Definition SwerveModuleImpl.hpp:387
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:376
SwerveModulePosition GetCachedPosition() const
Gets the last cached swerve module position.
Definition SwerveModuleImpl.hpp:349
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:28
Definition SwerveDrivetrainImpl.hpp:21
SteerRequestType
All possible control requests for the module steer motor.
Definition SwerveModuleImpl.hpp:25
@ MotionMagicExpo
Control the drive motor using a Motion Magic® Expo request.
Definition SwerveModuleImpl.hpp:30
@ Position
Control the drive motor using an unprofiled position request.
Definition SwerveModuleImpl.hpp:35
DriveRequestType
All possible control requests for the module drive motor.
Definition SwerveModuleImpl.hpp:41
@ Velocity
Control the drive motor using a velocity closed-loop request.
Definition SwerveModuleImpl.hpp:50
@ OpenLoopVoltage
Control the drive motor using an open-loop voltage request.
Definition SwerveModuleImpl.hpp:45
Definition SwerveModule.hpp:28
ClosedLoopOutputType
Supported closed-loop output types.
Definition SwerveModuleConstants.hpp:22
Definition ExternalFeedbackConfigs.hpp:16
Definition motor_constants.h:14
The state of the motor controller bridge when output is neutral or disabled.
Definition SpnEnums.hpp:1603
All constants for a swerve module.
Definition SwerveModuleConstants.hpp:148
Contains everything the swerve module needs to apply a request.
Definition SwerveModuleImpl.hpp:66
ModuleRequest & WithSteerRequest(SteerRequestType newSteerRequest)
Modifies the SteerRequest parameter and returns itself.
Definition SwerveModuleImpl.hpp:190
DriveRequestType DriveRequest
The type of control request to use for the drive motor.
Definition SwerveModuleImpl.hpp:92
wpi::units::newton_t WheelForceFeedforwardX
Robot-centric wheel force feedforward to apply in the X direction.
Definition SwerveModuleImpl.hpp:79
ModuleRequest & WithEnableFOC(bool newEnableFOC)
Modifies the EnableFOC parameter and returns itself.
Definition SwerveModuleImpl.hpp:230
ModuleRequest & WithWheelForceFeedforwardX(wpi::units::newton_t newWheelForceFeedforwardX)
Modifies the WheelForceFeedforwardX parameter and returns itself.
Definition SwerveModuleImpl.hpp:146
ModuleRequest & WithVelocity(SwerveModuleVelocity newVelocity)
Modifies the Velocity parameter and returns itself.
Definition SwerveModuleImpl.hpp:128
SwerveModuleVelocity Velocity
Unoptimized velocity the module should target.
Definition SwerveModuleImpl.hpp:70
ModuleRequest & WithWheelForceFeedforwardY(wpi::units::newton_t newWheelForceFeedforwardY)
Modifies the WheelForceFeedforwardY parameter and returns itself.
Definition SwerveModuleImpl.hpp:163
SteerRequestType SteerRequest
The type of control request to use for the steer motor.
Definition SwerveModuleImpl.hpp:96
ModuleRequest & WithDriveRequest(DriveRequestType newDriveRequest)
Modifies the DriveRequest parameter and returns itself.
Definition SwerveModuleImpl.hpp:177
bool EnableFOC
When using Voltage-based control, set to true (default) to use FOC commutation (requires Phoenix Pro)...
Definition SwerveModuleImpl.hpp:118
ModuleRequest & WithUpdatePeriod(wpi::units::second_t newUpdatePeriod)
Modifies the UpdatePeriod parameter and returns itself.
Definition SwerveModuleImpl.hpp:205
wpi::units::second_t UpdatePeriod
The update period of the module request.
Definition SwerveModuleImpl.hpp:102
wpi::units::newton_t WheelForceFeedforwardY
Robot-centric wheel force feedforward to apply in the Y direction.
Definition SwerveModuleImpl.hpp:87