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 | |
| 6 | namespace frc971 { |
| 7 | namespace wpilib { |
| 8 | namespace swerve { |
| 9 | |
| 10 | struct SwerveModule { |
Maxwell Henderson | 10ed5c3 | 2024-01-09 12:40:54 -0800 | [diff] [blame] | 11 | SwerveModule(TalonFXParams rotation_params, TalonFXParams translation_params, |
Maxwell Henderson | acf6368 | 2023-08-19 22:18:09 -0700 | [diff] [blame] | 12 | std::string canbus, |
Maxwell Henderson | f8c9689 | 2023-06-28 19:55:59 -0700 | [diff] [blame] | 13 | std::vector<ctre::phoenix6::BaseStatusSignal *> *signals, |
| 14 | double stator_current_limit, double supply_current_limit) |
Maxwell Henderson | 10ed5c3 | 2024-01-09 12:40:54 -0800 | [diff] [blame] | 15 | : rotation(std::make_shared<TalonFX>(rotation_params, canbus, signals, |
| 16 | stator_current_limit, |
| 17 | supply_current_limit)), |
| 18 | translation(std::make_shared<TalonFX>(translation_params, canbus, |
| 19 | signals, stator_current_limit, |
| 20 | supply_current_limit)) {} |
Maxwell Henderson | f8c9689 | 2023-06-28 19:55:59 -0700 | [diff] [blame] | 21 | |
| 22 | void WriteModule( |
| 23 | const frc971::control_loops::drivetrain::swerve::SwerveModuleOutput |
| 24 | *module_output, |
| 25 | double max_voltage) { |
| 26 | double rotation_current = 0.0; |
| 27 | double translation_current = 0.0; |
| 28 | |
| 29 | if (module_output != nullptr) { |
| 30 | rotation_current = module_output->rotation_current(); |
| 31 | translation_current = module_output->translation_current(); |
| 32 | } |
| 33 | |
| 34 | rotation->WriteCurrent(rotation_current, max_voltage); |
| 35 | translation->WriteCurrent(translation_current, max_voltage); |
| 36 | } |
| 37 | |
Maxwell Henderson | 10ed5c3 | 2024-01-09 12:40:54 -0800 | [diff] [blame] | 38 | std::shared_ptr<TalonFX> rotation; |
| 39 | std::shared_ptr<TalonFX> translation; |
Maxwell Henderson | f8c9689 | 2023-06-28 19:55:59 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | } // namespace swerve |
| 43 | } // namespace wpilib |
| 44 | } // namespace frc971 |
| 45 | #endif // FRC971_WPILIB_SWERVE_SWERVE_MODULE_H_ |