blob: c373a310c8e1745bed02ecd296c7ffb9bf80b0ef [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
Maxwell Henderson10ed5c32024-01-09 12:40:54 -08004#include "frc971/wpilib/talonfx.h"
Maxwell Hendersonf8c96892023-06-28 19:55:59 -07005
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -08006namespace frc971::wpilib::swerve {
Maxwell Hendersonf8c96892023-06-28 19:55:59 -07007
8struct SwerveModule {
Maxwell Henderson10ed5c32024-01-09 12:40:54 -08009 SwerveModule(TalonFXParams rotation_params, TalonFXParams translation_params,
Maxwell Hendersonacf63682023-08-19 22:18:09 -070010 std::string canbus,
Maxwell Hendersonf8c96892023-06-28 19:55:59 -070011 std::vector<ctre::phoenix6::BaseStatusSignal *> *signals,
12 double stator_current_limit, double supply_current_limit)
Maxwell Henderson10ed5c32024-01-09 12:40:54 -080013 : rotation(std::make_shared<TalonFX>(rotation_params, canbus, signals,
14 stator_current_limit,
15 supply_current_limit)),
16 translation(std::make_shared<TalonFX>(translation_params, canbus,
17 signals, stator_current_limit,
18 supply_current_limit)) {}
Maxwell Hendersonf8c96892023-06-28 19:55:59 -070019
20 void WriteModule(
21 const frc971::control_loops::drivetrain::swerve::SwerveModuleOutput
22 *module_output,
23 double max_voltage) {
24 double rotation_current = 0.0;
25 double translation_current = 0.0;
26
27 if (module_output != nullptr) {
28 rotation_current = module_output->rotation_current();
29 translation_current = module_output->translation_current();
30 }
31
32 rotation->WriteCurrent(rotation_current, max_voltage);
33 translation->WriteCurrent(translation_current, max_voltage);
34 }
35
Maxwell Henderson10ed5c32024-01-09 12:40:54 -080036 std::shared_ptr<TalonFX> rotation;
37 std::shared_ptr<TalonFX> translation;
Maxwell Hendersonf8c96892023-06-28 19:55:59 -070038};
39
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080040} // namespace frc971::wpilib::swerve
Maxwell Hendersonf8c96892023-06-28 19:55:59 -070041#endif // FRC971_WPILIB_SWERVE_SWERVE_MODULE_H_