Convert vision_status to event loops
Change-Id: I06c329f3fe42d2dbfa7da90d598c93eacdf746c7
diff --git a/y2018/control_loops/superstructure/superstructure.cc b/y2018/control_loops/superstructure/superstructure.cc
index d94e34d..d0ff71d 100644
--- a/y2018/control_loops/superstructure/superstructure.cc
+++ b/y2018/control_loops/superstructure/superstructure.cc
@@ -30,6 +30,9 @@
name),
status_light_sender_(
event_loop->MakeSender<::y2018::StatusLight>(".y2018.status_light")),
+ vision_status_fetcher_(
+ event_loop->MakeFetcher<::y2018::vision::VisionStatus>(
+ ".y2018.vision.vision_status")),
intake_left_(constants::GetValues().left_intake.zeroing),
intake_right_(constants::GetValues().right_intake.zeroing) {}
@@ -255,11 +258,13 @@
::frc971::control_loops::drivetrain_queue.output.FetchLatest();
- ::y2018::vision::vision_status.FetchLatest();
+ vision_status_fetcher_.Fetch();
+ monotonic_clock::time_point monotonic_now = event_loop()->monotonic_now();
if (status->estopped) {
SendColors(0.5, 0.0, 0.0);
- } else if (!y2018::vision::vision_status.get() ||
- y2018::vision::vision_status.Age() > chrono::seconds(1)) {
+ } else if (!vision_status_fetcher_.get() ||
+ monotonic_now >
+ vision_status_fetcher_->sent_time + chrono::seconds(1)) {
SendColors(0.5, 0.5, 0.0);
} else if (rotation_state_ == RotationState::ROTATING_LEFT ||
rotation_state_ == RotationState::ROTATING_RIGHT) {
diff --git a/y2018/control_loops/superstructure/superstructure.h b/y2018/control_loops/superstructure/superstructure.h
index 8ab6bf3..bceb643 100644
--- a/y2018/control_loops/superstructure/superstructure.h
+++ b/y2018/control_loops/superstructure/superstructure.h
@@ -10,6 +10,7 @@
#include "y2018/control_loops/superstructure/intake/intake.h"
#include "y2018/control_loops/superstructure/superstructure.q.h"
#include "y2018/status_light.q.h"
+#include "y2018/vision/vision.q.h"
namespace y2018 {
namespace control_loops {
@@ -38,6 +39,7 @@
void SendColors(float red, float green, float blue);
::aos::Sender<::y2018::StatusLight> status_light_sender_;
+ ::aos::Fetcher<::y2018::vision::VisionStatus> vision_status_fetcher_;
intake::IntakeSide intake_left_;
intake::IntakeSide intake_right_;
diff --git a/y2018/control_loops/superstructure/superstructure_lib_test.cc b/y2018/control_loops/superstructure/superstructure_lib_test.cc
index 5fa4abe..8533dce 100644
--- a/y2018/control_loops/superstructure/superstructure_lib_test.cc
+++ b/y2018/control_loops/superstructure/superstructure_lib_test.cc
@@ -274,7 +274,6 @@
".y2018.control_loops.superstructure.status",
".y2018.control_loops.superstructure.position"),
superstructure_(&event_loop_, ".y2018.control_loops.superstructure") {
- ::y2018::vision::vision_status.Clear();
::frc971::control_loops::drivetrain_queue.output.Clear();
set_team_id(::frc971::control_loops::testing::kTeamNumber);
}