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_) { |
Austin Schuh | 59a62e7 | 2019-03-13 22:39:03 -0700 | [diff] [blame] | 19 | auto_was_running_ = true; |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 20 | StartAuto(); |
| 21 | } else { |
| 22 | StopAuto(); |
| 23 | } |
| 24 | } |
| 25 | |
Austin Schuh | 30cc40a | 2019-03-12 21:02:13 -0700 | [diff] [blame] | 26 | if (!auto_running_ || (run_teleop_in_auto_ && !action_queue_.Running())) { |
Austin Schuh | 59a62e7 | 2019-03-13 22:39:03 -0700 | [diff] [blame] | 27 | if (auto_was_running_) { |
| 28 | AutoEnded(); |
| 29 | auto_was_running_ = false; |
| 30 | } |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 31 | if (!data.GetControlBit(ControlBit::kEnabled)) { |
| 32 | action_queue_.CancelAllActions(); |
| 33 | LOG(DEBUG, "Canceling\n"); |
| 34 | } |
| 35 | drivetrain_input_reader_->HandleDrivetrain(data); |
| 36 | HandleTeleop(data); |
| 37 | } |
| 38 | |
| 39 | // Process pending actions. |
| 40 | action_queue_.Tick(); |
| 41 | was_running_ = action_queue_.Running(); |
| 42 | } |
| 43 | |
| 44 | void ActionJoystickInput::StartAuto() { |
| 45 | LOG(INFO, "Starting auto mode\n"); |
Austin Schuh | a964406 | 2019-03-28 14:31:52 -0700 | [diff] [blame^] | 46 | action_queue_.EnqueueAction( |
| 47 | ::frc971::autonomous::MakeAutonomousAction(GetAutonomousMode())); |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void ActionJoystickInput::StopAuto() { |
| 51 | LOG(INFO, "Stopping auto mode\n"); |
| 52 | action_queue_.CancelAllActions(); |
| 53 | } |
| 54 | |
| 55 | } // namespace input |
| 56 | } // namespace aos |