blob: 87b980e7a50d74cc99a89ff7a5c70c841ba0e018 [file] [log] [blame]
Sabina Davis91b23602019-01-21 00:06:01 -08001#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
10namespace aos {
11namespace 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.
15class 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 Schuh30cc40a2019-03-12 21:02:13 -070027 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 Davis91b23602019-01-21 00:06:01 -080032 private:
Austin Schuh59a62e72019-03-13 22:39:03 -070033 // Handles anything that needs to be cleaned up when the auto action exits.
34 virtual void AutoEnded() {}
Sabina Davis91b23602019-01-21 00:06:01 -080035 // 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 Schuh30cc40a2019-03-12 21:02:13 -070048 // 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 Schuh59a62e72019-03-13 22:39:03 -070054 // 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 Davis91b23602019-01-21 00:06:01 -080058 ::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_