Convert aos over to flatbuffers

Everything builds, and all the tests pass.  I suspect that some entries
are missing from the config files, but those will be found pretty
quickly on startup.

There is no logging or live introspection of queue messages.

Change-Id: I496ee01ed68f202c7851bed7e8786cee30df29f5
diff --git a/y2018/actors/BUILD b/y2018/actors/BUILD
index 7d97f66..7a95419 100644
--- a/y2018/actors/BUILD
+++ b/y2018/actors/BUILD
@@ -8,14 +8,14 @@
     ],
     deps = [
         "//aos/actions:action_lib",
-        "//aos/events:event-loop",
+        "//aos/events:event_loop",
         "//aos/logging",
         "//aos/util:phased_loop",
         "//frc971/autonomous:base_autonomous_actor",
         "//frc971/control_loops/drivetrain:drivetrain_config",
-        "//frc971/control_loops/drivetrain:drivetrain_queue",
         "//y2018/control_loops/drivetrain:drivetrain_base",
-        "//y2018/control_loops/superstructure:superstructure_queue",
+        "//y2018/control_loops/superstructure:superstructure_goal_fbs",
+        "//y2018/control_loops/superstructure:superstructure_status_fbs",
         "//y2018/control_loops/superstructure/arm:generated_graph",
     ],
 )
@@ -29,7 +29,6 @@
     deps = [
         ":autonomous_action_lib",
         "//aos:init",
-        "//aos/events:shm-event-loop",
-        "//frc971/autonomous:auto_queue",
+        "//aos/events:shm_event_loop",
     ],
 )
diff --git a/y2018/actors/autonomous_actor.cc b/y2018/actors/autonomous_actor.cc
index dd94083..89082df 100644
--- a/y2018/actors/autonomous_actor.cc
+++ b/y2018/actors/autonomous_actor.cc
@@ -8,12 +8,11 @@
 #include "aos/logging/logging.h"
 #include "aos/util/phased_loop.h"
 
-#include "frc971/control_loops/drivetrain/drivetrain.q.h"
 #include "y2018/control_loops/drivetrain/drivetrain_base.h"
 
 namespace y2018 {
 namespace actors {
-using ::frc971::ProfileParameters;
+using ::frc971::ProfileParametersT;
 
 using ::aos::monotonic_clock;
 namespace chrono = ::std::chrono;
@@ -23,25 +22,34 @@
 
 namespace arm = ::y2018::control_loops::superstructure::arm;
 
-const ProfileParameters kFinalSwitchDrive = {0.5, 1.5};
-const ProfileParameters kDrive = {5.0, 2.5};
-const ProfileParameters kThirdBoxDrive = {3.0, 2.5};
-const ProfileParameters kSlowDrive = {1.5, 2.5};
-const ProfileParameters kScaleTurnDrive = {3.0, 2.5};
-const ProfileParameters kFarSwitchTurnDrive = {2.0, 2.5};
-const ProfileParameters kFarScaleFinalTurnDrive = kFarSwitchTurnDrive;
-const ProfileParameters kTurn = {4.0, 2.0};
-const ProfileParameters kSweepingTurn = {5.0, 7.0};
-const ProfileParameters kFarScaleSweepingTurn = kSweepingTurn;
-const ProfileParameters kFastTurn = {5.0, 7.0};
-const ProfileParameters kReallyFastTurn = {1.5, 9.0};
+ProfileParametersT MakeProfileParameters(float max_velocity,
+                                         float max_acceleration) {
+  ProfileParametersT result;
+  result.max_velocity = max_velocity;
+  result.max_acceleration = max_acceleration;
+  return result;
+}
 
-const ProfileParameters kThirdBoxSlowBackup = {0.35, 1.5};
-const ProfileParameters kThirdBoxSlowTurn = {1.5, 4.0};
+const ProfileParametersT kFinalSwitchDrive = MakeProfileParameters(0.5, 1.5);
+const ProfileParametersT kDrive = MakeProfileParameters(5.0, 2.5);
+const ProfileParametersT kThirdBoxDrive = MakeProfileParameters(3.0, 2.5);
+const ProfileParametersT kSlowDrive = MakeProfileParameters(1.5, 2.5);
+const ProfileParametersT kScaleTurnDrive = MakeProfileParameters(3.0, 2.5);
+const ProfileParametersT kFarSwitchTurnDrive = MakeProfileParameters(2.0, 2.5);
+const ProfileParametersT kFarScaleFinalTurnDrive = kFarSwitchTurnDrive;
+const ProfileParametersT kTurn = MakeProfileParameters(4.0, 2.0);
+const ProfileParametersT kSweepingTurn = MakeProfileParameters(5.0, 7.0);
+const ProfileParametersT kFarScaleSweepingTurn = kSweepingTurn;
+const ProfileParametersT kFastTurn = MakeProfileParameters(5.0, 7.0);
+const ProfileParametersT kReallyFastTurn = MakeProfileParameters(1.5, 9.0);
 
-const ProfileParameters kThirdBoxPlaceDrive = {4.0, 2.0};
+const ProfileParametersT kThirdBoxSlowBackup = MakeProfileParameters(0.35, 1.5);
+const ProfileParametersT kThirdBoxSlowTurn = MakeProfileParameters(1.5, 4.0);
 
-const ProfileParameters kFinalFrontFarSwitchDrive = {2.0, 2.0};
+const ProfileParametersT kThirdBoxPlaceDrive = MakeProfileParameters(4.0, 2.0);
+
+const ProfileParametersT kFinalFrontFarSwitchDrive =
+    MakeProfileParameters(2.0, 2.0);
 
 }  // namespace
 
@@ -49,24 +57,23 @@
     : frc971::autonomous::BaseAutonomousActor(
           event_loop, control_loops::drivetrain::GetDrivetrainConfig()),
       superstructure_goal_sender_(
-          event_loop
-              ->MakeSender<::y2018::control_loops::SuperstructureQueue::Goal>(
-                  ".frc971.control_loops.superstructure_queue.goal")),
+          event_loop->MakeSender<::y2018::control_loops::superstructure::Goal>(
+              "/superstructure")),
       superstructure_status_fetcher_(
-          event_loop->MakeFetcher<
-              ::y2018::control_loops::SuperstructureQueue::Status>(
-              ".frc971.control_loops.superstructure_queue.status")) {}
+          event_loop
+              ->MakeFetcher<::y2018::control_loops::superstructure::Status>(
+                  "/superstructure")) {}
 
 bool AutonomousActor::RunAction(
-    const ::frc971::autonomous::AutonomousActionParams &params) {
+    const ::frc971::autonomous::AutonomousActionParams *params) {
   const monotonic_clock::time_point start_time = monotonic_now();
   AOS_LOG(INFO, "Starting autonomous action with mode %" PRId32 "\n",
-          params.mode);
+          params->mode());
   Reset();
 
   // Switch
   /*
-  switch (params.mode) {
+  switch (params->mode()) {
     case 0:
     case 2: {
       if (FarSwitch(start_time, true)) return true;
@@ -79,7 +86,7 @@
   }
   */
   // Scale
-  switch (params.mode) {
+  switch (params->mode()) {
     case 0:
     case 1: {
       if (FarScale(start_time)) return true;
@@ -91,7 +98,7 @@
     } break;
   }
   /*
-  switch (params.mode) {
+  switch (params->mode()) {
     case 1: {
       if (FarScale(start_time)) return true;
       //if (CloseSwitch(start_time)) return true;
diff --git a/y2018/actors/autonomous_actor.h b/y2018/actors/autonomous_actor.h
index 3ef7677..014459a 100644
--- a/y2018/actors/autonomous_actor.h
+++ b/y2018/actors/autonomous_actor.h
@@ -6,12 +6,13 @@
 
 #include "aos/actions/actions.h"
 #include "aos/actions/actor.h"
-#include "aos/events/event-loop.h"
+#include "aos/events/event_loop.h"
 #include "frc971/autonomous/base_autonomous_actor.h"
-#include "frc971/control_loops/drivetrain/drivetrain.q.h"
 #include "frc971/control_loops/drivetrain/drivetrain_config.h"
+#include "frc971/control_loops/drivetrain/drivetrain_status_generated.h"
 #include "y2018/control_loops/superstructure/arm/generated_graph.h"
-#include "y2018/control_loops/superstructure/superstructure.q.h"
+#include "y2018/control_loops/superstructure/superstructure_goal_generated.h"
+#include "y2018/control_loops/superstructure/superstructure_status_generated.h"
 
 namespace y2018 {
 namespace actors {
@@ -21,7 +22,7 @@
   explicit AutonomousActor(::aos::EventLoop *event_loop);
 
   bool RunAction(
-      const ::frc971::autonomous::AutonomousActionParams &params) override;
+      const ::frc971::autonomous::AutonomousActionParams *params) override;
 
  private:
   void Reset() {
@@ -40,9 +41,9 @@
     SendSuperstructureGoal();
   }
 
-  ::aos::Sender<::y2018::control_loops::SuperstructureQueue::Goal>
+  ::aos::Sender<::y2018::control_loops::superstructure::Goal>
       superstructure_goal_sender_;
-  ::aos::Fetcher<::y2018::control_loops::SuperstructureQueue::Status>
+  ::aos::Fetcher<::y2018::control_loops::superstructure::Status>
       superstructure_status_fetcher_;
 
   double roller_voltage_ = 0.0;
@@ -82,19 +83,29 @@
   }
 
   void SendSuperstructureGoal() {
-    auto new_superstructure_goal = superstructure_goal_sender_.MakeMessage();
-    new_superstructure_goal->intake.roller_voltage = roller_voltage_;
-    new_superstructure_goal->intake.left_intake_angle = left_intake_angle_;
-    new_superstructure_goal->intake.right_intake_angle = right_intake_angle_;
+    auto builder = superstructure_goal_sender_.MakeBuilder();
+    control_loops::superstructure::IntakeGoal::Builder intake_goal_builder =
+        builder.MakeBuilder<control_loops::superstructure::IntakeGoal>();
+    intake_goal_builder.add_roller_voltage(roller_voltage_);
+    intake_goal_builder.add_left_intake_angle(left_intake_angle_);
+    intake_goal_builder.add_right_intake_angle(right_intake_angle_);
 
-    new_superstructure_goal->arm_goal_position = arm_goal_position_;
-    new_superstructure_goal->grab_box = grab_box_;
-    new_superstructure_goal->open_claw = open_claw_;
-    new_superstructure_goal->close_claw = close_claw_;
-    new_superstructure_goal->deploy_fork = deploy_fork_;
-    new_superstructure_goal->trajectory_override = false;
+    flatbuffers::Offset<control_loops::superstructure::IntakeGoal>
+        intake_offset = intake_goal_builder.Finish();
 
-    if (!new_superstructure_goal.Send()) {
+    control_loops::superstructure::Goal::Builder superstructure_builder =
+        builder.MakeBuilder<control_loops::superstructure::Goal>();
+
+    superstructure_builder.add_intake(intake_offset);
+
+    superstructure_builder.add_arm_goal_position(arm_goal_position_);
+    superstructure_builder.add_grab_box(grab_box_);
+    superstructure_builder.add_open_claw(open_claw_);
+    superstructure_builder.add_close_claw(close_claw_);
+    superstructure_builder.add_deploy_fork(deploy_fork_);
+    superstructure_builder.add_trajectory_override(false);
+
+    if (!builder.Send(superstructure_builder.Finish())) {
       AOS_LOG(ERROR, "Sending superstructure goal failed.\n");
     }
   }
@@ -129,17 +140,17 @@
           superstructure_status_fetcher_.get()) {
         const double left_profile_error =
             (initial_drivetrain_.left -
-             drivetrain_status_fetcher_->profiled_left_position_goal);
+             drivetrain_status_fetcher_->profiled_left_position_goal());
         const double right_profile_error =
             (initial_drivetrain_.right -
-             drivetrain_status_fetcher_->profiled_right_position_goal);
+             drivetrain_status_fetcher_->profiled_right_position_goal());
 
         const double left_error =
             (initial_drivetrain_.left -
-             drivetrain_status_fetcher_->estimated_left_position);
+             drivetrain_status_fetcher_->estimated_left_position());
         const double right_error =
             (initial_drivetrain_.right -
-             drivetrain_status_fetcher_->estimated_right_position);
+             drivetrain_status_fetcher_->estimated_right_position());
 
         const double profile_distance_to_go =
             (left_profile_error + right_profile_error) / 2.0;
@@ -147,12 +158,12 @@
         const double distance_to_go = (left_error + right_error) / 2.0;
 
         // Check superstructure first.
-        if (superstructure_status_fetcher_->arm.current_node ==
+        if (superstructure_status_fetcher_->arm()->current_node() ==
                 arm_goal_position_ &&
-            superstructure_status_fetcher_->arm.path_distance_to_go <
+            superstructure_status_fetcher_->arm()->path_distance_to_go() <
                 arm_threshold) {
           AOS_LOG(INFO, "Arm finished first: %f, drivetrain %f distance\n",
-                  superstructure_status_fetcher_->arm.path_distance_to_go,
+                  superstructure_status_fetcher_->arm()->path_distance_to_go(),
                   ::std::abs(distance_to_go));
           return true;
         }
@@ -163,7 +174,7 @@
             ::std::abs(distance_to_go) < drive_threshold + kPositionTolerance) {
           AOS_LOG(INFO,
                   "Drivetrain finished first: arm %f, drivetrain %f distance\n",
-                  superstructure_status_fetcher_->arm.path_distance_to_go,
+                  superstructure_status_fetcher_->arm()->path_distance_to_go(),
                   ::std::abs(distance_to_go));
           return true;
         }
@@ -183,9 +194,9 @@
 
       superstructure_status_fetcher_.Fetch();
       if (superstructure_status_fetcher_.get()) {
-        if (superstructure_status_fetcher_->arm.current_node ==
+        if (superstructure_status_fetcher_->arm()->current_node() ==
                 arm_goal_position_ &&
-            superstructure_status_fetcher_->arm.path_distance_to_go <
+            superstructure_status_fetcher_->arm()->path_distance_to_go() <
                 threshold) {
           return true;
         }
@@ -205,7 +216,7 @@
 
       superstructure_status_fetcher_.Fetch();
       if (superstructure_status_fetcher_.get()) {
-        if (superstructure_status_fetcher_->arm.grab_state == 4) {
+        if (superstructure_status_fetcher_->arm()->grab_state() == 4) {
           return true;
         }
       }
diff --git a/y2018/actors/autonomous_actor_main.cc b/y2018/actors/autonomous_actor_main.cc
index 6193d48..76fae2e 100644
--- a/y2018/actors/autonomous_actor_main.cc
+++ b/y2018/actors/autonomous_actor_main.cc
@@ -1,14 +1,16 @@
 #include <stdio.h>
 
-#include "aos/events/shm-event-loop.h"
+#include "aos/events/shm_event_loop.h"
 #include "aos/init.h"
-#include "frc971/autonomous/auto.q.h"
 #include "y2018/actors/autonomous_actor.h"
 
 int main(int /*argc*/, char * /*argv*/ []) {
   ::aos::Init(-1);
 
-  ::aos::ShmEventLoop event_loop;
+  aos::FlatbufferDetachedBuffer<aos::Configuration> config =
+      aos::configuration::ReadConfig("config.json");
+
+  ::aos::ShmEventLoop event_loop(&config.message());
   ::y2018::actors::AutonomousActor autonomous(&event_loop);
   event_loop.Run();