Remove global .frc971.control_loops.drivetrain_queue object

Change-Id: I424f09dcc8bc210e49cbdc805d1a423a72332617
diff --git a/y2019/actors/autonomous_actor.cc b/y2019/actors/autonomous_actor.cc
index 0f2b04e..5138123 100644
--- a/y2019/actors/autonomous_actor.cc
+++ b/y2019/actors/autonomous_actor.cc
@@ -16,7 +16,6 @@
 namespace y2019 {
 namespace actors {
 using ::aos::monotonic_clock;
-using ::frc971::control_loops::drivetrain_queue;
 namespace chrono = ::std::chrono;
 
 AutonomousActor::AutonomousActor(::aos::EventLoop *event_loop)
@@ -46,9 +45,9 @@
       return false;
     }
     phased_loop.SleepUntilNext();
-    drivetrain_queue.status.FetchLatest();
-    if (drivetrain_queue.status->x > x) {
-      LOG(INFO, "X at %f\n", drivetrain_queue.status->x);
+    drivetrain_status_fetcher_.Fetch();
+    if (drivetrain_status_fetcher_->x > x) {
+      LOG(INFO, "X at %f\n", drivetrain_status_fetcher_->x);
       return true;
     }
   }
@@ -65,9 +64,9 @@
       return false;
     }
     phased_loop.SleepUntilNext();
-    drivetrain_queue.status.FetchLatest();
-    if (::std::abs(drivetrain_queue.status->y) < y) {
-      LOG(INFO, "Y at %f\n", drivetrain_queue.status->y);
+    drivetrain_status_fetcher_.Fetch();
+    if (::std::abs(drivetrain_status_fetcher_->y) < y) {
+      LOG(INFO, "Y at %f\n", drivetrain_status_fetcher_->y);
       return true;
     }
   }
@@ -104,12 +103,12 @@
 
   // Wait for the drivetrain to run so it has time to reset the heading.
   // Otherwise our drivetrain reset will do a 180 right at the start.
-  drivetrain_queue.status.FetchAnother();
-  LOG(INFO, "Heading is %f\n", drivetrain_queue.status->estimated_heading);
+  WaitUntil([this]() { return drivetrain_status_fetcher_.Fetch(); });
+  LOG(INFO, "Heading is %f\n", drivetrain_status_fetcher_->estimated_heading);
   InitializeEncoders();
   ResetDrivetrain();
-  drivetrain_queue.status.FetchAnother();
-  LOG(INFO, "Heading is %f\n", drivetrain_queue.status->estimated_heading);
+  WaitUntil([this]() { return drivetrain_status_fetcher_.Fetch(); });
+  LOG(INFO, "Heading is %f\n", drivetrain_status_fetcher_->estimated_heading);
 
   ResetDrivetrain();
   InitializeEncoders();
diff --git a/y2019/control_loops/superstructure/superstructure.cc b/y2019/control_loops/superstructure/superstructure.cc
index a4796a8..ec9e2e5 100644
--- a/y2019/control_loops/superstructure/superstructure.cc
+++ b/y2019/control_loops/superstructure/superstructure.cc
@@ -16,6 +16,10 @@
     : aos::controls::ControlLoop<SuperstructureQueue>(event_loop, name),
       status_light_sender_(
           event_loop->MakeSender<::y2019::StatusLight>(".y2019.status_light")),
+      drivetrain_status_fetcher_(
+          event_loop
+              ->MakeFetcher<::frc971::control_loops::DrivetrainQueue::Status>(
+                  ".frc971.control_loops.drivetrain_queue.status")),
       elevator_(constants::GetValues().elevator.subsystem_params),
       wrist_(constants::GetValues().wrist.subsystem_params),
       intake_(constants::GetValues().intake),
@@ -94,22 +98,20 @@
   intake_.set_min_position(collision_avoidance_.min_intake_goal());
   intake_.set_max_position(collision_avoidance_.max_intake_goal());
 
-  ::frc971::control_loops::drivetrain_queue.status.FetchLatest();
+  drivetrain_status_fetcher_.Fetch();
 
   if (status && unsafe_goal) {
     // Light Logic
     if (status->estopped) {
       // Estop is red
       SendColors(1.0, 0.0, 0.0);
-    } else if (::frc971::control_loops::drivetrain_queue.status.get() &&
-               ::frc971::control_loops::drivetrain_queue.status
-                   ->line_follow_logging.frozen) {
+    } else if (drivetrain_status_fetcher_.get() &&
+               drivetrain_status_fetcher_->line_follow_logging.frozen) {
       // Vision align is flashing white for button pressed, purple for target
       // acquired.
       ++line_blink_count_;
       if (line_blink_count_ < 20) {
-        if (::frc971::control_loops::drivetrain_queue.status
-                ->line_follow_logging.have_target) {
+        if (drivetrain_status_fetcher_->line_follow_logging.have_target) {
           SendColors(1.0, 0.0, 1.0);
         } else {
           SendColors(1.0, 1.0, 1.0);
diff --git a/y2019/control_loops/superstructure/superstructure.h b/y2019/control_loops/superstructure/superstructure.h
index 2d51cff..aab8e7d 100644
--- a/y2019/control_loops/superstructure/superstructure.h
+++ b/y2019/control_loops/superstructure/superstructure.h
@@ -3,6 +3,7 @@
 
 #include "aos/controls/control_loop.h"
 #include "aos/events/event-loop.h"
+#include "frc971/control_loops/drivetrain/drivetrain.q.h"
 #include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem.h"
 #include "y2019/constants.h"
 #include "y2019/control_loops/superstructure/collision_avoidance.h"
@@ -47,6 +48,8 @@
   void SendColors(float red, float green, float blue);
 
   ::aos::Sender<::y2019::StatusLight> status_light_sender_;
+  ::aos::Fetcher<::frc971::control_loops::DrivetrainQueue::Status>
+      drivetrain_status_fetcher_;
 
   PotAndAbsoluteEncoderSubsystem elevator_;
   PotAndAbsoluteEncoderSubsystem wrist_;
diff --git a/y2019/control_loops/superstructure/superstructure_lib_test.cc b/y2019/control_loops/superstructure/superstructure_lib_test.cc
index 036b210..7628ca8 100644
--- a/y2019/control_loops/superstructure/superstructure_lib_test.cc
+++ b/y2019/control_loops/superstructure/superstructure_lib_test.cc
@@ -6,7 +6,6 @@
 #include "aos/controls/control_loop_test.h"
 #include "aos/queue.h"
 #include "frc971/control_loops/capped_test_plant.h"
-#include "frc971/control_loops/drivetrain/drivetrain.q.h"
 #include "frc971/control_loops/position_sensor_sim.h"
 #include "frc971/control_loops/team_number_test_environment.h"
 #include "gtest/gtest.h"
@@ -289,7 +288,6 @@
             ".y2019.control_loops.superstructure.superstructure_queue."
             "position"),
         superstructure_(&event_loop_) {
-    ::frc971::control_loops::drivetrain_queue.status.Clear();
     set_team_id(::frc971::control_loops::testing::kTeamNumber);
   }
 
diff --git a/y2019/wpilib_interface.cc b/y2019/wpilib_interface.cc
index 31b5158..9ca37d8 100644
--- a/y2019/wpilib_interface.cc
+++ b/y2019/wpilib_interface.cc
@@ -56,7 +56,6 @@
 #define M_PI 3.14159265358979323846
 #endif
 
-using ::frc971::control_loops::drivetrain_queue;
 using ::y2019::control_loops::superstructure::SuperstructureQueue;
 using ::y2019::constants::Values;
 using ::aos::monotonic_clock;
@@ -138,7 +137,11 @@
         superstructure_position_sender_(
             event_loop->MakeSender<SuperstructureQueue::Position>(
                 ".y2019.control_loops.superstructure.superstructure_queue."
-                "position")) {
+                "position")),
+        drivetrain_position_sender_(
+            event_loop->MakeSender<
+                ::frc971::control_loops::DrivetrainQueue::Position>(
+                ".frc971.control_loops.drivetrain_queue.position")) {
     // Set to filter out anything shorter than 1/4 of the minimum pulse width
     // we should ever see.
     UpdateFastEncoderFilterHz(kMaxFastEncoderPulsesPerSecond);
@@ -230,7 +233,7 @@
 
   void RunIteration() override {
     {
-      auto drivetrain_message = drivetrain_queue.position.MakeMessage();
+      auto drivetrain_message = drivetrain_position_sender_.MakeMessage();
       drivetrain_message->left_encoder =
           drivetrain_translate(drivetrain_left_encoder_->GetRaw());
       drivetrain_message->left_speed =
@@ -302,6 +305,8 @@
  private:
   ::aos::Sender<::frc971::autonomous::AutonomousMode> auto_mode_sender_;
   ::aos::Sender<SuperstructureQueue::Position> superstructure_position_sender_;
+  ::aos::Sender<::frc971::control_loops::DrivetrainQueue::Position>
+      drivetrain_position_sender_;
 
   ::frc971::wpilib::AbsoluteEncoderAndPotentiometer elevator_encoder_,
       wrist_encoder_, stilts_encoder_;