blob: 729ebab0da9ee8bf7c9f7439951783c2c1926440 [file] [log] [blame]
Maxwell Hendersonf8c96892023-06-28 19:55:59 -07001#ifndef FRC971_WPILIB_SWERVE_SWERVE_MODULE_H_
2#define FRC971_WPILIB_SWERVE_SWERVE_MODULE_H_
3
James Kuszmauld938d332024-05-15 20:47:19 -07004#include "frc971/control_loops/swerve/swerve_drivetrain_output_generated.h"
Maxwell Henderson10ed5c32024-01-09 12:40:54 -08005#include "frc971/wpilib/talonfx.h"
Maxwell Hendersonf8c96892023-06-28 19:55:59 -07006
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -08007namespace frc971::wpilib::swerve {
Maxwell Hendersonf8c96892023-06-28 19:55:59 -07008
9struct SwerveModule {
Maxwell Henderson10ed5c32024-01-09 12:40:54 -080010 SwerveModule(TalonFXParams rotation_params, TalonFXParams translation_params,
Maxwell Hendersonacf63682023-08-19 22:18:09 -070011 std::string canbus,
Maxwell Hendersonf8c96892023-06-28 19:55:59 -070012 std::vector<ctre::phoenix6::BaseStatusSignal *> *signals,
13 double stator_current_limit, double supply_current_limit)
Maxwell Henderson10ed5c32024-01-09 12:40:54 -080014 : rotation(std::make_shared<TalonFX>(rotation_params, canbus, signals,
15 stator_current_limit,
16 supply_current_limit)),
17 translation(std::make_shared<TalonFX>(translation_params, canbus,
18 signals, stator_current_limit,
19 supply_current_limit)) {}
Maxwell Hendersonf8c96892023-06-28 19:55:59 -070020
21 void WriteModule(
22 const frc971::control_loops::drivetrain::swerve::SwerveModuleOutput
23 *module_output,
24 double max_voltage) {
25 double rotation_current = 0.0;
26 double translation_current = 0.0;
27
28 if (module_output != nullptr) {
29 rotation_current = module_output->rotation_current();
30 translation_current = module_output->translation_current();
31 }
32
33 rotation->WriteCurrent(rotation_current, max_voltage);
34 translation->WriteCurrent(translation_current, max_voltage);
35 }
36
Maxwell Henderson10ed5c32024-01-09 12:40:54 -080037 std::shared_ptr<TalonFX> rotation;
38 std::shared_ptr<TalonFX> translation;
Maxwell Hendersonf8c96892023-06-28 19:55:59 -070039};
40
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080041} // namespace frc971::wpilib::swerve
Maxwell Hendersonf8c96892023-06-28 19:55:59 -070042#endif // FRC971_WPILIB_SWERVE_SWERVE_MODULE_H_