Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 1 | #ifndef AOS_INPUT_ACTION_JOYSTICK_INPUT_H_ |
| 2 | #define AOS_INPUT_ACTION_JOYSTICK_INPUT_H_ |
| 3 | |
| 4 | #include "aos/input/driver_station_data.h" |
| 5 | #include "aos/input/drivetrain_input.h" |
| 6 | #include "aos/input/joystick_input.h" |
| 7 | #include "frc971/autonomous/auto.q.h" |
| 8 | #include "frc971/autonomous/base_autonomous_actor.h" |
| 9 | |
| 10 | namespace aos { |
| 11 | namespace input { |
| 12 | |
| 13 | // Class to abstract out managing actions, autonomous mode, and drivetrains. |
| 14 | // Turns out we do the same thing every year, so let's stop copying it. |
| 15 | class ActionJoystickInput : public ::aos::input::JoystickInput { |
| 16 | public: |
| 17 | ActionJoystickInput( |
| 18 | ::aos::EventLoop *event_loop, |
| 19 | const ::frc971::control_loops::drivetrain::DrivetrainConfig<double> |
| 20 | &dt_config) |
| 21 | : ::aos::input::JoystickInput(event_loop), |
| 22 | drivetrain_input_reader_(DrivetrainInputReader::Make( |
| 23 | DrivetrainInputReader::InputType::kPistol, dt_config)) {} |
| 24 | |
| 25 | virtual ~ActionJoystickInput() {} |
| 26 | |
Austin Schuh | 30cc40a | 2019-03-12 21:02:13 -0700 | [diff] [blame^] | 27 | protected: |
| 28 | void set_run_teleop_in_auto(bool run_teleop_in_auto) { |
| 29 | run_teleop_in_auto_ = run_teleop_in_auto; |
| 30 | } |
| 31 | |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 32 | private: |
| 33 | // Handles any year specific superstructure code. |
| 34 | virtual void HandleTeleop(const ::aos::input::driver_station::Data &data) = 0; |
| 35 | |
| 36 | void RunIteration(const ::aos::input::driver_station::Data &data) override; |
| 37 | |
| 38 | void StartAuto(); |
| 39 | void StopAuto(); |
| 40 | |
| 41 | // True if the internal state machine thinks auto is running right now. |
| 42 | bool auto_running_ = false; |
| 43 | // True if an action was running last cycle. |
| 44 | bool was_running_ = false; |
| 45 | |
Austin Schuh | 30cc40a | 2019-03-12 21:02:13 -0700 | [diff] [blame^] | 46 | // If true, we will run teleop during auto mode after auto mode ends. This is |
| 47 | // to support the 2019 sandstorm mode. Auto will run, and then when the |
| 48 | // action ends (either when it's done, or when the driver triggers it to |
| 49 | // finish early), we will run teleop regardless of the mode. |
| 50 | bool run_teleop_in_auto_ = false; |
| 51 | |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 52 | ::std::unique_ptr<DrivetrainInputReader> drivetrain_input_reader_; |
| 53 | ::aos::common::actions::ActionQueue action_queue_; |
| 54 | }; |
| 55 | |
| 56 | } // namespace input |
| 57 | } // namespace aos |
| 58 | |
| 59 | #endif // AOS_INPUT_ACTION_JOYSTICK_INPUT_H_ |