Remove global .y2017.control_loops.superstructure_queue object
Change-Id: I9810de1f3dd79d580b71f0c7927b8c6bbd2765d7
diff --git a/y2017/actors/autonomous_actor.cc b/y2017/actors/autonomous_actor.cc
index b263139..9b7855c 100644
--- a/y2017/actors/autonomous_actor.cc
+++ b/y2017/actors/autonomous_actor.cc
@@ -37,7 +37,15 @@
AutonomousActor::AutonomousActor(::aos::EventLoop *event_loop)
: frc971::autonomous::BaseAutonomousActor(
- event_loop, control_loops::drivetrain::GetDrivetrainConfig()) {}
+ event_loop, control_loops::drivetrain::GetDrivetrainConfig()),
+ superstructure_status_fetcher_(
+ event_loop->MakeFetcher<
+ ::y2017::control_loops::SuperstructureQueue::Status>(
+ ".y2017.control_loops.superstructure_queue.status")),
+ superstructure_goal_sender_(
+ event_loop
+ ->MakeSender<::y2017::control_loops::SuperstructureQueue::Goal>(
+ ".y2017.control_loops.superstructure_queue.goal")) {}
bool AutonomousActor::RunAction(
const ::frc971::autonomous::AutonomousActionParams ¶ms) {
diff --git a/y2017/actors/autonomous_actor.h b/y2017/actors/autonomous_actor.h
index ac79eb9..c10b003 100644
--- a/y2017/actors/autonomous_actor.h
+++ b/y2017/actors/autonomous_actor.h
@@ -15,8 +15,6 @@
namespace actors {
using ::frc971::ProfileParameters;
-using ::y2017::control_loops::superstructure_queue;
-
class AutonomousActor : public ::frc971::autonomous::BaseAutonomousActor {
public:
explicit AutonomousActor(::aos::EventLoop *event_loop);
@@ -40,6 +38,11 @@
SendSuperstructureGoal();
}
+ ::aos::Fetcher<::y2017::control_loops::SuperstructureQueue::Status>
+ superstructure_status_fetcher_;
+ ::aos::Sender<::y2017::control_loops::SuperstructureQueue::Goal>
+ superstructure_goal_sender_;
+
double intake_goal_ = 0.0;
double turret_goal_ = 0.0;
bool vision_track_ = false;
@@ -77,9 +80,9 @@
while (true) {
if (ShouldCancel()) return;
- superstructure_queue.status.FetchLatest();
- if (superstructure_queue.status.get()) {
- if (superstructure_queue.status->hood.zeroed) {
+ superstructure_status_fetcher_.Fetch();
+ if (superstructure_status_fetcher_.get()) {
+ if (superstructure_status_fetcher_->hood.zeroed) {
return;
}
}
@@ -88,7 +91,7 @@
}
void SendSuperstructureGoal() {
- auto new_superstructure_goal = superstructure_queue.goal.MakeMessage();
+ auto new_superstructure_goal = superstructure_goal_sender_.MakeMessage();
new_superstructure_goal->intake.distance = intake_goal_;
new_superstructure_goal->intake.disable_intake = false;
new_superstructure_goal->turret.angle = turret_goal_;
diff --git a/y2017/control_loops/superstructure/superstructure.q b/y2017/control_loops/superstructure/superstructure.q
index 5c0771c..6ea2fa2 100644
--- a/y2017/control_loops/superstructure/superstructure.q
+++ b/y2017/control_loops/superstructure/superstructure.q
@@ -179,6 +179,7 @@
double turret_encoder_angle;
};
+// Published on ".y2017.control_loops.superstructure_queue"
queue_group SuperstructureQueue {
implements aos.control_loops.ControlLoop;
@@ -255,5 +256,3 @@
queue Output output;
queue Status status;
};
-
-queue_group SuperstructureQueue superstructure_queue;
diff --git a/y2017/joystick_reader.cc b/y2017/joystick_reader.cc
index 894d1da..10bf20d 100644
--- a/y2017/joystick_reader.cc
+++ b/y2017/joystick_reader.cc
@@ -19,7 +19,6 @@
#include "y2017/control_loops/drivetrain/drivetrain_base.h"
using ::frc971::control_loops::drivetrain_queue;
-using ::y2017::control_loops::superstructure_queue;
using ::aos::input::driver_station::ButtonLocation;
using ::aos::input::driver_station::ControlBit;
@@ -55,20 +54,26 @@
: ::aos::input::ActionJoystickInput(
event_loop,
::y2017::control_loops::drivetrain::GetDrivetrainConfig(),
- DrivetrainInputReader::InputType::kSteeringWheel, {}) {}
+ DrivetrainInputReader::InputType::kSteeringWheel, {}),
+ superstructure_status_fetcher_(
+ event_loop->MakeFetcher<
+ ::y2017::control_loops::SuperstructureQueue::Status>(
+ ".y2017.control_loops.superstructure_queue.status")),
+ superstructure_goal_sender_(
+ event_loop
+ ->MakeSender<::y2017::control_loops::SuperstructureQueue::Goal>(
+ ".y2017.control_loops.superstructure_queue.goal")) {}
enum class ShotDistance { VISION_SHOT, MIDDLE_SHOT, FAR_SHOT };
- ShotDistance last_shot_distance_ = ShotDistance::VISION_SHOT;
-
void HandleTeleop(const ::aos::input::driver_station::Data &data) {
// Default the intake to in.
intake_goal_ = 0.07;
bool lights_on = false;
bool vision_track = false;
- superstructure_queue.status.FetchLatest();
- if (!superstructure_queue.status.get()) {
+ superstructure_status_fetcher_.Fetch();
+ if (!superstructure_status_fetcher_.get()) {
LOG(ERROR, "Got no superstructure status packet.\n");
return;
}
@@ -147,10 +152,10 @@
fire_ = data.IsPressed(kFire) && shooter_velocity_ != 0.0;
if (data.IsPressed(kVisionAlign)) {
- fire_ = fire_ && superstructure_queue.status->turret.vision_tracking;
+ fire_ = fire_ && superstructure_status_fetcher_->turret.vision_tracking;
}
- auto new_superstructure_goal = superstructure_queue.goal.MakeMessage();
+ auto new_superstructure_goal = superstructure_goal_sender_.MakeMessage();
if (data.IsPressed(kHang)) {
intake_goal_ = 0.23;
}
@@ -191,13 +196,14 @@
new_superstructure_goal->use_vision_for_shots = false;
}
- if (superstructure_queue.status->intake.position >
- superstructure_queue.status->intake.unprofiled_goal_position + 0.01) {
+ if (superstructure_status_fetcher_->intake.position >
+ superstructure_status_fetcher_->intake.unprofiled_goal_position +
+ 0.01) {
intake_accumulator_ = 10;
}
if (intake_accumulator_ > 0) {
--intake_accumulator_;
- if (!superstructure_queue.status->intake.estopped) {
+ if (!superstructure_status_fetcher_->intake.estopped) {
new_superstructure_goal->intake.voltage_rollers = 10.0;
}
}
@@ -246,6 +252,13 @@
}
private:
+ ::aos::Fetcher<::y2017::control_loops::SuperstructureQueue::Status>
+ superstructure_status_fetcher_;
+ ::aos::Sender<::y2017::control_loops::SuperstructureQueue::Goal>
+ superstructure_goal_sender_;
+
+ ShotDistance last_shot_distance_ = ShotDistance::VISION_SHOT;
+
// Current goals to send to the robot.
double intake_goal_ = 0.0;
double turret_goal_ = 0.0;