Kill target_selector_hint queue
Use EventLoop instead.
Change-Id: I84f839e6ec247648470c70be234611517dff8f51
diff --git a/frc971/autonomous/base_autonomous_actor.cc b/frc971/autonomous/base_autonomous_actor.cc
index d040b11..f551898 100644
--- a/frc971/autonomous/base_autonomous_actor.cc
+++ b/frc971/autonomous/base_autonomous_actor.cc
@@ -14,7 +14,6 @@
using ::frc971::control_loops::drivetrain_queue;
using ::aos::monotonic_clock;
-using ::y2019::control_loops::drivetrain::target_selector_hint;
namespace chrono = ::std::chrono;
namespace this_thread = ::std::this_thread;
@@ -26,7 +25,11 @@
const control_loops::drivetrain::DrivetrainConfig<double> &dt_config)
: aos::common::actions::ActorBase<AutonomousActionQueueGroup>(s),
dt_config_(dt_config),
- initial_drivetrain_({0.0, 0.0}) {}
+ initial_drivetrain_({0.0, 0.0}),
+ target_selector_hint_sender_(
+ event_loop_.MakeSender<
+ ::y2019::control_loops::drivetrain::TargetSelectorHint>(
+ ".y2019.control_loops.drivetrain.target_selector_hint")) {}
void BaseAutonomousActor::ResetDrivetrain() {
LOG(INFO, "resetting the drivetrain\n");
@@ -386,7 +389,7 @@
// factor it out in some way.
drivetrain_message->throttle = velocity / 4.0;
drivetrain_message.Send();
- auto target_hint = target_selector_hint.MakeMessage();
+ auto target_hint = target_selector_hint_sender_.MakeMessage();
target_hint->suggested_target = hint;
target_hint.Send();
}
diff --git a/frc971/autonomous/base_autonomous_actor.h b/frc971/autonomous/base_autonomous_actor.h
index 581e107..a6a57cd 100644
--- a/frc971/autonomous/base_autonomous_actor.h
+++ b/frc971/autonomous/base_autonomous_actor.h
@@ -5,9 +5,11 @@
#include "aos/actions/actions.h"
#include "aos/actions/actor.h"
+#include "aos/events/shm-event-loop.h"
#include "frc971/autonomous/auto.q.h"
#include "frc971/control_loops/drivetrain/drivetrain.q.h"
#include "frc971/control_loops/drivetrain/drivetrain_config.h"
+#include "y2019/control_loops/drivetrain/target_selector.q.h"
namespace frc971 {
namespace autonomous {
@@ -88,6 +90,10 @@
bool WaitForTurnProfileNear(double tolerance);
bool WaitForTurnProfileDone();
+ void set_max_drivetrain_voltage(double max_drivetrain_voltage) {
+ max_drivetrain_voltage_ = max_drivetrain_voltage;
+ }
+
// Returns the distance left to go.
double DriveDistanceLeft();
@@ -100,12 +106,12 @@
};
InitialDrivetrain initial_drivetrain_;
- void set_max_drivetrain_voltage(double max_drivetrain_voltage) {
- max_drivetrain_voltage_ = max_drivetrain_voltage;
- }
-
private:
friend class SplineHandle;
+ ::aos::ShmEventLoop event_loop_;
+
+ ::aos::Sender<::y2019::control_loops::drivetrain::TargetSelectorHint>
+ target_selector_hint_sender_;
double max_drivetrain_voltage_ = 12.0;
diff --git a/y2019/control_loops/drivetrain/BUILD b/y2019/control_loops/drivetrain/BUILD
index 8cfa45e..845575f 100644
--- a/y2019/control_loops/drivetrain/BUILD
+++ b/y2019/control_loops/drivetrain/BUILD
@@ -147,6 +147,7 @@
srcs = ["target_selector_test.cc"],
deps = [
":target_selector",
+ "//aos/events:shm-event-loop",
"//aos/testing:googletest",
"//aos/testing:test_shm",
],
diff --git a/y2019/control_loops/drivetrain/target_selector.q b/y2019/control_loops/drivetrain/target_selector.q
index 7ad2013..021bd3a 100644
--- a/y2019/control_loops/drivetrain/target_selector.q
+++ b/y2019/control_loops/drivetrain/target_selector.q
@@ -1,6 +1,7 @@
package y2019.control_loops.drivetrain;
// A message to provide information to the target selector about what it should
+// The drivetrain listens on ".y2019.control_loops.drivetrain.target_selector_hint"
message TargetSelectorHint {
// Which target we should go for:
// 0 implies no selection, we should just default to whatever.
@@ -9,5 +10,3 @@
// These should match the SelectionHint enum in target_selector.h.
uint8_t suggested_target;
};
-
-queue TargetSelectorHint target_selector_hint;
diff --git a/y2019/control_loops/drivetrain/target_selector_test.cc b/y2019/control_loops/drivetrain/target_selector_test.cc
index aa655e6..966f766 100644
--- a/y2019/control_loops/drivetrain/target_selector_test.cc
+++ b/y2019/control_loops/drivetrain/target_selector_test.cc
@@ -1,5 +1,6 @@
#include "y2019/control_loops/drivetrain/target_selector.h"
+#include "aos/events/shm-event-loop.h"
#include "aos/testing/test_shm.h"
#include "gtest/gtest.h"
#include "y2019/control_loops/superstructure/superstructure.q.h"
@@ -36,15 +37,27 @@
double expected_radius;
};
class TargetSelectorParamTest : public ::testing::TestWithParam<TestParams> {
- protected:
- virtual void TearDown() override {
- ::y2019::control_loops::superstructure::superstructure_queue.goal.Clear();
- ::y2019::control_loops::drivetrain::target_selector_hint.Clear();
- }
- ::aos::ShmEventLoop event_loop_;
+ public:
+ TargetSelectorParamTest()
+ : target_selector_hint_sender_(
+ test_event_loop_.MakeSender<
+ ::y2019::control_loops::drivetrain::TargetSelectorHint>(
+ ".y2019.control_loops.drivetrain.target_selector_hint")) {}
private:
::aos::testing::TestSharedMemory my_shm_;
+
+ protected:
+ virtual void TearDown() override {
+ ::y2019::control_loops::superstructure::superstructure_queue.goal.Clear();
+ }
+
+ ::aos::ShmEventLoop event_loop_;
+ ::aos::ShmEventLoop test_event_loop_;
+
+ ::aos::Sender<::y2019::control_loops::drivetrain::TargetSelectorHint>
+ target_selector_hint_sender_;
+
};
TEST_P(TargetSelectorParamTest, ExpectReturn) {
@@ -57,8 +70,7 @@
ASSERT_TRUE(super_goal.Send());
}
{
- auto hint =
- ::y2019::control_loops::drivetrain::target_selector_hint.MakeMessage();
+ auto hint = target_selector_hint_sender_.MakeMessage();
hint->suggested_target = static_cast<int>(GetParam().selection_hint);
ASSERT_TRUE(hint.Send());
}
diff --git a/y2019/joystick_reader.cc b/y2019/joystick_reader.cc
index 2108846..58d1c36 100644
--- a/y2019/joystick_reader.cc
+++ b/y2019/joystick_reader.cc
@@ -28,7 +28,6 @@
#include "y2019/vision.pb.h"
using ::y2019::control_loops::superstructure::superstructure_queue;
-using ::y2019::control_loops::drivetrain::target_selector_hint;
using ::frc971::control_loops::drivetrain::localizer_control;
using ::aos::input::driver_station::ButtonLocation;
using ::aos::input::driver_station::ControlBit;
@@ -141,7 +140,11 @@
event_loop,
::y2019::control_loops::drivetrain::GetDrivetrainConfig(),
{.run_teleop_in_auto = true,
- .cancel_auto_button = kCancelAutoMode}) {
+ .cancel_auto_button = kCancelAutoMode}),
+ target_selector_hint_sender_(
+ event_loop->MakeSender<
+ ::y2019::control_loops::drivetrain::TargetSelectorHint>(
+ ".y2019.control_loops.drivetrain.target_selector_hint")) {
const uint16_t team = ::aos::network::GetTeamNumber();
superstructure_queue.goal.FetchLatest();
if (superstructure_queue.goal.get()) {
@@ -176,7 +179,7 @@
auto new_superstructure_goal = superstructure_queue.goal.MakeMessage();
{
- auto target_hint = target_selector_hint.MakeMessage();
+ auto target_hint = target_selector_hint_sender_.MakeMessage();
if (data.IsPressed(kNearCargoHint)) {
target_hint->suggested_target = 1;
} else if (data.IsPressed(kMidCargoHint)) {
@@ -495,6 +498,9 @@
return ::frc971::autonomous::auto_mode->mode;
}
+ ::aos::Sender<::y2019::control_loops::drivetrain::TargetSelectorHint>
+ target_selector_hint_sender_;
+
// Bool to track if we've been above the deploy position. Once this bool is
// set, don't let the stilts retract until we see the platform.
bool was_above_ = false;