Convert control_loops::shooter::shooter_queue to event loops.
Change-Id: Ie11efa85250288b7f7d64ba7ace6ae6bb92a0a90
diff --git a/y2016/actors/autonomous_actor.cc b/y2016/actors/autonomous_actor.cc
index f486d38..f2a779a 100644
--- a/y2016/actors/autonomous_actor.cc
+++ b/y2016/actors/autonomous_actor.cc
@@ -55,7 +55,15 @@
".y2016.vision.vision_status")),
ball_detector_fetcher_(
event_loop->MakeFetcher<::y2016::sensors::BallDetector>(
- ".y2016.sensors.ball_detector")) {}
+ ".y2016.sensors.ball_detector")),
+ shooter_goal_sender_(
+ event_loop
+ ->MakeSender<::y2016::control_loops::shooter::ShooterQueue::Goal>(
+ ".y2016.control_loops.shooter.shooter_queue.goal")),
+ shooter_status_fetcher_(
+ event_loop->MakeFetcher<
+ ::y2016::control_loops::shooter::ShooterQueue::Status>(
+ ".y2016.control_loops.shooter.shooter_queue.status")) {}
constexpr double kDoNotTurnCare = 2.0;
@@ -104,12 +112,12 @@
void AutonomousActor::OpenShooter() {
shooter_speed_ = 0.0;
- if (!control_loops::shooter::shooter_queue.goal.MakeWithBuilder()
- .angular_velocity(shooter_speed_)
- .clamp_open(true)
- .push_to_shooter(false)
- .force_lights_on(false)
- .Send()) {
+ auto shooter_goal = shooter_goal_sender_.MakeMessage();
+ shooter_goal->angular_velocity = shooter_speed_;
+ shooter_goal->clamp_open = true;
+ shooter_goal->push_to_shooter = false;
+ shooter_goal->force_lights_on = false;
+ if (!shooter_goal.Send()) {
LOG(ERROR, "Sending shooter goal failed.\n");
}
}
@@ -117,12 +125,13 @@
void AutonomousActor::CloseShooter() {
shooter_speed_ = 0.0;
- if (!control_loops::shooter::shooter_queue.goal.MakeWithBuilder()
- .angular_velocity(shooter_speed_)
- .clamp_open(false)
- .push_to_shooter(false)
- .force_lights_on(false)
- .Send()) {
+ auto shooter_goal = shooter_goal_sender_.MakeMessage();
+ shooter_goal->angular_velocity = shooter_speed_;
+ shooter_goal->clamp_open = false;
+ shooter_goal->push_to_shooter = false;
+ shooter_goal->force_lights_on = false;
+
+ if (!shooter_goal.Send()) {
LOG(ERROR, "Sending shooter goal failed.\n");
}
}
@@ -134,12 +143,13 @@
// hope of a human aligning the robot.
bool force_lights_on = shooter_speed_ > 1.0;
- if (!control_loops::shooter::shooter_queue.goal.MakeWithBuilder()
- .angular_velocity(shooter_speed_)
- .clamp_open(false)
- .push_to_shooter(false)
- .force_lights_on(force_lights_on)
- .Send()) {
+ auto shooter_goal = shooter_goal_sender_.MakeMessage();
+ shooter_goal->angular_velocity = shooter_speed_;
+ shooter_goal->clamp_open = false;
+ shooter_goal->push_to_shooter = false;
+ shooter_goal->force_lights_on = force_lights_on;
+
+ if (!shooter_goal.Send()) {
LOG(ERROR, "Sending shooter goal failed.\n");
}
}
@@ -147,21 +157,22 @@
void AutonomousActor::Shoot() {
uint32_t initial_shots = 0;
- control_loops::shooter::shooter_queue.status.FetchLatest();
- if (control_loops::shooter::shooter_queue.status.get()) {
- initial_shots = control_loops::shooter::shooter_queue.status->shots;
+ shooter_status_fetcher_.Fetch();
+ if (shooter_status_fetcher_.get()) {
+ initial_shots = shooter_status_fetcher_->shots;
}
// In auto, we want to have the lights on whenever possible since we have no
// hope of a human aligning the robot.
bool force_lights_on = shooter_speed_ > 1.0;
- if (!control_loops::shooter::shooter_queue.goal.MakeWithBuilder()
- .angular_velocity(shooter_speed_)
- .clamp_open(false)
- .push_to_shooter(true)
- .force_lights_on(force_lights_on)
- .Send()) {
+ auto shooter_goal = shooter_goal_sender_.MakeMessage();
+ shooter_goal->angular_velocity = shooter_speed_;
+ shooter_goal->clamp_open = false;
+ shooter_goal->push_to_shooter = true;
+ shooter_goal->force_lights_on = force_lights_on;
+
+ if (!shooter_goal.Send()) {
LOG(ERROR, "Sending shooter goal failed.\n");
}
@@ -172,9 +183,9 @@
if (ShouldCancel()) return;
// Wait for the shot count to change so we know when the shot is complete.
- control_loops::shooter::shooter_queue.status.FetchLatest();
- if (control_loops::shooter::shooter_queue.status.get()) {
- if (initial_shots < control_loops::shooter::shooter_queue.status->shots) {
+ shooter_status_fetcher_.Fetch();
+ if (shooter_status_fetcher_.get()) {
+ if (initial_shots < shooter_status_fetcher_->shots) {
return;
}
}
@@ -189,10 +200,10 @@
while (true) {
if (ShouldCancel()) return;
- control_loops::shooter::shooter_queue.status.FetchLatest();
- if (control_loops::shooter::shooter_queue.status.get()) {
- if (control_loops::shooter::shooter_queue.status->left.ready &&
- control_loops::shooter::shooter_queue.status->right.ready) {
+ shooter_status_fetcher_.Fetch();
+ if (shooter_status_fetcher_.get()) {
+ if (shooter_status_fetcher_->left.ready &&
+ shooter_status_fetcher_->right.ready) {
return;
}
}
diff --git a/y2016/actors/autonomous_actor.h b/y2016/actors/autonomous_actor.h
index 22d963d..c4ec7f0 100644
--- a/y2016/actors/autonomous_actor.h
+++ b/y2016/actors/autonomous_actor.h
@@ -11,6 +11,7 @@
#include "frc971/control_loops/drivetrain/drivetrain.q.h"
#include "frc971/control_loops/drivetrain/drivetrain_config.h"
#include "y2016/actors/vision_align_actor.h"
+#include "y2016/control_loops/shooter/shooter.q.h"
#include "y2016/queues/ball_detector.q.h"
namespace y2016 {
@@ -89,6 +90,10 @@
::aos::Fetcher<::y2016::vision::VisionStatus> vision_status_fetcher_;
::aos::Fetcher<::y2016::sensors::BallDetector> ball_detector_fetcher_;
+ ::aos::Sender<::y2016::control_loops::shooter::ShooterQueue::Goal>
+ shooter_goal_sender_;
+ ::aos::Fetcher<::y2016::control_loops::shooter::ShooterQueue::Status>
+ shooter_status_fetcher_;
};
} // namespace actors