Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 1 | #include "frc971/wpilib/drivetrain_writer.h" |
| 2 | |
| 3 | #include "aos/commonmath.h" |
| 4 | #include "aos/logging/logging.h" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 5 | #include "frc971/control_loops/drivetrain/drivetrain_output_generated.h" |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 6 | #include "frc971/wpilib/ahal/PWM.h" |
| 7 | #include "frc971/wpilib/loop_output_handler.h" |
| 8 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 9 | namespace frc971::wpilib { |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 10 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 11 | void DrivetrainWriter::Write( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 12 | const ::frc971::control_loops::drivetrain::Output &output) { |
| 13 | left_controller0_->SetSpeed( |
| 14 | SafeSpeed(reversed_left0_, output.left_voltage())); |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 15 | right_controller0_->SetSpeed( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 16 | SafeSpeed(reversed_right0_, output.right_voltage())); |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 17 | |
| 18 | if (left_controller1_) { |
| 19 | left_controller1_->SetSpeed( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 20 | SafeSpeed(reversed_left1_, output.left_voltage())); |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 21 | } |
| 22 | if (right_controller1_) { |
| 23 | right_controller1_->SetSpeed( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 24 | SafeSpeed(reversed_right1_, output.right_voltage())); |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 25 | } |
| 26 | } |
| 27 | |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 28 | void DrivetrainWriter::Stop() { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 29 | AOS_LOG(WARNING, "drivetrain output too old\n"); |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 30 | left_controller0_->SetDisabled(); |
| 31 | right_controller0_->SetDisabled(); |
| 32 | |
| 33 | if (left_controller1_) { |
| 34 | left_controller1_->SetDisabled(); |
| 35 | } |
| 36 | if (right_controller1_) { |
| 37 | right_controller1_->SetDisabled(); |
| 38 | } |
| 39 | } |
| 40 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 41 | } // namespace frc971::wpilib |