Switch away from watchers in autonomous
Since auto is blocking, they never get run. The end result is that we
crash auto when it finishes.
Change-Id: I7e382a6b7551fc373636ac11761efc1e876349d1
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/y2020/actors/autonomous_actor.cc b/y2020/actors/autonomous_actor.cc
index d25a8c3..46a7542 100644
--- a/y2020/actors/autonomous_actor.cc
+++ b/y2020/actors/autonomous_actor.cc
@@ -38,27 +38,33 @@
superstructure_goal_sender_(
event_loop->MakeSender<control_loops::superstructure::Goal>(
"/superstructure")),
- joystick_state_fetcher_(
- event_loop->MakeFetcher<aos::JoystickState>("/aos")),
superstructure_status_fetcher_(
event_loop->MakeFetcher<y2020::control_loops::superstructure::Status>(
"/superstructure")),
+ joystick_state_fetcher_(
+ event_loop->MakeFetcher<aos::JoystickState>("/aos")),
+ robot_state_fetcher_(event_loop->MakeFetcher<aos::RobotState>("/aos")),
auto_splines_() {
set_max_drivetrain_voltage(12.0);
replan_timer_ = event_loop->AddTimer([this]() { Replan(); });
event_loop->OnRun([this, event_loop]() {
replan_timer_->Setup(event_loop->monotonic_now());
+ button_poll_->Setup(event_loop->monotonic_now(), chrono::milliseconds(50));
});
- event_loop->MakeWatcher("/aos", [this](const aos::RobotState &msg) {
- if (msg.user_button()) {
- user_indicated_safe_to_reset_ = true;
- MaybeSendStartingPosition();
+
+ button_poll_ = event_loop->AddTimer([this]() {
+ if (robot_state_fetcher_.Fetch()) {
+ if (robot_state_fetcher_->user_button()) {
+ user_indicated_safe_to_reset_ = true;
+ MaybeSendStartingPosition();
+ }
}
- });
- event_loop->MakeWatcher("/aos", [this](const aos::JoystickState &msg) {
- if (msg.has_alliance() && (msg.alliance() != alliance_)) {
- alliance_ = msg.alliance();
- Replan();
+ if (joystick_state_fetcher_.Fetch()) {
+ if (joystick_state_fetcher_->has_alliance() &&
+ (joystick_state_fetcher_->alliance() != alliance_)) {
+ alliance_ = joystick_state_fetcher_->alliance();
+ Replan();
+ }
}
});
}
diff --git a/y2020/actors/autonomous_actor.h b/y2020/actors/autonomous_actor.h
index 3e698f3..7cbabb0 100644
--- a/y2020/actors/autonomous_actor.h
+++ b/y2020/actors/autonomous_actor.h
@@ -71,11 +71,13 @@
localizer_control_sender_;
aos::Sender<y2020::control_loops::superstructure::Goal>
superstructure_goal_sender_;
- aos::Fetcher<aos::JoystickState> joystick_state_fetcher_;
aos::Fetcher<y2020::control_loops::superstructure::Status>
superstructure_status_fetcher_;
+ aos::Fetcher<aos::JoystickState> joystick_state_fetcher_;
+ aos::Fetcher<aos::RobotState> robot_state_fetcher_;
aos::TimerHandler *replan_timer_;
+ aos::TimerHandler *button_poll_;
std::optional<std::array<SplineHandle, 2>> target_offset_splines_;
std::optional<std::array<SplineHandle, 2>> target_aligned_splines_;