blob: 061f4dc441410150e7801f8ed26d588c0211df5b [file] [log] [blame]
Sabina Davis91b23602019-01-21 00:06:01 -08001#include "aos/input/action_joystick_input.h"
2
3#include "aos/input/driver_station_data.h"
4#include "frc971/autonomous/auto.q.h"
5#include "frc971/autonomous/base_autonomous_actor.h"
6
7using ::aos::input::driver_station::ControlBit;
8
9namespace aos {
10namespace input {
11
12void ActionJoystickInput::RunIteration(
13 const ::aos::input::driver_station::Data &data) {
14 const bool last_auto_running = auto_running_;
15 auto_running_ = data.GetControlBit(ControlBit::kAutonomous) &&
16 data.GetControlBit(ControlBit::kEnabled);
17 if (auto_running_ != last_auto_running) {
18 if (auto_running_) {
Austin Schuh59a62e72019-03-13 22:39:03 -070019 auto_was_running_ = true;
Sabina Davis91b23602019-01-21 00:06:01 -080020 StartAuto();
21 } else {
22 StopAuto();
23 }
24 }
25
Austin Schuh30cc40a2019-03-12 21:02:13 -070026 if (!auto_running_ || (run_teleop_in_auto_ && !action_queue_.Running())) {
Austin Schuh59a62e72019-03-13 22:39:03 -070027 if (auto_was_running_) {
28 AutoEnded();
29 auto_was_running_ = false;
30 }
Sabina Davis91b23602019-01-21 00:06:01 -080031 if (!data.GetControlBit(ControlBit::kEnabled)) {
32 action_queue_.CancelAllActions();
33 LOG(DEBUG, "Canceling\n");
34 }
35 drivetrain_input_reader_->HandleDrivetrain(data);
36 HandleTeleop(data);
37 }
38
39 // Process pending actions.
40 action_queue_.Tick();
41 was_running_ = action_queue_.Running();
42}
43
44void ActionJoystickInput::StartAuto() {
45 LOG(INFO, "Starting auto mode\n");
Austin Schuha9644062019-03-28 14:31:52 -070046 action_queue_.EnqueueAction(
47 ::frc971::autonomous::MakeAutonomousAction(GetAutonomousMode()));
Sabina Davis91b23602019-01-21 00:06:01 -080048}
49
50void ActionJoystickInput::StopAuto() {
51 LOG(INFO, "Stopping auto mode\n");
52 action_queue_.CancelAllActions();
53}
54
55} // namespace input
56} // namespace aos