Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame^] | 1 | #include "aos/input/action_joystick_input.h" |
| 2 | |
| 3 | #include "aos/input/driver_station_data.h" |
| 4 | #include "frc971/autonomous/auto.q.h" |
| 5 | #include "frc971/autonomous/base_autonomous_actor.h" |
| 6 | |
| 7 | using ::aos::input::driver_station::ControlBit; |
| 8 | |
| 9 | namespace aos { |
| 10 | namespace input { |
| 11 | |
| 12 | void ActionJoystickInput::RunIteration( |
| 13 | const ::aos::input::driver_station::Data &data) { |
| 14 | const bool last_auto_running = auto_running_; |
| 15 | auto_running_ = data.GetControlBit(ControlBit::kAutonomous) && |
| 16 | data.GetControlBit(ControlBit::kEnabled); |
| 17 | if (auto_running_ != last_auto_running) { |
| 18 | if (auto_running_) { |
| 19 | StartAuto(); |
| 20 | } else { |
| 21 | StopAuto(); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | if (!auto_running_) { |
| 26 | if (!data.GetControlBit(ControlBit::kEnabled)) { |
| 27 | action_queue_.CancelAllActions(); |
| 28 | LOG(DEBUG, "Canceling\n"); |
| 29 | } |
| 30 | drivetrain_input_reader_->HandleDrivetrain(data); |
| 31 | HandleTeleop(data); |
| 32 | } |
| 33 | |
| 34 | // Process pending actions. |
| 35 | action_queue_.Tick(); |
| 36 | was_running_ = action_queue_.Running(); |
| 37 | } |
| 38 | |
| 39 | void ActionJoystickInput::StartAuto() { |
| 40 | LOG(INFO, "Starting auto mode\n"); |
| 41 | action_queue_.EnqueueAction(::frc971::autonomous::MakeAutonomousAction(0)); |
| 42 | } |
| 43 | |
| 44 | void ActionJoystickInput::StopAuto() { |
| 45 | LOG(INFO, "Stopping auto mode\n"); |
| 46 | action_queue_.CancelAllActions(); |
| 47 | } |
| 48 | |
| 49 | } // namespace input |
| 50 | } // namespace aos |