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/y2014_bot3/control_loops/drivetrain/BUILD b/y2014_bot3/control_loops/drivetrain/BUILD
index 18e0e90..7060ac1 100644
--- a/y2014_bot3/control_loops/drivetrain/BUILD
+++ b/y2014_bot3/control_loops/drivetrain/BUILD
@@ -1,7 +1,5 @@
package(default_visibility = ["//visibility:public"])
-load("//aos/build:queues.bzl", "queue_library")
-
genrule(
name = "genrule_drivetrain",
outs = [
@@ -77,7 +75,7 @@
deps = [
":drivetrain_base",
"//aos:init",
- "//aos/events:shm-event-loop",
+ "//aos/events:shm_event_loop",
"//frc971/control_loops/drivetrain:drivetrain_lib",
],
)
diff --git a/y2014_bot3/control_loops/drivetrain/drivetrain_main.cc b/y2014_bot3/control_loops/drivetrain/drivetrain_main.cc
index 48f09c5..05d09b3 100644
--- a/y2014_bot3/control_loops/drivetrain/drivetrain_main.cc
+++ b/y2014_bot3/control_loops/drivetrain/drivetrain_main.cc
@@ -1,6 +1,6 @@
#include "aos/init.h"
-#include "aos/events/shm-event-loop.h"
+#include "aos/events/shm_event_loop.h"
#include "frc971/control_loops/drivetrain/drivetrain.h"
#include "y2014_bot3/control_loops/drivetrain/drivetrain_base.h"
@@ -9,7 +9,10 @@
int main() {
::aos::InitNRT(true);
- ::aos::ShmEventLoop event_loop;
+ aos::FlatbufferDetachedBuffer<aos::Configuration> config =
+ aos::configuration::ReadConfig("config.json");
+
+ ::aos::ShmEventLoop event_loop(&config.message());
::frc971::control_loops::drivetrain::DeadReckonEkf localizer(
&event_loop,
::y2014_bot3::control_loops::drivetrain::GetDrivetrainConfig());
diff --git a/y2014_bot3/control_loops/rollers/BUILD b/y2014_bot3/control_loops/rollers/BUILD
index 9535489..e0d7dc6 100644
--- a/y2014_bot3/control_loops/rollers/BUILD
+++ b/y2014_bot3/control_loops/rollers/BUILD
@@ -1,16 +1,37 @@
package(default_visibility = ["//visibility:public"])
-load("//aos/build:queues.bzl", "queue_library")
+load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library")
-queue_library(
- name = "rollers_queue",
+flatbuffer_cc_library(
+ name = "rollers_goal_fbs",
srcs = [
- "rollers.q",
+ "rollers_goal.fbs",
],
- deps = [
- "//aos/controls:control_loop_queues",
- "//frc971/control_loops:queues",
+ gen_reflections = 1,
+)
+
+flatbuffer_cc_library(
+ name = "rollers_position_fbs",
+ srcs = [
+ "rollers_position.fbs",
],
+ gen_reflections = 1,
+)
+
+flatbuffer_cc_library(
+ name = "rollers_output_fbs",
+ srcs = [
+ "rollers_output.fbs",
+ ],
+ gen_reflections = 1,
+)
+
+flatbuffer_cc_library(
+ name = "rollers_status_fbs",
+ srcs = [
+ "rollers_status.fbs",
+ ],
+ gen_reflections = 1,
)
cc_library(
@@ -22,7 +43,10 @@
"rollers.h",
],
deps = [
- ":rollers_queue",
+ ":rollers_goal_fbs",
+ ":rollers_output_fbs",
+ ":rollers_position_fbs",
+ ":rollers_status_fbs",
"//aos/controls:control_loop",
"//aos/logging",
],
@@ -36,6 +60,6 @@
deps = [
":rollers_lib",
"//aos:init",
- "//aos/events:shm-event-loop",
+ "//aos/events:shm_event_loop",
],
)
diff --git a/y2014_bot3/control_loops/rollers/rollers.cc b/y2014_bot3/control_loops/rollers/rollers.cc
index d2b4da9..d62831a 100644
--- a/y2014_bot3/control_loops/rollers/rollers.cc
+++ b/y2014_bot3/control_loops/rollers/rollers.cc
@@ -1,46 +1,51 @@
#include "y2014_bot3/control_loops/rollers/rollers.h"
#include "aos/logging/logging.h"
+#include "y2014_bot3/control_loops/rollers/rollers_goal_generated.h"
+#include "y2014_bot3/control_loops/rollers/rollers_output_generated.h"
+#include "y2014_bot3/control_loops/rollers/rollers_position_generated.h"
+#include "y2014_bot3/control_loops/rollers/rollers_status_generated.h"
namespace y2014_bot3 {
namespace control_loops {
+namespace rollers {
Rollers::Rollers(::aos::EventLoop *event_loop, const ::std::string &name)
- : aos::controls::ControlLoop<control_loops::RollersQueue>(event_loop,
- name) {}
+ : aos::controls::ControlLoop<Goal, Position, Status, Output>(event_loop,
+ name) {}
-void Rollers::RunIteration(
- const control_loops::RollersQueue::Goal *goal,
- const control_loops::RollersQueue::Position * /*position*/,
- control_loops::RollersQueue::Output *output,
- control_loops::RollersQueue::Status * /*status*/) {
+void Rollers::RunIteration(const Goal *goal, const Position * /*position*/,
+ aos::Sender<Output>::Builder *output,
+ aos::Sender<Status>::Builder *status) {
constexpr double k2014Bot3IntakeForwardVoltage = 12.0;
constexpr double k2014Bot3IntakeBackwardVoltage = -12.0;
constexpr double k2014Bot3LowGoalForwardVoltage = 6.0;
constexpr double k2014Bot3LowGoalBackwardVoltage = -6.0;
+ status->Send(status->MakeBuilder<Status>().Finish());
+
if (!output || !goal) {
return;
}
- const int intake = goal->intake;
- const int low_spit = goal->low_spit;
- const bool human_player = goal->human_player;
+ const int intake = goal->intake();
+ const int low_spit = goal->low_spit();
+ const bool human_player = goal->human_player();
- output->Zero();
+ OutputT output_struct;
switch (low_spit) {
case 1:
// Spit towards front
- output->low_goal_voltage = k2014Bot3LowGoalBackwardVoltage;
- output->front_intake_voltage = k2014Bot3IntakeBackwardVoltage;
- output->back_intake_voltage = -k2014Bot3IntakeForwardVoltage;
+ output_struct.low_goal_voltage = k2014Bot3LowGoalBackwardVoltage;
+ output_struct.front_intake_voltage = k2014Bot3IntakeBackwardVoltage;
+ output_struct.back_intake_voltage = -k2014Bot3IntakeForwardVoltage;
break;
case -1:
// Spit towards back
- output->low_goal_voltage = k2014Bot3LowGoalForwardVoltage;
- output->back_intake_voltage = -k2014Bot3IntakeBackwardVoltage;
- output->front_intake_voltage = k2014Bot3IntakeForwardVoltage;
+ output_struct.low_goal_voltage = k2014Bot3LowGoalForwardVoltage;
+ output_struct.back_intake_voltage = -k2014Bot3IntakeBackwardVoltage;
+ output_struct.front_intake_voltage = k2014Bot3IntakeForwardVoltage;
break;
default:
// Stationary
@@ -50,17 +55,17 @@
switch (intake) {
case 1:
// Front intake.
- output->front_extended = true;
- output->back_extended = false;
- output->front_intake_voltage = k2014Bot3IntakeForwardVoltage;
- output->back_intake_voltage = 0.0;
+ output_struct.front_extended = true;
+ output_struct.back_extended = false;
+ output_struct.front_intake_voltage = k2014Bot3IntakeForwardVoltage;
+ output_struct.back_intake_voltage = 0.0;
break;
case -1:
// Back intake.
- output->back_extended = true;
- output->front_extended = false;
- output->back_intake_voltage = -k2014Bot3IntakeForwardVoltage;
- output->front_intake_voltage = 0.0;
+ output_struct.back_extended = true;
+ output_struct.front_extended = false;
+ output_struct.back_intake_voltage = -k2014Bot3IntakeForwardVoltage;
+ output_struct.front_intake_voltage = 0.0;
break;
default:
// Stationary
@@ -69,12 +74,15 @@
if (human_player) {
// Intake for human player.
- output->front_extended = false;
- output->back_extended = false;
- output->front_intake_voltage = k2014Bot3IntakeForwardVoltage;
- output->back_intake_voltage = -k2014Bot3IntakeForwardVoltage;
+ output_struct.front_extended = false;
+ output_struct.back_extended = false;
+ output_struct.front_intake_voltage = k2014Bot3IntakeForwardVoltage;
+ output_struct.back_intake_voltage = -k2014Bot3IntakeForwardVoltage;
}
+
+ output->Send(Output::Pack(*output->fbb(), &output_struct));
}
+} // namespace rollers
} // namespace control_loops
} // namespace y2014_bot3
diff --git a/y2014_bot3/control_loops/rollers/rollers.h b/y2014_bot3/control_loops/rollers/rollers.h
index 9890871..8903cd2 100644
--- a/y2014_bot3/control_loops/rollers/rollers.h
+++ b/y2014_bot3/control_loops/rollers/rollers.h
@@ -3,27 +3,31 @@
#include "aos/controls/control_loop.h"
-#include "y2014_bot3/control_loops/rollers/rollers.q.h"
+#include "y2014_bot3/control_loops/rollers/rollers_goal_generated.h"
+#include "y2014_bot3/control_loops/rollers/rollers_output_generated.h"
+#include "y2014_bot3/control_loops/rollers/rollers_position_generated.h"
+#include "y2014_bot3/control_loops/rollers/rollers_status_generated.h"
namespace y2014_bot3 {
namespace control_loops {
+namespace rollers {
-class Rollers : public aos::controls::ControlLoop<control_loops::RollersQueue> {
+class Rollers
+ : public aos::controls::ControlLoop<Goal, Position, Status, Output> {
public:
// Constructs a control loops which can take a rollers or defaults to the
// rollers at ::2014_bot3::control_loops::rollers.
- explicit Rollers(
- ::aos::EventLoop *event_loop,
- const ::std::string &name = ".y2014_bot3.control_loops.rollers_queue");
+ explicit Rollers(::aos::EventLoop *event_loop,
+ const ::std::string &name = "/rollers");
protected:
// Executes one cycle of the control loop.
- void RunIteration(const control_loops::RollersQueue::Goal *goal,
- const control_loops::RollersQueue::Position *position,
- control_loops::RollersQueue::Output *output,
- control_loops::RollersQueue::Status *status) override;
+ void RunIteration(const Goal *goal, const Position *position,
+ aos::Sender<Output>::Builder *output,
+ aos::Sender<Status>::Builder *status) override;
};
+} // namespace rollers
} // namespace control_loops
} // namespace y2014_bot3
diff --git a/y2014_bot3/control_loops/rollers/rollers.q b/y2014_bot3/control_loops/rollers/rollers.q
deleted file mode 100644
index 1e40369..0000000
--- a/y2014_bot3/control_loops/rollers/rollers.q
+++ /dev/null
@@ -1,40 +0,0 @@
-package y2014_bot3.control_loops;
-
-import "aos/controls/control_loops.q";
-import "frc971/control_loops/control_loops.q";
-
-// on ".y2014_bot3.control_loops.rollers_queue"
-queue_group RollersQueue {
- implements aos.control_loops.ControlLoop;
-
- message Goal {
- // -1 = back intake, 1 = front intake, all else = stationary.
- int16_t intake;
- // -1 = backwards, 1 = forwards, all else = stationary.
- int16_t low_spit;
- // Whether we want the human player load function.
- bool human_player;
- };
-
- message Position {};
-
- message Output {
- // Positive voltage = intaking, Negative = spitting.
- double front_intake_voltage;
- double back_intake_voltage;
- // Voltage for the low goal rollers.
- // Positive voltage = ball towards back, Negative = ball towards front.
- double low_goal_voltage;
-
- // Whether the front and back intake pistons are extended.
- bool front_extended;
- bool back_extended;
- };
-
- message Status {};
-
- queue Goal goal;
- queue Position position;
- queue Output output;
- queue Status status;
-};
diff --git a/y2014_bot3/control_loops/rollers/rollers_goal.fbs b/y2014_bot3/control_loops/rollers/rollers_goal.fbs
new file mode 100644
index 0000000..92ee589
--- /dev/null
+++ b/y2014_bot3/control_loops/rollers/rollers_goal.fbs
@@ -0,0 +1,12 @@
+namespace y2014_bot3.control_loops.rollers;
+
+table Goal {
+ // -1 = back intake, 1 = front intake, all else = stationary.
+ intake:int;
+ // -1 = backwards, 1 = forwards, all else = stationary.
+ low_spit:int;
+ // Whether we want the human player load function.
+ human_player:bool;
+}
+
+root_type Goal;
diff --git a/y2014_bot3/control_loops/rollers/rollers_main.cc b/y2014_bot3/control_loops/rollers/rollers_main.cc
index 1a0d82b..906c067 100644
--- a/y2014_bot3/control_loops/rollers/rollers_main.cc
+++ b/y2014_bot3/control_loops/rollers/rollers_main.cc
@@ -1,13 +1,16 @@
#include "y2014_bot3/control_loops/rollers/rollers.h"
-#include "aos/events/shm-event-loop.h"
+#include "aos/events/shm_event_loop.h"
#include "aos/init.h"
int main() {
::aos::InitNRT(true);
- ::aos::ShmEventLoop event_loop;
- ::y2014_bot3::control_loops::Rollers rollers(&event_loop);
+ aos::FlatbufferDetachedBuffer<aos::Configuration> config =
+ aos::configuration::ReadConfig("config.json");
+
+ ::aos::ShmEventLoop event_loop(&config.message());
+ ::y2014_bot3::control_loops::rollers::Rollers rollers(&event_loop);
event_loop.Run();
diff --git a/y2014_bot3/control_loops/rollers/rollers_output.fbs b/y2014_bot3/control_loops/rollers/rollers_output.fbs
new file mode 100644
index 0000000..daae09b
--- /dev/null
+++ b/y2014_bot3/control_loops/rollers/rollers_output.fbs
@@ -0,0 +1,16 @@
+namespace y2014_bot3.control_loops.rollers;
+
+table Output {
+ // Positive voltage = intaking, Negative = spitting.
+ front_intake_voltage:double;
+ back_intake_voltage:double;
+ // Voltage for the low goal rollers.
+ // Positive voltage = ball towards back, Negative = ball towards front.
+ low_goal_voltage:double;
+
+ // Whether the front and back intake pistons are extended.
+ front_extended:bool;
+ back_extended:bool;
+}
+
+root_type Output;
diff --git a/y2014_bot3/control_loops/rollers/rollers_position.fbs b/y2014_bot3/control_loops/rollers/rollers_position.fbs
new file mode 100644
index 0000000..040502c
--- /dev/null
+++ b/y2014_bot3/control_loops/rollers/rollers_position.fbs
@@ -0,0 +1,6 @@
+namespace y2014_bot3.control_loops.rollers;
+
+table Position {
+}
+
+root_type Position;
diff --git a/y2014_bot3/control_loops/rollers/rollers_status.fbs b/y2014_bot3/control_loops/rollers/rollers_status.fbs
new file mode 100644
index 0000000..2486bb7
--- /dev/null
+++ b/y2014_bot3/control_loops/rollers/rollers_status.fbs
@@ -0,0 +1,6 @@
+namespace y2014_bot3.control_loops.rollers;
+
+table Status {
+}
+
+root_type Status;