Hide control_loop() inside ControlLoop better
control_loop() is a depenency we want to remove when we convert to
event loops. We want to only use the queue group to hold strings.
Change-Id: I3f444cd505ebb1e448f050e08f416e0901ce8afb
diff --git a/aos/controls/control_loop.h b/aos/controls/control_loop.h
index d52a5d1..335a1bb 100644
--- a/aos/controls/control_loop.h
+++ b/aos/controls/control_loop.h
@@ -63,14 +63,13 @@
}
// Constructs and sends a message on the output queue which sets everything to
- // a safe state (generally motors off). For some subclasses, this will be a
- // bit different (ie pistons).
- // The implementation here creates a new Output message, calls Zero() on it,
- // and then sends it.
- virtual void ZeroOutputs();
+ // a safe state. Default is to set everything to zero. Override Zero below
+ // to change that behavior.
+ void ZeroOutputs();
// Sets the output to zero.
- // Over-ride if a value of zero is not "off" for this subsystem.
+ // Override this if a value of zero (or false) is not "off" for this
+ // subsystem.
virtual void Zero(OutputType *output) { output->Zero(); }
// Runs the loop forever.
@@ -79,9 +78,6 @@
// Runs one cycle of the loop.
void Iterate() override;
- // Returns the name of the queue group.
- const char *name() { return control_loop_->name(); }
-
protected:
static void Quit(int /*signum*/) {
run_ = false;
@@ -101,9 +97,6 @@
OutputType *output,
StatusType *status) = 0;
- T *queue_group() { return control_loop_; }
- const T *queue_group() const { return control_loop_; }
-
private:
static constexpr ::std::chrono::milliseconds kStaleLogInterval =
::std::chrono::milliseconds(100);
diff --git a/y2014/control_loops/shooter/shooter.cc b/y2014/control_loops/shooter/shooter.cc
index e2f104c..f61cc02 100644
--- a/y2014/control_loops/shooter/shooter.cc
+++ b/y2014/control_loops/shooter/shooter.cc
@@ -699,12 +699,10 @@
status->shots = shot_count_;
}
-void ShooterMotor::ZeroOutputs() {
- queue_group()->output.MakeWithBuilder()
- .voltage(0)
- .latch_piston(latch_piston_)
- .brake_piston(brake_piston_)
- .Send();
+void ShooterMotor::Zero(::y2014::control_loops::ShooterQueue::Output *output) {
+ output->voltage = 0.0;
+ output->latch_piston = latch_piston_;
+ output->brake_piston = brake_piston_;
}
} // namespace control_loops
diff --git a/y2014/control_loops/shooter/shooter.h b/y2014/control_loops/shooter/shooter.h
index 0530012..75a05db 100644
--- a/y2014/control_loops/shooter/shooter.h
+++ b/y2014/control_loops/shooter/shooter.h
@@ -41,7 +41,7 @@
const static int kZeroingMaxVoltage = 5;
- virtual void CapU();
+ void CapU() override;
// Returns the accumulated voltage.
double voltage() const { return voltage_; }
@@ -158,15 +158,15 @@
State state() { return state_; }
protected:
- virtual void RunIteration(
+ void RunIteration(
const ::y2014::control_loops::ShooterQueue::Goal *goal,
const ::y2014::control_loops::ShooterQueue::Position *position,
::y2014::control_loops::ShooterQueue::Output *output,
- ::y2014::control_loops::ShooterQueue::Status *status);
+ ::y2014::control_loops::ShooterQueue::Status *status) override;
private:
// We have to override this to keep the pistons in the correct positions.
- virtual void ZeroOutputs();
+ void Zero(::y2014::control_loops::ShooterQueue::Output *output) override;
// Friend the test classes for acces to the internal state.
friend class testing::ShooterTest_UnloadWindupPositive_Test;