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" |
| 5 | #include "aos/logging/queue_logging.h" |
| 6 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
| 7 | #include "frc971/wpilib/ahal/PWM.h" |
| 8 | #include "frc971/wpilib/loop_output_handler.h" |
| 9 | |
| 10 | namespace frc971 { |
| 11 | namespace wpilib { |
| 12 | |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame^] | 13 | void DrivetrainWriter::Write( |
| 14 | const ::frc971::control_loops::DrivetrainQueue::Output &output) { |
| 15 | LOG_STRUCT(DEBUG, "will output", output); |
| 16 | left_controller0_->SetSpeed(SafeSpeed(reversed_left0_, output.left_voltage)); |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 17 | right_controller0_->SetSpeed( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame^] | 18 | SafeSpeed(reversed_right0_, output.right_voltage)); |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 19 | |
| 20 | if (left_controller1_) { |
| 21 | left_controller1_->SetSpeed( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame^] | 22 | SafeSpeed(reversed_left1_, output.left_voltage)); |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 23 | } |
| 24 | if (right_controller1_) { |
| 25 | right_controller1_->SetSpeed( |
Austin Schuh | bd1fe9c | 2019-06-29 16:35:48 -0700 | [diff] [blame^] | 26 | SafeSpeed(reversed_right1_, output.right_voltage)); |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 27 | } |
| 28 | } |
| 29 | |
Sabina Davis | d004fd6 | 2019-02-02 23:51:46 -0800 | [diff] [blame] | 30 | void DrivetrainWriter::Stop() { |
| 31 | LOG(WARNING, "drivetrain output too old\n"); |
| 32 | left_controller0_->SetDisabled(); |
| 33 | right_controller0_->SetDisabled(); |
| 34 | |
| 35 | if (left_controller1_) { |
| 36 | left_controller1_->SetDisabled(); |
| 37 | } |
| 38 | if (right_controller1_) { |
| 39 | right_controller1_->SetDisabled(); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | } // namespace wpilib |
| 44 | } // namespace frc971 |