Valkyrie 2026
Loading...
Searching...
No Matches
SwerveModule.h
1#pragma once
2
3#include <ctre/phoenix6/CANcoder.hpp>
4#include <frc/DutyCycleEncoder.h>
5#include <frc/Filesystem.h>
6#include <frc/geometry/Rotation2d.h>
7#include <frc/geometry/Translation2d.h>
8#include <frc/kinematics/SwerveModulePosition.h>
9#include <frc/kinematics/SwerveModuleState.h>
10#include <frc/simulation/DCMotorSim.h>
11#include <units/voltage.h>
12
13#include "valkyrie/Loggable.h"
14#include "valkyrie/controllers/BaseController.h"
15#include "valkyrie/drivetrain/swerve/Requests.h"
16
17namespace valor {
18namespace swerve {
19
20using meters_per_turn_t = units::unit_t<units::compound_unit<units::meters, units::inverse<units::turn>>>;
21
30class SwerveModule : public valor::Loggable {
31 public:
32 SwerveModule(std::unique_ptr<BaseController> azimuthMotor, std::unique_ptr<BaseController> driveMotor, units::meter_t wheelDiameter,
33 frc::sim::DCMotorSim driveSim, frc::sim::DCMotorSim azimuthSim);
34
35 frc::SwerveModuleState GetState() const;
36 frc::SwerveModulePosition GetPosition() const;
37
38 units::meters_per_second_t GetMaxSpeed() const;
39
40 void ApplyRequest(requests::ApplyState);
41
42 inline BaseController& GetDriveMotor() const { return *driveMotor; }
43
44 inline BaseController& GetAzimuthMotor() const { return *azimuthMotor; }
45
46 void Reset();
47
48 void LoggablePeriodic() override;
49
50 // Doesn't override anything, just for convention - called explicitly from
51 // Swerve
52 void SimulationPeriodic();
53
54 private:
55 std::unique_ptr<BaseController> azimuthMotor;
56 std::unique_ptr<BaseController> driveMotor;
57
58 meters_per_turn_t wheelConversion;
59
60 frc::sim::DCMotorSim driveSim;
61 frc::sim::DCMotorSim azimuthSim;
62};
63
64} // namespace swerve
65} // namespace valor
Abstract class that all Valor controllers's should implement.
Definition BaseController.h:58
Base helper for publishing and subscribing values to NetworkTables.
Definition Loggable.h:218
void LoggablePeriodic() override
Periodic callback for logging updates.
Request structure for commanding a single swerve module state.
Definition Requests.h:214