Added a AutoEnded function
This gets called when the auto action finishes running. This lets us
reset state when the driver takes control. It gets run before
HandleTeleop.
Change-Id: I2969d95ed623f9e45735c07da1dc6c504efae06b
diff --git a/aos/input/action_joystick_input.cc b/aos/input/action_joystick_input.cc
index c2c3763..81e277d 100644
--- a/aos/input/action_joystick_input.cc
+++ b/aos/input/action_joystick_input.cc
@@ -16,6 +16,7 @@
data.GetControlBit(ControlBit::kEnabled);
if (auto_running_ != last_auto_running) {
if (auto_running_) {
+ auto_was_running_ = true;
StartAuto();
} else {
StopAuto();
@@ -23,6 +24,10 @@
}
if (!auto_running_ || (run_teleop_in_auto_ && !action_queue_.Running())) {
+ if (auto_was_running_) {
+ AutoEnded();
+ auto_was_running_ = false;
+ }
if (!data.GetControlBit(ControlBit::kEnabled)) {
action_queue_.CancelAllActions();
LOG(DEBUG, "Canceling\n");
diff --git a/aos/input/action_joystick_input.h b/aos/input/action_joystick_input.h
index 9936c98..87b980e 100644
--- a/aos/input/action_joystick_input.h
+++ b/aos/input/action_joystick_input.h
@@ -30,6 +30,8 @@
}
private:
+ // Handles anything that needs to be cleaned up when the auto action exits.
+ virtual void AutoEnded() {}
// Handles any year specific superstructure code.
virtual void HandleTeleop(const ::aos::input::driver_station::Data &data) = 0;
@@ -49,6 +51,10 @@
// finish early), we will run teleop regardless of the mode.
bool run_teleop_in_auto_ = false;
+ // Bool to track if auto was running the last cycle through. This lets us
+ // call AutoEnded when the auto mode function stops.
+ bool auto_was_running_ = false;
+
::std::unique_ptr<DrivetrainInputReader> drivetrain_input_reader_;
::aos::common::actions::ActionQueue action_queue_;
};