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: |
Austin Schuh | 59a62e7 | 2019-03-13 22:39:03 -0700 | [diff] [blame^] | 33 | // Handles anything that needs to be cleaned up when the auto action exits. |
| 34 | virtual void AutoEnded() {} |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 35 | // Handles any year specific superstructure code. |
| 36 | virtual void HandleTeleop(const ::aos::input::driver_station::Data &data) = 0; |
| 37 | |
| 38 | void RunIteration(const ::aos::input::driver_station::Data &data) override; |
| 39 | |
| 40 | void StartAuto(); |
| 41 | void StopAuto(); |
| 42 | |
| 43 | // True if the internal state machine thinks auto is running right now. |
| 44 | bool auto_running_ = false; |
| 45 | // True if an action was running last cycle. |
| 46 | bool was_running_ = false; |
| 47 | |
Austin Schuh | 30cc40a | 2019-03-12 21:02:13 -0700 | [diff] [blame] | 48 | // If true, we will run teleop during auto mode after auto mode ends. This is |
| 49 | // to support the 2019 sandstorm mode. Auto will run, and then when the |
| 50 | // action ends (either when it's done, or when the driver triggers it to |
| 51 | // finish early), we will run teleop regardless of the mode. |
| 52 | bool run_teleop_in_auto_ = false; |
| 53 | |
Austin Schuh | 59a62e7 | 2019-03-13 22:39:03 -0700 | [diff] [blame^] | 54 | // Bool to track if auto was running the last cycle through. This lets us |
| 55 | // call AutoEnded when the auto mode function stops. |
| 56 | bool auto_was_running_ = false; |
| 57 | |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 58 | ::std::unique_ptr<DrivetrainInputReader> drivetrain_input_reader_; |
| 59 | ::aos::common::actions::ActionQueue action_queue_; |
| 60 | }; |
| 61 | |
| 62 | } // namespace input |
| 63 | } // namespace aos |
| 64 | |
| 65 | #endif // AOS_INPUT_ACTION_JOYSTICK_INPUT_H_ |