Remove global .y2014.control_loops.shooter_queue object
Change-Id: I5e4d4245d8904eaf50ddccf421784bdc4728eb11
diff --git a/y2014/actors/shoot_actor.cc b/y2014/actors/shoot_actor.cc
index 4a57943..736632d 100644
--- a/y2014/actors/shoot_actor.cc
+++ b/y2014/actors/shoot_actor.cc
@@ -27,7 +27,16 @@
".y2014.control_loops.claw_queue.status")),
claw_goal_sender_(
event_loop->MakeSender<::y2014::control_loops::ClawQueue::Goal>(
- ".y2014.control_loops.claw_queue.goal")) {}
+ ".y2014.control_loops.claw_queue.goal")),
+ shooter_status_fetcher_(
+ event_loop->MakeFetcher<::y2014::control_loops::ShooterQueue::Status>(
+ ".y2014.control_loops.shooter_queue.status")),
+ shooter_goal_fetcher_(
+ event_loop->MakeFetcher<::y2014::control_loops::ShooterQueue::Goal>(
+ ".y2014.control_loops.shooter_queue.goal")),
+ shooter_goal_sender_(
+ event_loop->MakeSender<::y2014::control_loops::ShooterQueue::Goal>(
+ ".y2014.control_loops.shooter_queue.goal")) {}
double ShootActor::SpeedToAngleOffset(double speed) {
const constants::Values &values = constants::GetValues();
@@ -63,16 +72,16 @@
// Now do our 'finally' block and make sure that we aren't requesting shots
// continually.
- control_loops::shooter_queue.goal.FetchLatest();
- if (control_loops::shooter_queue.goal.get() == nullptr) {
+ shooter_goal_fetcher_.Fetch();
+ if (shooter_goal_fetcher_.get() == nullptr) {
return true;
}
- if (!control_loops::shooter_queue.goal.MakeWithBuilder()
- .shot_power(control_loops::shooter_queue.goal->shot_power)
- .shot_requested(false)
- .unload_requested(false)
- .load_requested(false)
- .Send()) {
+ 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()) {
LOG(WARNING, "sending shooter goal failed\n");
return false;
}
@@ -92,19 +101,22 @@
if (!IntakeOff()) return;
// Make sure that we have the latest shooter status.
- control_loops::shooter_queue.status.FetchLatest();
+ 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_ = control_loops::shooter_queue.status->shots;
+ previous_shots_ = shooter_status_fetcher_->shots;
// Shoot!
- if (!control_loops::shooter_queue.goal.MakeWithBuilder()
- .shot_power(control_loops::shooter_queue.goal->shot_power)
- .shot_requested(true)
- .unload_requested(false)
- .load_requested(false)
- .Send()) {
- LOG(WARNING, "sending shooter goal failed\n");
- return;
+ 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()) {
+ LOG(WARNING, "sending shooter goal failed\n");
+ return;
+ }
}
// wait for record of shot having been fired
@@ -132,22 +144,22 @@
return ans;
}
-bool ShooterIsReady() {
- control_loops::shooter_queue.goal.FetchLatest();
+bool ShootActor::ShooterIsReady() {
+ shooter_goal_fetcher_.Fetch();
LOG(DEBUG, "Power error is %f - %f -> %f, ready %d\n",
- control_loops::shooter_queue.status->hard_stop_power,
- control_loops::shooter_queue.goal->shot_power,
- ::std::abs(control_loops::shooter_queue.status->hard_stop_power -
- control_loops::shooter_queue.goal->shot_power),
- control_loops::shooter_queue.status->ready);
- return (::std::abs(control_loops::shooter_queue.status->hard_stop_power -
- control_loops::shooter_queue.goal->shot_power) < 1.0) &&
- control_loops::shooter_queue.status->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() {
- control_loops::shooter_queue.status.FetchAnother();
+ shooter_status_fetcher_.Fetch();
claw_status_fetcher_.Fetch();
// Make sure that both the shooter and claw have reached the necessary
// states.
@@ -169,8 +181,9 @@
}
bool ShootActor::DoneShot() {
- control_loops::shooter_queue.status.FetchAnother();
- if (control_loops::shooter_queue.status->shots > previous_shots_) {
+ shooter_status_fetcher_.Fetch();
+ if (shooter_status_fetcher_.get() &&
+ shooter_status_fetcher_->shots > previous_shots_) {
LOG(INFO, "Shot succeeded!\n");
return true;
}
diff --git a/y2014/actors/shoot_actor.h b/y2014/actors/shoot_actor.h
index 33a284c..a4412ff 100644
--- a/y2014/actors/shoot_actor.h
+++ b/y2014/actors/shoot_actor.h
@@ -7,6 +7,7 @@
#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"
namespace y2014 {
namespace actors {
@@ -43,6 +44,7 @@
bool DonePreShotOpen();
// in the right place
bool DoneSetupShot();
+ bool ShooterIsReady();
bool IntakeOff();
bool ClawIsReady();
@@ -52,6 +54,12 @@
::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>
+ shooter_status_fetcher_;
+ ::aos::Fetcher<::y2014::control_loops::ShooterQueue::Goal>
+ shooter_goal_fetcher_;
+ ::aos::Sender<::y2014::control_loops::ShooterQueue::Goal>
+ shooter_goal_sender_;
// to track when shot is complete
int previous_shots_;