Remove global .y2014.control_loops.shooter_queue object

Change-Id: I5e4d4245d8904eaf50ddccf421784bdc4728eb11
diff --git a/y2014/actors/shoot_actor.cc b/y2014/actors/shoot_actor.cc
index 4a57943..736632d 100644
--- a/y2014/actors/shoot_actor.cc
+++ b/y2014/actors/shoot_actor.cc
@@ -27,7 +27,16 @@
               ".y2014.control_loops.claw_queue.status")),
       claw_goal_sender_(
           event_loop->MakeSender<::y2014::control_loops::ClawQueue::Goal>(
-              ".y2014.control_loops.claw_queue.goal")) {}
+              ".y2014.control_loops.claw_queue.goal")),
+      shooter_status_fetcher_(
+          event_loop->MakeFetcher<::y2014::control_loops::ShooterQueue::Status>(
+              ".y2014.control_loops.shooter_queue.status")),
+      shooter_goal_fetcher_(
+          event_loop->MakeFetcher<::y2014::control_loops::ShooterQueue::Goal>(
+              ".y2014.control_loops.shooter_queue.goal")),
+      shooter_goal_sender_(
+          event_loop->MakeSender<::y2014::control_loops::ShooterQueue::Goal>(
+              ".y2014.control_loops.shooter_queue.goal")) {}
 
 double ShootActor::SpeedToAngleOffset(double speed) {
   const constants::Values &values = constants::GetValues();
@@ -63,16 +72,16 @@
 
   // Now do our 'finally' block and make sure that we aren't requesting shots
   // continually.
-  control_loops::shooter_queue.goal.FetchLatest();
-  if (control_loops::shooter_queue.goal.get() == nullptr) {
+  shooter_goal_fetcher_.Fetch();
+  if (shooter_goal_fetcher_.get() == nullptr) {
     return true;
   }
-  if (!control_loops::shooter_queue.goal.MakeWithBuilder()
-           .shot_power(control_loops::shooter_queue.goal->shot_power)
-           .shot_requested(false)
-           .unload_requested(false)
-           .load_requested(false)
-           .Send()) {
+  auto goal_message = shooter_goal_sender_.MakeMessage();
+  goal_message->shot_power = shooter_goal_fetcher_->shot_power;
+  goal_message->shot_requested = false;
+  goal_message->unload_requested = false;
+  goal_message->load_requested = false;
+  if (!goal_message.Send()) {
     LOG(WARNING, "sending shooter goal failed\n");
     return false;
   }
@@ -92,19 +101,22 @@
   if (!IntakeOff()) return;
 
   // Make sure that we have the latest shooter status.
-  control_loops::shooter_queue.status.FetchLatest();
+  shooter_status_fetcher_.Fetch();
   // Get the number of shots fired up to this point. This should not be updated
   // again for another few cycles.
-  previous_shots_ = control_loops::shooter_queue.status->shots;
+  previous_shots_ = shooter_status_fetcher_->shots;
   // Shoot!
-  if (!control_loops::shooter_queue.goal.MakeWithBuilder()
-           .shot_power(control_loops::shooter_queue.goal->shot_power)
-           .shot_requested(true)
-           .unload_requested(false)
-           .load_requested(false)
-           .Send()) {
-    LOG(WARNING, "sending shooter goal failed\n");
-    return;
+  shooter_goal_fetcher_.Fetch();
+  {
+    auto goal_message = shooter_goal_sender_.MakeMessage();
+    goal_message->shot_power = shooter_goal_fetcher_->shot_power;
+    goal_message->shot_requested = true;
+    goal_message->unload_requested = false;
+    goal_message->load_requested = false;
+    if (!goal_message.Send()) {
+      LOG(WARNING, "sending shooter goal failed\n");
+      return;
+    }
   }
 
   // wait for record of shot having been fired
@@ -132,22 +144,22 @@
   return ans;
 }
 
-bool ShooterIsReady() {
-  control_loops::shooter_queue.goal.FetchLatest();
+bool ShootActor::ShooterIsReady() {
+  shooter_goal_fetcher_.Fetch();
 
   LOG(DEBUG, "Power error is %f - %f -> %f, ready %d\n",
-      control_loops::shooter_queue.status->hard_stop_power,
-      control_loops::shooter_queue.goal->shot_power,
-      ::std::abs(control_loops::shooter_queue.status->hard_stop_power -
-                 control_loops::shooter_queue.goal->shot_power),
-      control_loops::shooter_queue.status->ready);
-  return (::std::abs(control_loops::shooter_queue.status->hard_stop_power -
-                     control_loops::shooter_queue.goal->shot_power) < 1.0) &&
-         control_loops::shooter_queue.status->ready;
+      shooter_status_fetcher_->hard_stop_power,
+      shooter_goal_fetcher_->shot_power,
+      ::std::abs(shooter_status_fetcher_->hard_stop_power -
+                 shooter_goal_fetcher_->shot_power),
+      shooter_status_fetcher_->ready);
+  return (::std::abs(shooter_status_fetcher_->hard_stop_power -
+                     shooter_goal_fetcher_->shot_power) < 1.0) &&
+         shooter_status_fetcher_->ready;
 }
 
 bool ShootActor::DoneSetupShot() {
-  control_loops::shooter_queue.status.FetchAnother();
+  shooter_status_fetcher_.Fetch();
   claw_status_fetcher_.Fetch();
   // Make sure that both the shooter and claw have reached the necessary
   // states.
@@ -169,8 +181,9 @@
 }
 
 bool ShootActor::DoneShot() {
-  control_loops::shooter_queue.status.FetchAnother();
-  if (control_loops::shooter_queue.status->shots > previous_shots_) {
+  shooter_status_fetcher_.Fetch();
+  if (shooter_status_fetcher_.get() &&
+      shooter_status_fetcher_->shots > previous_shots_) {
     LOG(INFO, "Shot succeeded!\n");
     return true;
   }
diff --git a/y2014/actors/shoot_actor.h b/y2014/actors/shoot_actor.h
index 33a284c..a4412ff 100644
--- a/y2014/actors/shoot_actor.h
+++ b/y2014/actors/shoot_actor.h
@@ -7,6 +7,7 @@
 #include "aos/actions/actor.h"
 #include "y2014/actors/shoot_action.q.h"
 #include "y2014/control_loops/claw/claw.q.h"
+#include "y2014/control_loops/shooter/shooter.q.h"
 
 namespace y2014 {
 namespace actors {
@@ -43,6 +44,7 @@
   bool DonePreShotOpen();
   // in the right place
   bool DoneSetupShot();
+  bool ShooterIsReady();
 
   bool IntakeOff();
   bool ClawIsReady();
@@ -52,6 +54,12 @@
   ::aos::Fetcher<::y2014::control_loops::ClawQueue::Status>
       claw_status_fetcher_;
   ::aos::Sender<::y2014::control_loops::ClawQueue::Goal> claw_goal_sender_;
+  ::aos::Fetcher<::y2014::control_loops::ShooterQueue::Status>
+      shooter_status_fetcher_;
+  ::aos::Fetcher<::y2014::control_loops::ShooterQueue::Goal>
+      shooter_goal_fetcher_;
+  ::aos::Sender<::y2014::control_loops::ShooterQueue::Goal>
+      shooter_goal_sender_;
 
   // to track when shot is complete
   int previous_shots_;
diff --git a/y2014/control_loops/shooter/BUILD b/y2014/control_loops/shooter/BUILD
index b58ff98..075cafc 100644
--- a/y2014/control_loops/shooter/BUILD
+++ b/y2014/control_loops/shooter/BUILD
@@ -2,18 +2,6 @@
 
 load("//aos/build:queues.bzl", "queue_library")
 
-cc_binary(
-    name = "replay_shooter",
-    srcs = [
-        "replay_shooter.cc",
-    ],
-    deps = [
-        ":shooter_queue",
-        "//aos:init",
-        "//aos/controls:replay_control_loop",
-    ],
-)
-
 queue_library(
     name = "shooter_queue",
     srcs = [
diff --git a/y2014/control_loops/shooter/replay_shooter.cc b/y2014/control_loops/shooter/replay_shooter.cc
deleted file mode 100644
index e86cedc..0000000
--- a/y2014/control_loops/shooter/replay_shooter.cc
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "aos/controls/replay_control_loop.h"
-#include "aos/init.h"
-
-#include "y2014/control_loops/shooter/shooter.q.h"
-
-// Reads one or more log files and sends out all the queue messages (in the
-// correct order and at the correct time) to feed a "live" shooter process.
-
-int main(int argc, char **argv) {
-  if (argc <= 1) {
-    fprintf(stderr, "Need at least one file to replay!\n");
-    return EXIT_FAILURE;
-  }
-
-  ::aos::InitNRT();
-
-  ::aos::controls::ControlLoopReplayer<::y2014::control_loops::ShooterQueue>
-      replayer(&::y2014::control_loops::shooter_queue, "shooter");
-  for (int i = 1; i < argc; ++i) {
-    replayer.ProcessFile(argv[i]);
-  }
-
-  ::aos::Cleanup();
-}
diff --git a/y2014/control_loops/shooter/shooter.q b/y2014/control_loops/shooter/shooter.q
index 5624d84..c7ed97d 100644
--- a/y2014/control_loops/shooter/shooter.q
+++ b/y2014/control_loops/shooter/shooter.q
@@ -3,6 +3,7 @@
 import "aos/controls/control_loops.q";
 import "frc971/control_loops/control_loops.q";
 
+// Published on ".y2014.control_loops.shooter_queue"
 queue_group ShooterQueue {
   implements aos.control_loops.ControlLoop;
 
@@ -61,8 +62,6 @@
   queue Status status;
 };
 
-queue_group ShooterQueue shooter_queue;
-
 struct ShooterStateToLog {
 	double absolute_position;
 	double absolute_velocity;
diff --git a/y2014/joystick_reader.cc b/y2014/joystick_reader.cc
index 590c74a..5510635 100644
--- a/y2014/joystick_reader.cc
+++ b/y2014/joystick_reader.cc
@@ -165,6 +165,9 @@
         claw_goal_sender_(
             event_loop->MakeSender<::y2014::control_loops::ClawQueue::Goal>(
                 ".y2014.control_loops.claw_queue.goal")),
+        shooter_goal_sender_(
+            event_loop->MakeSender<::y2014::control_loops::ShooterQueue::Goal>(
+                ".y2014.control_loops.shooter_queue.goal")),
         shot_power_(80.0),
         goal_angle_(0.0),
         separation_angle_(kGrabSeparation),
@@ -389,13 +392,15 @@
         }
       }
 
-      if (!control_loops::shooter_queue.goal.MakeWithBuilder()
-               .shot_power(shot_power_)
-               .shot_requested(data.IsPressed(kFire))
-               .unload_requested(data.IsPressed(kUnload))
-               .load_requested(data.IsPressed(kReload))
-               .Send()) {
-        LOG(WARNING, "sending shooter goal failed\n");
+      {
+        auto goal_message = shooter_goal_sender_.MakeMessage();
+        goal_message->shot_power = shot_power_;
+        goal_message->shot_requested = data.IsPressed(kFire);
+        goal_message->unload_requested = data.IsPressed(kUnload);
+        goal_message->load_requested = data.IsPressed(kReload);
+        if (!goal_message.Send()) {
+          LOG(WARNING, "sending shooter goal failed\n");
+        }
       }
     }
   }
@@ -411,6 +416,7 @@
   ::aos::Fetcher<::y2014::control_loops::ClawQueue::Status>
       claw_status_fetcher_;
   ::aos::Sender<::y2014::control_loops::ClawQueue::Goal> claw_goal_sender_;
+  ::aos::Sender<::y2014::control_loops::ShooterQueue::Goal> shooter_goal_sender_;
 
   double shot_power_;
   double goal_angle_;