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 | |
| 9 | namespace frc971 { |
| 10 | namespace wpilib { |
| 11 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame] | 12 | void DrivetrainWriter::Write( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 13 | const ::frc971::control_loops::drivetrain::Output &output) { |
| 14 | left_controller0_->SetSpeed( |
| 15 | SafeSpeed(reversed_left0_, output.left_voltage())); |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 16 | right_controller0_->SetSpeed( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 17 | SafeSpeed(reversed_right0_, output.right_voltage())); |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 18 | |
| 19 | if (left_controller1_) { |
| 20 | left_controller1_->SetSpeed( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 21 | SafeSpeed(reversed_left1_, output.left_voltage())); |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 22 | } |
| 23 | if (right_controller1_) { |
| 24 | right_controller1_->SetSpeed( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 25 | SafeSpeed(reversed_right1_, output.right_voltage())); |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 26 | } |
| 27 | } |
| 28 | |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 29 | void DrivetrainWriter::Stop() { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 30 | AOS_LOG(WARNING, "drivetrain output too old\n"); |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 31 | left_controller0_->SetDisabled(); |
| 32 | right_controller0_->SetDisabled(); |
| 33 | |
| 34 | if (left_controller1_) { |
| 35 | left_controller1_->SetDisabled(); |
| 36 | } |
| 37 | if (right_controller1_) { |
| 38 | right_controller1_->SetDisabled(); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | } // namespace wpilib |
| 43 | } // namespace frc971 |