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/y2017/control_loops/superstructure/shooter/BUILD b/y2017/control_loops/superstructure/shooter/BUILD
index cb7fa54..d83e34b 100644
--- a/y2017/control_loops/superstructure/shooter/BUILD
+++ b/y2017/control_loops/superstructure/shooter/BUILD
@@ -1,49 +1,53 @@
-package(default_visibility = ['//visibility:public'])
+package(default_visibility = ["//visibility:public"])
genrule(
- name = 'genrule_shooter',
- cmd = '$(location //y2017/control_loops/python:shooter) $(OUTS)',
- tools = [
- '//y2017/control_loops/python:shooter',
- ],
- outs = [
- 'shooter_plant.h',
- 'shooter_plant.cc',
- 'shooter_integral_plant.h',
- 'shooter_integral_plant.cc',
- ],
+ name = "genrule_shooter",
+ outs = [
+ "shooter_plant.h",
+ "shooter_plant.cc",
+ "shooter_integral_plant.h",
+ "shooter_integral_plant.cc",
+ ],
+ cmd = "$(location //y2017/control_loops/python:shooter) $(OUTS)",
+ tools = [
+ "//y2017/control_loops/python:shooter",
+ ],
)
cc_library(
- name = 'shooter_plants',
- visibility = ['//visibility:public'],
- srcs = [
- 'shooter_plant.cc',
- 'shooter_integral_plant.cc',
- ],
- hdrs = [
- 'shooter_plant.h',
- 'shooter_integral_plant.h',
- ],
- deps = [
- '//frc971/control_loops:hybrid_state_feedback_loop',
- '//frc971/control_loops:state_feedback_loop',
- ],
+ name = "shooter_plants",
+ srcs = [
+ "shooter_integral_plant.cc",
+ "shooter_plant.cc",
+ ],
+ hdrs = [
+ "shooter_integral_plant.h",
+ "shooter_plant.h",
+ ],
+ visibility = ["//visibility:public"],
+ deps = [
+ "//frc971/control_loops:hybrid_state_feedback_loop",
+ "//frc971/control_loops:state_feedback_loop",
+ ],
)
cc_library(
- name = 'shooter',
- visibility = ['//visibility:public'],
- srcs = [
- 'shooter.cc',
- ],
- hdrs = [
- 'shooter.h',
- ],
- deps = [
- ':shooter_plants',
- '//aos/controls:control_loop',
- '//third_party/eigen',
- '//y2017/control_loops/superstructure:superstructure_queue',
- ],
+ name = "shooter",
+ srcs = [
+ "shooter.cc",
+ ],
+ hdrs = [
+ "shooter.h",
+ ],
+ visibility = ["//visibility:public"],
+ deps = [
+ ":shooter_plants",
+ "//aos/controls:control_loop",
+ "//frc971/control_loops:control_loops_fbs",
+ "//frc971/control_loops:profiled_subsystem_fbs",
+ "//y2017/control_loops/superstructure:superstructure_goal_fbs",
+ "//y2017/control_loops/superstructure:superstructure_position_fbs",
+ "//y2017/control_loops/superstructure:superstructure_status_fbs",
+ "@org_tuxfamily_eigen//:eigen",
+ ],
)
diff --git a/y2017/control_loops/superstructure/shooter/shooter.cc b/y2017/control_loops/superstructure/shooter/shooter.cc
index 2b668ae..0ea4836 100644
--- a/y2017/control_loops/superstructure/shooter/shooter.cc
+++ b/y2017/control_loops/superstructure/shooter/shooter.cc
@@ -2,11 +2,7 @@
#include <chrono>
-#include "aos/controls/control_loops.q.h"
#include "aos/logging/logging.h"
-#include "aos/logging/queue_logging.h"
-
-#include "y2017/control_loops/superstructure/shooter/shooter.h"
namespace y2017 {
namespace control_loops {
@@ -104,31 +100,35 @@
loop_->Update(disabled, dt);
}
-void ShooterController::SetStatus(ShooterStatus *status) {
- status->avg_angular_velocity = average_angular_velocity_;
+flatbuffers::Offset<ShooterStatus> ShooterController::BuildStatus(
+ flatbuffers::FlatBufferBuilder *fbb) {
+ ShooterStatus::Builder status_builder(*fbb);
+ status_builder.add_avg_angular_velocity(average_angular_velocity_);
- status->filtered_velocity = X_hat_current_(1, 0);
- status->angular_velocity = X_hat_current_(2, 0);
- status->ready = ready_;
+ status_builder.add_filtered_velocity(X_hat_current_(1, 0));
+ status_builder.add_angular_velocity(X_hat_current_(2, 0));
+ status_builder.add_ready(ready_);
- status->voltage_error = X_hat_current_(3, 0);
- status->position_error = position_error_;
- status->instantaneous_velocity = dt_velocity_;
- status->fixed_instantaneous_velocity = fixed_dt_velocity_;
+ status_builder.add_voltage_error(X_hat_current_(3, 0));
+ status_builder.add_position_error(position_error_);
+ status_builder.add_instantaneous_velocity(dt_velocity_);
+ status_builder.add_fixed_instantaneous_velocity(fixed_dt_velocity_);
+
+ return status_builder.Finish();
}
void Shooter::Reset() { wheel_.Reset(); }
-void Shooter::Iterate(const control_loops::ShooterGoal *goal,
- const double *position,
- ::aos::monotonic_clock::time_point position_time,
- double *output, control_loops::ShooterStatus *status) {
+flatbuffers::Offset<ShooterStatus> Shooter::Iterate(
+ const ShooterGoalT *goal, const double position,
+ ::aos::monotonic_clock::time_point position_time, double *output,
+ flatbuffers::FlatBufferBuilder *fbb) {
if (goal) {
// Update position/goal for our wheel.
wheel_.set_goal(goal->angular_velocity);
}
- wheel_.set_position(*position);
+ wheel_.set_position(position);
chrono::nanoseconds dt = ::aos::controls::kLoopFrequency;
if (last_time_ != ::aos::monotonic_clock::min_time) {
@@ -138,20 +138,22 @@
wheel_.Update(output == nullptr, dt);
- wheel_.SetStatus(status);
+ flatbuffers::Offset<ShooterStatus> status_offset = wheel_.BuildStatus(fbb);
- if (last_ready_ && !status->ready) {
+ if (last_ready_ && !wheel_.ready()) {
min_ = wheel_.dt_velocity();
- } else if (!status->ready) {
+ } else if (!wheel_.ready()) {
min_ = ::std::min(min_, wheel_.dt_velocity());
- } else if (!last_ready_ && status->ready) {
+ } else if (!last_ready_ && wheel_.ready()) {
AOS_LOG(INFO, "Shot min was [%f]\n", min_);
}
if (output) {
*output = wheel_.voltage();
}
- last_ready_ = status->ready;
+ last_ready_ = wheel_.ready();
+
+ return status_offset;
}
} // namespace shooter
diff --git a/y2017/control_loops/superstructure/shooter/shooter.h b/y2017/control_loops/superstructure/shooter/shooter.h
index e8f7789..19fc7dd 100644
--- a/y2017/control_loops/superstructure/shooter/shooter.h
+++ b/y2017/control_loops/superstructure/shooter/shooter.h
@@ -7,10 +7,11 @@
#include "aos/controls/control_loop.h"
#include "aos/time/time.h"
#include "frc971/control_loops/state_feedback_loop.h"
-#include "third_party/eigen/Eigen/Dense"
+#include "Eigen/Dense"
#include "y2017/control_loops/superstructure/shooter/shooter_integral_plant.h"
-#include "y2017/control_loops/superstructure/superstructure.q.h"
+#include "y2017/control_loops/superstructure/superstructure_goal_generated.h"
+#include "y2017/control_loops/superstructure/superstructure_status_generated.h"
namespace y2017 {
namespace control_loops {
@@ -27,7 +28,8 @@
void set_position(double current_position);
// Populates the status structure.
- void SetStatus(control_loops::ShooterStatus *status);
+ flatbuffers::Offset<ShooterStatus> BuildStatus(
+ flatbuffers::FlatBufferBuilder *fbb);
// Returns the control loop calculated voltage.
double voltage() const;
@@ -46,6 +48,8 @@
// Resets the kalman filter and any other internal state.
void Reset();
+ bool ready() { return ready_; }
+
private:
// The current sensor measurement.
Eigen::Matrix<double, 1, 1> Y_;
@@ -86,9 +90,10 @@
// Iterates the shooter control loop one cycle. position and status must
// never be nullptr. goal can be nullptr if no goal exists, and output should
// be nullptr if disabled.
- void Iterate(const control_loops::ShooterGoal *goal, const double *position,
- ::aos::monotonic_clock::time_point position_time, double *output,
- control_loops::ShooterStatus *status);
+ flatbuffers::Offset<ShooterStatus> Iterate(
+ const ShooterGoalT *goal, const double position,
+ ::aos::monotonic_clock::time_point position_time, double *output,
+ flatbuffers::FlatBufferBuilder *fbb);
// Sets the shooter up to reset the kalman filter next time Iterate is called.
void Reset();