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" |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 4 | #include "frc971/autonomous/auto_generated.h" |
Austin Schuh | ed5b26d | 2019-12-05 20:51:59 -0800 | [diff] [blame] | 5 | #include "frc971/autonomous/auto_mode_generated.h" |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 6 | #include "frc971/autonomous/base_autonomous_actor.h" |
| 7 | |
| 8 | using ::aos::input::driver_station::ControlBit; |
| 9 | |
| 10 | namespace aos { |
| 11 | namespace input { |
| 12 | |
| 13 | void ActionJoystickInput::RunIteration( |
| 14 | const ::aos::input::driver_station::Data &data) { |
| 15 | const bool last_auto_running = auto_running_; |
| 16 | auto_running_ = data.GetControlBit(ControlBit::kAutonomous) && |
| 17 | data.GetControlBit(ControlBit::kEnabled); |
| 18 | if (auto_running_ != last_auto_running) { |
| 19 | if (auto_running_) { |
Austin Schuh | 59a62e7 | 2019-03-13 22:39:03 -0700 | [diff] [blame] | 20 | auto_was_running_ = true; |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 21 | StartAuto(); |
| 22 | } else { |
| 23 | StopAuto(); |
| 24 | } |
| 25 | } |
| 26 | |
James Kuszmaul | ccc368b | 2019-04-11 20:00:07 -0700 | [diff] [blame] | 27 | if (!auto_running_ || |
| 28 | (input_config_.run_teleop_in_auto && !action_queue_.Running())) { |
Austin Schuh | 59a62e7 | 2019-03-13 22:39:03 -0700 | [diff] [blame] | 29 | if (auto_was_running_) { |
| 30 | AutoEnded(); |
| 31 | auto_was_running_ = false; |
| 32 | } |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 33 | if (!data.GetControlBit(ControlBit::kEnabled)) { |
| 34 | action_queue_.CancelAllActions(); |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 35 | } |
| 36 | drivetrain_input_reader_->HandleDrivetrain(data); |
| 37 | HandleTeleop(data); |
| 38 | } |
| 39 | |
James Kuszmaul | ccc368b | 2019-04-11 20:00:07 -0700 | [diff] [blame] | 40 | if (auto_action_running_ && |
| 41 | data.IsPressed(input_config_.cancel_auto_button)) { |
| 42 | StopAuto(); |
| 43 | } |
| 44 | |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 45 | // Process pending actions. |
| 46 | action_queue_.Tick(); |
| 47 | was_running_ = action_queue_.Running(); |
| 48 | } |
| 49 | |
| 50 | void ActionJoystickInput::StartAuto() { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 51 | AOS_LOG(INFO, "Starting auto mode\n"); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 52 | frc971::autonomous::AutonomousActionParamsT params; |
| 53 | params.mode = GetAutonomousMode(); |
| 54 | |
| 55 | action_queue_.EnqueueAction(autonomous_action_factory_.Make(params)); |
James Kuszmaul | ccc368b | 2019-04-11 20:00:07 -0700 | [diff] [blame] | 56 | auto_action_running_ = true; |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void ActionJoystickInput::StopAuto() { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 60 | AOS_LOG(INFO, "Stopping auto mode\n"); |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 61 | action_queue_.CancelAllActions(); |
James Kuszmaul | ccc368b | 2019-04-11 20:00:07 -0700 | [diff] [blame] | 62 | auto_action_running_ = false; |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 63 | AutoEnded(); |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | } // namespace input |
| 67 | } // namespace aos |