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: |
James Kuszmaul | ccc368b | 2019-04-11 20:00:07 -0700 | [diff] [blame] | 17 | // Configuration parameters that don't really belong in the DrivetrainConfig. |
| 18 | struct InputConfig { |
| 19 | // If true, we will run teleop during auto mode after auto mode ends. This |
| 20 | // is to support the 2019 sandstorm mode. Auto will run, and then when the |
| 21 | // action ends (either when it's done, or when the driver triggers it to |
| 22 | // finish early), we will run teleop regardless of the mode. |
| 23 | bool run_teleop_in_auto = false; |
| 24 | // A button, for use with the run_teleop_in_auto, that will cancel the auto |
| 25 | // mode, and if run_telop_in_auto is specified, resume teloperation. |
Austin Schuh | bfb0412 | 2019-05-22 21:16:51 -0700 | [diff] [blame^] | 26 | const driver_station::ButtonLocation cancel_auto_button = {-1, -1}; |
James Kuszmaul | ccc368b | 2019-04-11 20:00:07 -0700 | [diff] [blame] | 27 | }; |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 28 | ActionJoystickInput( |
| 29 | ::aos::EventLoop *event_loop, |
Austin Schuh | bfb0412 | 2019-05-22 21:16:51 -0700 | [diff] [blame^] | 30 | const ::frc971::control_loops::drivetrain::DrivetrainConfig<double> |
| 31 | &dt_config, |
| 32 | DrivetrainInputReader::InputType input_type, |
James Kuszmaul | ccc368b | 2019-04-11 20:00:07 -0700 | [diff] [blame] | 33 | const InputConfig &input_config) |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 34 | : ::aos::input::JoystickInput(event_loop), |
James Kuszmaul | ccc368b | 2019-04-11 20:00:07 -0700 | [diff] [blame] | 35 | input_config_(input_config), |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 36 | drivetrain_input_reader_(DrivetrainInputReader::Make( |
Austin Schuh | bfb0412 | 2019-05-22 21:16:51 -0700 | [diff] [blame^] | 37 | input_type, dt_config)) {} |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 38 | |
| 39 | virtual ~ActionJoystickInput() {} |
| 40 | |
Austin Schuh | bfb0412 | 2019-05-22 21:16:51 -0700 | [diff] [blame^] | 41 | protected: |
| 42 | bool was_running_action() { return was_running_; } |
| 43 | |
| 44 | bool ActionRunning() { return action_queue_.Running(); } |
| 45 | void CancelAllActions() { action_queue_.CancelAllActions(); } |
| 46 | void CancelCurrentAction() { action_queue_.CancelCurrentAction(); } |
| 47 | |
| 48 | void EnqueueAction(::std::unique_ptr<::aos::common::actions::Action> action) { |
| 49 | action_queue_.EnqueueAction(::std::move(action)); |
| 50 | } |
| 51 | |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 52 | private: |
Austin Schuh | 59a62e7 | 2019-03-13 22:39:03 -0700 | [diff] [blame] | 53 | // Handles anything that needs to be cleaned up when the auto action exits. |
| 54 | virtual void AutoEnded() {} |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 55 | // Handles any year specific superstructure code. |
| 56 | virtual void HandleTeleop(const ::aos::input::driver_station::Data &data) = 0; |
| 57 | |
| 58 | void RunIteration(const ::aos::input::driver_station::Data &data) override; |
| 59 | |
| 60 | void StartAuto(); |
| 61 | void StopAuto(); |
| 62 | |
Austin Schuh | a964406 | 2019-03-28 14:31:52 -0700 | [diff] [blame] | 63 | // Returns the current autonomous mode which has been selected by robot |
| 64 | // inputs. |
| 65 | virtual uint32_t GetAutonomousMode() { return 0; } |
| 66 | |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 67 | // True if the internal state machine thinks auto is running right now. |
| 68 | bool auto_running_ = false; |
James Kuszmaul | ccc368b | 2019-04-11 20:00:07 -0700 | [diff] [blame] | 69 | // True if we think that the auto *action* is running right now. |
| 70 | bool auto_action_running_ = false; |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 71 | // True if an action was running last cycle. |
| 72 | bool was_running_ = false; |
| 73 | |
James Kuszmaul | ccc368b | 2019-04-11 20:00:07 -0700 | [diff] [blame] | 74 | const InputConfig input_config_; |
Austin Schuh | 30cc40a | 2019-03-12 21:02:13 -0700 | [diff] [blame] | 75 | |
Austin Schuh | 59a62e7 | 2019-03-13 22:39:03 -0700 | [diff] [blame] | 76 | // Bool to track if auto was running the last cycle through. This lets us |
| 77 | // call AutoEnded when the auto mode function stops. |
| 78 | bool auto_was_running_ = false; |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 79 | ::std::unique_ptr<DrivetrainInputReader> drivetrain_input_reader_; |
| 80 | ::aos::common::actions::ActionQueue action_queue_; |
| 81 | }; |
| 82 | |
| 83 | } // namespace input |
| 84 | } // namespace aos |
| 85 | |
| 86 | #endif // AOS_INPUT_ACTION_JOYSTICK_INPUT_H_ |