Maxwell Henderson | f8c9689 | 2023-06-28 19:55:59 -0700 | [diff] [blame] | 1 | #ifndef FRC971_WPILIB_SWERVE_SWERVE_MODULE_H_ |
| 2 | #define FRC971_WPILIB_SWERVE_SWERVE_MODULE_H_ |
| 3 | |
James Kuszmaul | d938d33 | 2024-05-15 20:47:19 -0700 | [diff] [blame] | 4 | #include "frc971/control_loops/swerve/swerve_drivetrain_output_generated.h" |
Maxwell Henderson | 10ed5c3 | 2024-01-09 12:40:54 -0800 | [diff] [blame] | 5 | #include "frc971/wpilib/talonfx.h" |
Maxwell Henderson | f8c9689 | 2023-06-28 19:55:59 -0700 | [diff] [blame] | 6 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 7 | namespace frc971::wpilib::swerve { |
Maxwell Henderson | f8c9689 | 2023-06-28 19:55:59 -0700 | [diff] [blame] | 8 | |
| 9 | struct SwerveModule { |
Maxwell Henderson | 10ed5c3 | 2024-01-09 12:40:54 -0800 | [diff] [blame] | 10 | SwerveModule(TalonFXParams rotation_params, TalonFXParams translation_params, |
Maxwell Henderson | acf6368 | 2023-08-19 22:18:09 -0700 | [diff] [blame] | 11 | std::string canbus, |
Maxwell Henderson | f8c9689 | 2023-06-28 19:55:59 -0700 | [diff] [blame] | 12 | std::vector<ctre::phoenix6::BaseStatusSignal *> *signals, |
| 13 | double stator_current_limit, double supply_current_limit) |
Maxwell Henderson | 10ed5c3 | 2024-01-09 12:40:54 -0800 | [diff] [blame] | 14 | : 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 Henderson | f8c9689 | 2023-06-28 19:55:59 -0700 | [diff] [blame] | 20 | |
| 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 Henderson | 10ed5c3 | 2024-01-09 12:40:54 -0800 | [diff] [blame] | 37 | std::shared_ptr<TalonFX> rotation; |
| 38 | std::shared_ptr<TalonFX> translation; |
Maxwell Henderson | f8c9689 | 2023-06-28 19:55:59 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 41 | } // namespace frc971::wpilib::swerve |
Maxwell Henderson | f8c9689 | 2023-06-28 19:55:59 -0700 | [diff] [blame] | 42 | #endif // FRC971_WPILIB_SWERVE_SWERVE_MODULE_H_ |