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/actors/BUILD b/y2014/actors/BUILD
index 8612d0b..82255ab 100644
--- a/y2014/actors/BUILD
+++ b/y2014/actors/BUILD
@@ -1,5 +1,3 @@
-load("//aos/build:queues.bzl", "queue_library")
-
filegroup(
name = "binaries",
srcs = [
@@ -18,16 +16,6 @@
visibility = ["//visibility:public"],
)
-queue_library(
- name = "shoot_action_queue",
- srcs = [
- "shoot_action.q",
- ],
- deps = [
- "//aos/actions:action_queue",
- ],
-)
-
cc_library(
name = "shoot_action_lib",
srcs = [
@@ -38,14 +26,13 @@
],
visibility = ["//visibility:public"],
deps = [
- ":shoot_action_queue",
"//aos/actions:action_lib",
"//aos/logging",
- "//frc971/control_loops/drivetrain:drivetrain_queue",
"//y2014:constants",
- "//y2014/control_loops/claw:claw_queue",
- "//y2014/control_loops/shooter:shooter_queue",
- "//y2014/queues:profile_params",
+ "//y2014/control_loops/claw:claw_goal_fbs",
+ "//y2014/control_loops/claw:claw_status_fbs",
+ "//y2014/control_loops/shooter:shooter_goal_fbs",
+ "//y2014/control_loops/shooter:shooter_status_fbs",
],
)
@@ -56,9 +43,8 @@
],
deps = [
":shoot_action_lib",
- ":shoot_action_queue",
"//aos:init",
- "//aos/events:shm-event-loop",
+ "//aos/events:shm_event_loop",
],
)
@@ -72,19 +58,18 @@
],
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",
"//y2014/actors:shoot_action_lib",
- "//y2014/control_loops/claw:claw_queue",
+ "//y2014/control_loops/claw:claw_goal_fbs",
+ "//y2014/control_loops/claw:claw_status_fbs",
"//y2014/control_loops/drivetrain:drivetrain_base",
- "//y2014/control_loops/shooter:shooter_queue",
- "//y2014/queues:auto_mode",
- "//y2014/queues:hot_goal",
- "//y2014/queues:profile_params",
+ "//y2014/control_loops/shooter:shooter_goal_fbs",
+ "//y2014/queues:auto_mode_fbs",
+ "//y2014/queues:hot_goal_fbs",
],
)
@@ -96,7 +81,6 @@
deps = [
":autonomous_action_lib",
"//aos:init",
- "//aos/events:shm-event-loop",
- "//frc971/autonomous:auto_queue",
+ "//aos/events:shm_event_loop",
],
)
diff --git a/y2014/actors/autonomous_actor.cc b/y2014/actors/autonomous_actor.cc
index 4e2c9aa..7d1eb3f 100644
--- a/y2014/actors/autonomous_actor.cc
+++ b/y2014/actors/autonomous_actor.cc
@@ -7,18 +7,16 @@
#include "aos/actions/actions.h"
#include "aos/logging/logging.h"
-#include "aos/logging/queue_logging.h"
#include "aos/time/time.h"
#include "aos/util/phased_loop.h"
-#include "frc971/autonomous/auto.q.h"
-#include "frc971/control_loops/drivetrain/drivetrain.q.h"
#include "y2014/actors/shoot_actor.h"
#include "y2014/constants.h"
-#include "y2014/control_loops/claw/claw.q.h"
+#include "y2014/control_loops/claw/claw_goal_generated.h"
+#include "y2014/control_loops/claw/claw_status_generated.h"
#include "y2014/control_loops/drivetrain/drivetrain_base.h"
-#include "y2014/control_loops/shooter/shooter.q.h"
-#include "y2014/queues/auto_mode.q.h"
-#include "y2014/queues/hot_goal.q.h"
+#include "y2014/control_loops/shooter/shooter_goal_generated.h"
+#include "y2014/queues/auto_mode_generated.h"
+#include "y2014/queues/hot_goal_generated.h"
namespace y2014 {
namespace actors {
@@ -26,49 +24,50 @@
namespace chrono = ::std::chrono;
namespace this_thread = ::std::this_thread;
using ::aos::monotonic_clock;
-using ::frc971::ProfileParameters;
+using ::frc971::ProfileParametersT;
AutonomousActor::AutonomousActor(::aos::EventLoop *event_loop)
: frc971::autonomous::BaseAutonomousActor(
event_loop, control_loops::GetDrivetrainConfig()),
- auto_mode_fetcher_(event_loop->MakeFetcher<::y2014::sensors::AutoMode>(
- ".y2014.sensors.auto_mode")),
- hot_goal_fetcher_(
- event_loop->MakeFetcher<::y2014::HotGoal>(".y2014.hot_goal")),
+ auto_mode_fetcher_(
+ event_loop->MakeFetcher<::y2014::sensors::AutoMode>("/aos")),
+ hot_goal_fetcher_(event_loop->MakeFetcher<::y2014::HotGoal>("/")),
claw_goal_sender_(
- event_loop->MakeSender<::y2014::control_loops::ClawQueue::Goal>(
- ".y2014.control_loops.claw_queue.goal")),
+ event_loop->MakeSender<::y2014::control_loops::claw::Goal>("/claw")),
claw_goal_fetcher_(
- event_loop->MakeFetcher<::y2014::control_loops::ClawQueue::Goal>(
- ".y2014.control_loops.claw_queue.goal")),
+ event_loop->MakeFetcher<::y2014::control_loops::claw::Goal>("/claw")),
claw_status_fetcher_(
- event_loop->MakeFetcher<::y2014::control_loops::ClawQueue::Status>(
- ".y2014.control_loops.claw_queue.status")),
+ event_loop->MakeFetcher<::y2014::control_loops::claw::Status>(
+ "/claw")),
shooter_goal_sender_(
- event_loop->MakeSender<::y2014::control_loops::ShooterQueue::Goal>(
- ".y2014.control_loops.shooter_queue.goal")),
+ event_loop->MakeSender<::y2014::control_loops::shooter::Goal>(
+ "/shooter")),
shoot_action_factory_(actors::ShootActor::MakeFactory(event_loop)) {}
void AutonomousActor::PositionClawVertically(double intake_power,
double centering_power) {
- auto goal_message = claw_goal_sender_.MakeMessage();
- goal_message->bottom_angle = 0.0;
- goal_message->separation_angle = 0.0;
- goal_message->intake = intake_power;
- goal_message->centering = centering_power;
+ auto builder = claw_goal_sender_.MakeBuilder();
+ control_loops::claw::Goal::Builder goal_builder =
+ builder.MakeBuilder<control_loops::claw::Goal>();
+ goal_builder.add_bottom_angle(0.0);
+ goal_builder.add_separation_angle(0.0);
+ goal_builder.add_intake(intake_power);
+ goal_builder.add_centering(centering_power);
- if (!goal_message.Send()) {
+ if (!builder.Send(goal_builder.Finish())) {
AOS_LOG(WARNING, "sending claw goal failed\n");
}
}
void AutonomousActor::PositionClawBackIntake() {
- auto goal_message = claw_goal_sender_.MakeMessage();
- goal_message->bottom_angle = -2.273474;
- goal_message->separation_angle = 0.0;
- goal_message->intake = 12.0;
- goal_message->centering = 12.0;
- if (!goal_message.Send()) {
+ auto builder = claw_goal_sender_.MakeBuilder();
+ control_loops::claw::Goal::Builder goal_builder =
+ builder.MakeBuilder<control_loops::claw::Goal>();
+ goal_builder.add_bottom_angle(-2.273474);
+ goal_builder.add_separation_angle(0.0);
+ goal_builder.add_intake(12.0);
+ goal_builder.add_centering(12.0);
+ if (!builder.Send(goal_builder.Finish())) {
AOS_LOG(WARNING, "sending claw goal failed\n");
}
}
@@ -76,48 +75,63 @@
void AutonomousActor::PositionClawUpClosed() {
// Move the claw to where we're going to shoot from but keep it closed until
// it gets there.
- auto goal_message = claw_goal_sender_.MakeMessage();
- goal_message->bottom_angle = 0.86;
- goal_message->separation_angle = 0.0;
- goal_message->intake = 4.0;
- goal_message->centering = 1.0;
- if (!goal_message.Send()) {
+ auto builder = claw_goal_sender_.MakeBuilder();
+ control_loops::claw::Goal::Builder goal_builder =
+ builder.MakeBuilder<control_loops::claw::Goal>();
+ goal_builder.add_bottom_angle(0.86);
+ goal_builder.add_separation_angle(0.0);
+ goal_builder.add_intake(4.0);
+ goal_builder.add_centering(1.0);
+ if (!builder.Send(goal_builder.Finish())) {
AOS_LOG(WARNING, "sending claw goal failed\n");
}
}
void AutonomousActor::PositionClawForShot() {
- auto goal_message = claw_goal_sender_.MakeMessage();
- goal_message->bottom_angle = 0.86;
- goal_message->separation_angle = 0.10;
- goal_message->intake = 4.0;
- goal_message->centering = 1.0;
- if (!goal_message.Send()) {
+ auto builder = claw_goal_sender_.MakeBuilder();
+ control_loops::claw::Goal::Builder goal_builder =
+ builder.MakeBuilder<control_loops::claw::Goal>();
+ goal_builder.add_bottom_angle(0.86);
+ goal_builder.add_separation_angle(0.10);
+ goal_builder.add_intake(4.0);
+ goal_builder.add_centering(1.0);
+ if (!builder.Send(goal_builder.Finish())) {
AOS_LOG(WARNING, "sending claw goal failed\n");
}
}
void AutonomousActor::SetShotPower(double power) {
AOS_LOG(INFO, "Setting shot power to %f\n", power);
- auto goal_message = shooter_goal_sender_.MakeMessage();
- goal_message->shot_power = power;
- goal_message->shot_requested = false;
- goal_message->unload_requested = false;
- goal_message->load_requested = false;
- if (!goal_message.Send()) {
+ auto builder = shooter_goal_sender_.MakeBuilder();
+ control_loops::shooter::Goal::Builder goal_builder =
+ builder.MakeBuilder<control_loops::shooter::Goal>();
+ goal_builder.add_shot_power(power);
+ goal_builder.add_shot_requested(false);
+ goal_builder.add_unload_requested(false);
+ goal_builder.add_load_requested(false);
+ if (!builder.Send(goal_builder.Finish())) {
AOS_LOG(WARNING, "sending shooter goal failed\n");
}
}
-const ProfileParameters kFastDrive = {3.0, 2.5};
-const ProfileParameters kSlowDrive = {2.5, 2.5};
-const ProfileParameters kFastWithBallDrive = {3.0, 2.0};
-const ProfileParameters kSlowWithBallDrive = {2.5, 2.0};
-const ProfileParameters kFastTurn = {3.0, 10.0};
+ProfileParametersT MakeProfileParameters(float max_velocity,
+ float max_acceleration) {
+ ProfileParametersT result;
+ result.max_velocity = max_velocity;
+ result.max_acceleration = max_acceleration;
+ return result;
+}
+
+const ProfileParametersT kFastDrive = MakeProfileParameters(3.0, 2.5);
+const ProfileParametersT kSlowDrive = MakeProfileParameters(2.5, 2.5);
+const ProfileParametersT kFastWithBallDrive = MakeProfileParameters(3.0, 2.0);
+const ProfileParametersT kSlowWithBallDrive = MakeProfileParameters(2.5, 2.0);
+const ProfileParametersT kFastTurn = MakeProfileParameters(3.0, 10.0);
void AutonomousActor::Shoot() {
// Shoot.
- auto shoot_action = shoot_action_factory_.Make(0.0);
+ aos::common::actions::DoubleParamT param;
+ auto shoot_action = shoot_action_factory_.Make(param);
shoot_action->Start();
WaitUntilDoneOrCanceled(::std::move(shoot_action));
}
@@ -138,12 +152,12 @@
claw_goal_fetcher_.get() == nullptr) {
continue;
}
- bool ans = claw_status_fetcher_->zeroed &&
- (::std::abs(claw_status_fetcher_->bottom_velocity) < 1.0) &&
- (::std::abs(claw_status_fetcher_->bottom -
- claw_goal_fetcher_->bottom_angle) < 0.10) &&
- (::std::abs(claw_status_fetcher_->separation -
- claw_goal_fetcher_->separation_angle) < 0.4);
+ bool ans = claw_status_fetcher_->zeroed() &&
+ (::std::abs(claw_status_fetcher_->bottom_velocity()) < 1.0) &&
+ (::std::abs(claw_status_fetcher_->bottom() -
+ claw_goal_fetcher_->bottom_angle()) < 0.10) &&
+ (::std::abs(claw_status_fetcher_->separation() -
+ claw_goal_fetcher_->separation_angle()) < 0.4);
if (ans) {
return true;
}
@@ -160,8 +174,7 @@
void ResetCounts() {
hot_goal_fetcher_->Fetch();
if (hot_goal_fetcher_->get()) {
- start_counts_ = *hot_goal_fetcher_->get();
- AOS_LOG_STRUCT(INFO, "counts reset to", start_counts_);
+ hot_goal_fetcher_->get()->UnPackTo(&start_counts_);
start_counts_valid_ = true;
} else {
AOS_LOG(WARNING, "no hot goal message. ignoring\n");
@@ -169,30 +182,26 @@
}
}
- void Update() {
- hot_goal_fetcher_->Fetch();
- if (hot_goal_fetcher_->get())
- AOS_LOG_STRUCT(INFO, "new counts", *hot_goal_fetcher_->get());
- }
+ void Update() { hot_goal_fetcher_->Fetch(); }
bool left_triggered() const {
if (!start_counts_valid_ || !hot_goal_fetcher_->get()) return false;
- return (hot_goal_fetcher_->get()->left_count - start_counts_.left_count) >
+ return (hot_goal_fetcher_->get()->left_count() - start_counts_.left_count) >
kThreshold;
}
bool right_triggered() const {
if (!start_counts_valid_ || !hot_goal_fetcher_->get()) return false;
- return (hot_goal_fetcher_->get()->right_count - start_counts_.right_count) >
- kThreshold;
+ return (hot_goal_fetcher_->get()->right_count() -
+ start_counts_.right_count) > kThreshold;
}
bool is_left() const {
if (!start_counts_valid_ || !hot_goal_fetcher_->get()) return false;
const uint64_t left_difference =
- hot_goal_fetcher_->get()->left_count - start_counts_.left_count;
+ hot_goal_fetcher_->get()->left_count() - start_counts_.left_count;
const uint64_t right_difference =
- hot_goal_fetcher_->get()->right_count - start_counts_.right_count;
+ hot_goal_fetcher_->get()->right_count() - start_counts_.right_count;
if (left_difference > kThreshold) {
if (right_difference > kThreshold) {
// We've seen a lot of both, so pick the one we've seen the most of.
@@ -210,9 +219,9 @@
bool is_right() const {
if (!start_counts_valid_ || !hot_goal_fetcher_->get()) return false;
const uint64_t left_difference =
- hot_goal_fetcher_->get()->left_count - start_counts_.left_count;
+ hot_goal_fetcher_->get()->left_count() - start_counts_.left_count;
const uint64_t right_difference =
- hot_goal_fetcher_->get()->right_count - start_counts_.right_count;
+ hot_goal_fetcher_->get()->right_count() - start_counts_.right_count;
if (right_difference > kThreshold) {
if (left_difference > kThreshold) {
// We've seen a lot of both, so pick the one we've seen the most of.
@@ -230,14 +239,14 @@
private:
static const uint64_t kThreshold = 5;
- ::y2014::HotGoal start_counts_;
+ ::y2014::HotGoalT start_counts_;
bool start_counts_valid_;
::aos::Fetcher<::y2014::HotGoal> *hot_goal_fetcher_;
};
bool AutonomousActor::RunAction(
- const ::frc971::autonomous::AutonomousActionParams & /*params*/) {
+ const ::frc971::autonomous::AutonomousActionParams * /*params*/) {
enum class AutoVersion : uint8_t {
kStraight,
kDoubleHot,
@@ -261,9 +270,9 @@
static const double kSelectorMin = 0.2, kSelectorMax = 4.4;
const double kSelectorStep = (kSelectorMax - kSelectorMin) / 3.0;
- if (auto_mode_fetcher_->voltage < kSelectorStep + kSelectorMin) {
+ if (auto_mode_fetcher_->voltage() < kSelectorStep + kSelectorMin) {
auto_version = AutoVersion::kSingleHot;
- } else if (auto_mode_fetcher_->voltage < 2 * kSelectorStep + kSelectorMin) {
+ } else if (auto_mode_fetcher_->voltage() < 2 * kSelectorStep + kSelectorMin) {
auto_version = AutoVersion::kStraight;
} else {
auto_version = AutoVersion::kDoubleHot;
@@ -272,9 +281,9 @@
AOS_LOG(INFO, "running auto %" PRIu8 "\n",
static_cast<uint8_t>(auto_version));
- const ProfileParameters &drive_params =
+ const ProfileParametersT drive_params =
(auto_version == AutoVersion::kStraight) ? kFastDrive : kSlowDrive;
- const ProfileParameters &drive_with_ball_params =
+ const ProfileParametersT drive_with_ball_params =
(auto_version == AutoVersion::kStraight) ? kFastWithBallDrive
: kSlowWithBallDrive;
diff --git a/y2014/actors/autonomous_actor.h b/y2014/actors/autonomous_actor.h
index e832980..f1b06bf 100644
--- a/y2014/actors/autonomous_actor.h
+++ b/y2014/actors/autonomous_actor.h
@@ -7,12 +7,11 @@
#include "aos/actions/actions.h"
#include "aos/actions/actor.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 "y2014/actors/shoot_actor.h"
-#include "y2014/control_loops/shooter/shooter.q.h"
-#include "y2014/queues/auto_mode.q.h"
-#include "y2014/queues/hot_goal.q.h"
+#include "y2014/control_loops/shooter/shooter_goal_generated.h"
+#include "y2014/queues/auto_mode_generated.h"
+#include "y2014/queues/hot_goal_generated.h"
namespace y2014 {
namespace actors {
@@ -22,7 +21,7 @@
explicit AutonomousActor(::aos::EventLoop *event_loop);
bool RunAction(
- const ::frc971::autonomous::AutonomousActionParams ¶ms) override;
+ const ::frc971::autonomous::AutonomousActionParams *params) override;
private:
void Reset() {
@@ -41,12 +40,10 @@
::aos::Fetcher<::y2014::sensors::AutoMode> auto_mode_fetcher_;
::aos::Fetcher<::y2014::HotGoal> hot_goal_fetcher_;
- ::aos::Sender<::y2014::control_loops::ClawQueue::Goal> claw_goal_sender_;
- ::aos::Fetcher<::y2014::control_loops::ClawQueue::Goal> claw_goal_fetcher_;
- ::aos::Fetcher<::y2014::control_loops::ClawQueue::Status>
- claw_status_fetcher_;
- ::aos::Sender<::y2014::control_loops::ShooterQueue::Goal>
- shooter_goal_sender_;
+ ::aos::Sender<::y2014::control_loops::claw::Goal> claw_goal_sender_;
+ ::aos::Fetcher<::y2014::control_loops::claw::Goal> claw_goal_fetcher_;
+ ::aos::Fetcher<::y2014::control_loops::claw::Status> claw_status_fetcher_;
+ ::aos::Sender<::y2014::control_loops::shooter::Goal> shooter_goal_sender_;
actors::ShootActor::Factory shoot_action_factory_;
};
diff --git a/y2014/actors/autonomous_actor_main.cc b/y2014/actors/autonomous_actor_main.cc
index 817f0e4..44e10d0 100644
--- a/y2014/actors/autonomous_actor_main.cc
+++ b/y2014/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 "y2014/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());
::y2014::actors::AutonomousActor autonomous(&event_loop);
event_loop.Run();
diff --git a/y2014/actors/shoot_action.q b/y2014/actors/shoot_action.q
deleted file mode 100644
index 832153c..0000000
--- a/y2014/actors/shoot_action.q
+++ /dev/null
@@ -1,10 +0,0 @@
-package y2014.actors;
-
-import "aos/actions/actions.q";
-
-queue_group ShootActionQueueGroup {
- implements frc971.actions.ActionQueueGroup;
-
- queue aos.common.actions.Goal goal;
- queue aos.common.actions.Status status;
-};
diff --git a/y2014/actors/shoot_actor.cc b/y2014/actors/shoot_actor.cc
index 7fb4c05..58df186 100644
--- a/y2014/actors/shoot_actor.cc
+++ b/y2014/actors/shoot_actor.cc
@@ -4,10 +4,11 @@
#include "aos/logging/logging.h"
-#include "frc971/control_loops/drivetrain/drivetrain.q.h"
#include "y2014/constants.h"
-#include "y2014/control_loops/claw/claw.q.h"
-#include "y2014/control_loops/shooter/shooter.q.h"
+#include "y2014/control_loops/claw/claw_goal_generated.h"
+#include "y2014/control_loops/claw/claw_status_generated.h"
+#include "y2014/control_loops/shooter/shooter_goal_generated.h"
+#include "y2014/control_loops/shooter/shooter_status_generated.h"
namespace y2014 {
namespace actors {
@@ -17,26 +18,24 @@
constexpr double ShootActor::kClawShootingSeparationGoal;
ShootActor::ShootActor(::aos::EventLoop *event_loop)
- : ::aos::common::actions::ActorBase<actors::ShootActionQueueGroup>(
- event_loop, ".y2014.actors.shoot_action"),
+ : ::aos::common::actions::ActorBase<aos::common::actions::Goal>(
+ event_loop, "/shoot_action"),
claw_goal_fetcher_(
- event_loop->MakeFetcher<::y2014::control_loops::ClawQueue::Goal>(
- ".y2014.control_loops.claw_queue.goal")),
+ event_loop->MakeFetcher<::y2014::control_loops::claw::Goal>("/claw")),
claw_status_fetcher_(
- event_loop->MakeFetcher<::y2014::control_loops::ClawQueue::Status>(
- ".y2014.control_loops.claw_queue.status")),
+ event_loop->MakeFetcher<::y2014::control_loops::claw::Status>(
+ "/claw")),
claw_goal_sender_(
- event_loop->MakeSender<::y2014::control_loops::ClawQueue::Goal>(
- ".y2014.control_loops.claw_queue.goal")),
+ event_loop->MakeSender<::y2014::control_loops::claw::Goal>("/claw")),
shooter_status_fetcher_(
- event_loop->MakeFetcher<::y2014::control_loops::ShooterQueue::Status>(
- ".y2014.control_loops.shooter_queue.status")),
+ event_loop->MakeFetcher<::y2014::control_loops::shooter::Status>(
+ "/shooter")),
shooter_goal_fetcher_(
- event_loop->MakeFetcher<::y2014::control_loops::ShooterQueue::Goal>(
- ".y2014.control_loops.shooter_queue.goal")),
+ event_loop->MakeFetcher<::y2014::control_loops::shooter::Goal>(
+ "/shooter")),
shooter_goal_sender_(
- event_loop->MakeSender<::y2014::control_loops::ShooterQueue::Goal>(
- ".y2014.control_loops.shooter_queue.goal")) {}
+ event_loop->MakeSender<::y2014::control_loops::shooter::Goal>(
+ "/shooter")) {}
double ShootActor::SpeedToAngleOffset(double speed) {
const constants::Values &values = constants::GetValues();
@@ -52,14 +51,17 @@
// turn it off.
return true;
} else {
- auto goal_message = claw_goal_sender_.MakeMessage();
+ auto builder = claw_goal_sender_.MakeBuilder();
- goal_message->bottom_angle = claw_goal_fetcher_->bottom_angle;
- goal_message->separation_angle = claw_goal_fetcher_->separation_angle;
- goal_message->intake = 0.0;
- goal_message->centering = 0.0;
+ control_loops::claw::Goal::Builder claw_builder =
+ builder.MakeBuilder<control_loops::claw::Goal>();
- if (!goal_message.Send()) {
+ claw_builder.add_bottom_angle(claw_goal_fetcher_->bottom_angle());
+ claw_builder.add_separation_angle(claw_goal_fetcher_->separation_angle());
+ claw_builder.add_intake(0.0);
+ claw_builder.add_centering(0.0);
+
+ if (!builder.Send(claw_builder.Finish())) {
AOS_LOG(WARNING, "sending claw goal failed\n");
return false;
}
@@ -67,7 +69,7 @@
return true;
}
-bool ShootActor::RunAction(const double&) {
+bool ShootActor::RunAction(const aos::common::actions::DoubleParam *) {
InnerRunAction();
// Now do our 'finally' block and make sure that we aren't requesting shots
@@ -76,12 +78,15 @@
if (shooter_goal_fetcher_.get() == nullptr) {
return true;
}
- 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()) {
+ auto builder = shooter_goal_sender_.MakeBuilder();
+ control_loops::shooter::Goal::Builder shooter_builder =
+ builder.MakeBuilder<control_loops::shooter::Goal>();
+
+ shooter_builder.add_shot_power(shooter_goal_fetcher_->shot_power());
+ shooter_builder.add_shot_requested(false);
+ shooter_builder.add_unload_requested(false);
+ shooter_builder.add_load_requested(false);
+ if (!builder.Send(shooter_builder.Finish())) {
AOS_LOG(WARNING, "sending shooter goal failed\n");
return false;
}
@@ -104,16 +109,18 @@
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_ = shooter_status_fetcher_->shots;
+ previous_shots_ = shooter_status_fetcher_->shots();
// Shoot!
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()) {
+ auto builder = shooter_goal_sender_.MakeBuilder();
+ control_loops::shooter::Goal::Builder goal_builder =
+ builder.MakeBuilder<control_loops::shooter::Goal>();
+ goal_builder.add_shot_power(shooter_goal_fetcher_->shot_power());
+ goal_builder.add_shot_requested(true);
+ goal_builder.add_unload_requested(false);
+ goal_builder.add_load_requested(false);
+ if (!builder.Send(goal_builder.Finish())) {
AOS_LOG(WARNING, "sending shooter goal failed\n");
return;
}
@@ -128,20 +135,20 @@
bool ShootActor::ClawIsReady() {
claw_goal_fetcher_.Fetch();
- bool ans = claw_status_fetcher_->zeroed &&
- (::std::abs(claw_status_fetcher_->bottom_velocity) < 0.5) &&
- (::std::abs(claw_status_fetcher_->bottom -
- claw_goal_fetcher_->bottom_angle) < 0.10) &&
- (::std::abs(claw_status_fetcher_->separation -
- claw_goal_fetcher_->separation_angle) < 0.4);
+ bool ans = claw_status_fetcher_->zeroed() &&
+ (::std::abs(claw_status_fetcher_->bottom_velocity()) < 0.5) &&
+ (::std::abs(claw_status_fetcher_->bottom() -
+ claw_goal_fetcher_->bottom_angle()) < 0.10) &&
+ (::std::abs(claw_status_fetcher_->separation() -
+ claw_goal_fetcher_->separation_angle()) < 0.4);
AOS_LOG(DEBUG,
"Claw is %sready zeroed %d bottom_velocity %f bottom %f sep %f\n",
- ans ? "" : "not ", claw_status_fetcher_->zeroed,
- ::std::abs(claw_status_fetcher_->bottom_velocity),
- ::std::abs(claw_status_fetcher_->bottom -
- claw_goal_fetcher_->bottom_angle),
- ::std::abs(claw_status_fetcher_->separation -
- claw_goal_fetcher_->separation_angle));
+ ans ? "" : "not ", claw_status_fetcher_->zeroed(),
+ ::std::abs(claw_status_fetcher_->bottom_velocity()),
+ ::std::abs(claw_status_fetcher_->bottom() -
+ claw_goal_fetcher_->bottom_angle()),
+ ::std::abs(claw_status_fetcher_->separation() -
+ claw_goal_fetcher_->separation_angle()));
return ans;
}
@@ -149,14 +156,14 @@
shooter_goal_fetcher_.Fetch();
AOS_LOG(DEBUG, "Power error is %f - %f -> %f, ready %d\n",
- 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;
+ 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() {
@@ -174,7 +181,7 @@
bool ShootActor::DonePreShotOpen() {
claw_status_fetcher_.Fetch();
- if (claw_status_fetcher_->separation > kClawShootingSeparation) {
+ if (claw_status_fetcher_->separation() > kClawShootingSeparation) {
AOS_LOG(INFO, "Opened up enough to shoot.\n");
return true;
}
@@ -184,7 +191,7 @@
bool ShootActor::DoneShot() {
shooter_status_fetcher_.Fetch();
if (shooter_status_fetcher_.get() &&
- shooter_status_fetcher_->shots > previous_shots_) {
+ shooter_status_fetcher_->shots() > previous_shots_) {
AOS_LOG(INFO, "Shot succeeded!\n");
return true;
}
diff --git a/y2014/actors/shoot_actor.h b/y2014/actors/shoot_actor.h
index a4412ff..88a2358 100644
--- a/y2014/actors/shoot_actor.h
+++ b/y2014/actors/shoot_actor.h
@@ -5,29 +5,30 @@
#include "aos/actions/actions.h"
#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"
+#include "y2014/control_loops/claw/claw_goal_generated.h"
+#include "y2014/control_loops/claw/claw_status_generated.h"
+#include "y2014/control_loops/shooter/shooter_goal_generated.h"
+#include "y2014/control_loops/shooter/shooter_status_generated.h"
namespace y2014 {
namespace actors {
class ShootActor
- : public ::aos::common::actions::ActorBase<actors::ShootActionQueueGroup> {
+ : public ::aos::common::actions::ActorBase<aos::common::actions::Goal> {
public:
typedef ::aos::common::actions::TypedActionFactory<
- actors::ShootActionQueueGroup>
+ aos::common::actions::Goal>
Factory;
explicit ShootActor(::aos::EventLoop *event_loop);
static Factory MakeFactory(::aos::EventLoop *event_loop) {
- return Factory(event_loop, ".y2014.actors.shoot_action");
+ return Factory(event_loop, "/shoot_action");
}
// Actually execute the action of moving the claw and shooter into position
// and actually firing them.
- bool RunAction(const double ¶ms) override;
+ bool RunAction(const aos::common::actions::DoubleParam *params) override;
void InnerRunAction();
// calc an offset to our requested shot based on robot speed
@@ -50,16 +51,13 @@
bool ClawIsReady();
private:
- ::aos::Fetcher<::y2014::control_loops::ClawQueue::Goal> claw_goal_fetcher_;
- ::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>
+ ::aos::Fetcher<::y2014::control_loops::claw::Goal> claw_goal_fetcher_;
+ ::aos::Fetcher<::y2014::control_loops::claw::Status> claw_status_fetcher_;
+ ::aos::Sender<::y2014::control_loops::claw::Goal> claw_goal_sender_;
+ ::aos::Fetcher<::y2014::control_loops::shooter::Status>
shooter_status_fetcher_;
- ::aos::Fetcher<::y2014::control_loops::ShooterQueue::Goal>
- shooter_goal_fetcher_;
- ::aos::Sender<::y2014::control_loops::ShooterQueue::Goal>
- shooter_goal_sender_;
+ ::aos::Fetcher<::y2014::control_loops::shooter::Goal> shooter_goal_fetcher_;
+ ::aos::Sender<::y2014::control_loops::shooter::Goal> shooter_goal_sender_;
// to track when shot is complete
int previous_shots_;
diff --git a/y2014/actors/shoot_actor_main.cc b/y2014/actors/shoot_actor_main.cc
index 8575783..ef06915 100644
--- a/y2014/actors/shoot_actor_main.cc
+++ b/y2014/actors/shoot_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 "y2014/actors/shoot_action.q.h"
#include "y2014/actors/shoot_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());
::y2014::actors::ShootActor shoot(&event_loop);
event_loop.Run();