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