Merge changes I3f444cd5,If3815bdc,Iac39d224
* changes:
Hide control_loop() inside ControlLoop better
Remove unused queuegroup hash
Remove unused SerializableControlLoop class
diff --git a/aos/build/queues/output/q_file.rb b/aos/build/queues/output/q_file.rb
index 1e39247..3bbdaed 100644
--- a/aos/build/queues/output/q_file.rb
+++ b/aos/build/queues/output/q_file.rb
@@ -118,8 +118,7 @@
type_class.add_member(:public,member_func)
#cpp_tree.cc_file.add_funct(member_func)
member_func.args << "const char *name";
- member_func.args << "uint32_t hash";
- member_func.add_cons("::aos::QueueGroup","name", "hash")
+ member_func.add_cons("::aos::QueueGroup","name")
@queues.each do |queue|
member_func.args << "const char *#{queue.name}_name";
member_func.add_cons(queue.name,"#{queue.name}_name")
@@ -169,7 +168,6 @@
cons_call = CPP::FuncCall.new("new #{type_name}")
cons_call.args.push(@loc.queue_name(@name).inspect)
- cons_call.args.push(@type.hash_with_name(@loc.queue_name(@name).inspect))
@type.queues.collect do |queue|
cons_call.args.push(@loc.queue_name(@name + "." + queue.name).inspect)
end
diff --git a/aos/controls/control_loop.h b/aos/controls/control_loop.h
index fd63e3f..335a1bb 100644
--- a/aos/controls/control_loop.h
+++ b/aos/controls/control_loop.h
@@ -22,21 +22,6 @@
virtual void Iterate() = 0;
};
-class SerializableControlLoop : public Runnable {
- public:
- // Returns the size of all the data to be sent when serialized.
- virtual size_t SeralizedSize() = 0;
- // Serialize the current data.
- virtual void Serialize(char *buffer) const = 0;
- // Serialize zeroed data in case the data is out of date.
- virtual void SerializeZeroMessage(char *buffer) const = 0;
- // Deserialize data into the control loop.
- virtual void Deserialize(const char *buffer) = 0;
- // Unique identifier for the control loop.
- // Most likely the hash of the queue group.
- virtual uint32_t UniqueID() = 0;
-};
-
// Control loops run this often, "starting" at time 0.
constexpr ::std::chrono::nanoseconds kLoopFrequency =
::std::chrono::milliseconds(5);
@@ -47,7 +32,7 @@
// It will then call the RunIteration method every cycle that it has enough
// valid data for the control loop to run.
template <class T>
-class ControlLoop : public SerializableControlLoop {
+class ControlLoop : public Runnable {
public:
// Create some convenient typedefs to reference the Goal, Position, Status,
// and Output structures.
@@ -78,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.
@@ -94,29 +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(); }
-
- // Methods to serialize all the data that should be sent over the network.
- size_t SeralizedSize() override { return control_loop_->goal->Size(); }
- void Serialize(char *buffer) const override {
- control_loop_->goal->Serialize(buffer);
- }
- void SerializeZeroMessage(char *buffer) const override {
- GoalType zero_goal;
- zero_goal.Zero();
- zero_goal.Serialize(buffer);
- }
-
- void Deserialize(const char *buffer) override {
- ScopedMessagePtr<GoalType> new_msg = control_loop_->goal.MakeMessage();
- new_msg->Deserialize(buffer);
- new_msg.Send();
- }
-
- uint32_t UniqueID() override { return control_loop_->hash(); }
-
-
protected:
static void Quit(int /*signum*/) {
run_ = false;
@@ -136,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/aos/queue.h b/aos/queue.h
index 1897773..47540f6 100644
--- a/aos/queue.h
+++ b/aos/queue.h
@@ -209,16 +209,13 @@
public:
// Constructs a queue group given its name and a unique hash of the name and
// type.
- QueueGroup(const char *name, uint32_t hash) : name_(name), hash_(hash) {}
+ QueueGroup(const char *name) : name_(name) {}
// Returns the name of the queue group.
const char *name() const { return name_.c_str(); }
- // Returns a unique hash representing this instance of the queue group.
- uint32_t hash() const { return hash_; }
private:
std::string name_;
- uint32_t hash_;
};
} // namespace aos
diff --git a/aos/queue_test.cc b/aos/queue_test.cc
index 8eeca6e..1c4ebdd 100644
--- a/aos/queue_test.cc
+++ b/aos/queue_test.cc
@@ -213,7 +213,6 @@
protected:
GroupTest()
: my_test_queuegroup(".aos.common.testing.test_queuegroup",
- 0x20561114,
".aos.common.testing.test_queuegroup.first",
".aos.common.testing.test_queuegroup.second") {}
@@ -226,16 +225,6 @@
::aos::testing::TestSharedMemory my_shm_;
};
-// Tests that the hash gets preserved.
-TEST_F(GroupTest, Hash) {
- EXPECT_EQ(static_cast<uint32_t>(0x20561114), my_test_queuegroup.hash());
-}
-
-// Tests that the hash works.
-TEST_F(GroupTest, RealHash) {
- EXPECT_EQ(static_cast<uint32_t>(0x93596b2f), test_queuegroup.hash());
-}
-
// Tests that name works.
TEST_F(GroupTest, Name) {
EXPECT_EQ(std::string(".aos.common.testing.test_queuegroup"),
diff --git a/frc971/codelab/basic_test.cc b/frc971/codelab/basic_test.cc
index 0761cb2..5132407 100644
--- a/frc971/codelab/basic_test.cc
+++ b/frc971/codelab/basic_test.cc
@@ -20,7 +20,7 @@
class BasicSimulation {
public:
BasicSimulation()
- : basic_queue_(".frc971.codelab.basic_queue", 0x78d8e372,
+ : basic_queue_(".frc971.codelab.basic_queue",
".frc971.codelab.basic_queue.goal",
".frc971.codelab.basic_queue.position",
".frc971.codelab.basic_queue.output",
@@ -60,7 +60,7 @@
class BasicControlLoopTest : public ::aos::testing::ControlLoopTest {
public:
BasicControlLoopTest()
- : basic_queue_(".frc971.codelab.basic_queue", 0x78d8e372,
+ : basic_queue_(".frc971.codelab.basic_queue",
".frc971.codelab.basic_queue.goal",
".frc971.codelab.basic_queue.position",
".frc971.codelab.basic_queue.output",
diff --git a/frc971/control_loops/drivetrain/drivetrain_lib_test.cc b/frc971/control_loops/drivetrain/drivetrain_lib_test.cc
index e4d320e..a6711e4 100644
--- a/frc971/control_loops/drivetrain/drivetrain_lib_test.cc
+++ b/frc971/control_loops/drivetrain/drivetrain_lib_test.cc
@@ -103,7 +103,7 @@
// TODO(aschuh) Do we want to test the clutch one too?
DrivetrainSimulation()
: drivetrain_plant_(new DrivetrainPlant(MakeDrivetrainPlant())),
- my_drivetrain_queue_(".frc971.control_loops.drivetrain", 0x8a8dde77,
+ my_drivetrain_queue_(".frc971.control_loops.drivetrain",
".frc971.control_loops.drivetrain.goal",
".frc971.control_loops.drivetrain.position",
".frc971.control_loops.drivetrain.output",
@@ -223,7 +223,7 @@
DrivetrainSimulation drivetrain_motor_plant_;
DrivetrainTest()
- : my_drivetrain_queue_(".frc971.control_loops.drivetrain", 0x8a8dde77,
+ : my_drivetrain_queue_(".frc971.control_loops.drivetrain",
".frc971.control_loops.drivetrain.goal",
".frc971.control_loops.drivetrain.position",
".frc971.control_loops.drivetrain.output",
diff --git a/y2014/control_loops/claw/claw_lib_test.cc b/y2014/control_loops/claw/claw_lib_test.cc
index 753c087..f10e61e 100644
--- a/y2014/control_loops/claw/claw_lib_test.cc
+++ b/y2014/control_loops/claw/claw_lib_test.cc
@@ -37,7 +37,7 @@
ClawMotorSimulation(double initial_top_position,
double initial_bottom_position)
: claw_plant_(new StateFeedbackPlant<4, 2, 2>(MakeClawPlant())),
- claw_queue(".y2014.control_loops.claw_queue", 0x9f1a99dd,
+ claw_queue(".y2014.control_loops.claw_queue",
".y2014.control_loops.claw_queue.goal",
".y2014.control_loops.claw_queue.position",
".y2014.control_loops.claw_queue.output",
@@ -254,7 +254,7 @@
double min_separation_;
ClawTest()
- : claw_queue(".y2014.control_loops.claw_queue", 0x9f1a99dd,
+ : claw_queue(".y2014.control_loops.claw_queue",
".y2014.control_loops.claw_queue.goal",
".y2014.control_loops.claw_queue.position",
".y2014.control_loops.claw_queue.output",
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;
diff --git a/y2014/control_loops/shooter/shooter_lib_test.cc b/y2014/control_loops/shooter/shooter_lib_test.cc
index 972b8b0..108502b 100644
--- a/y2014/control_loops/shooter/shooter_lib_test.cc
+++ b/y2014/control_loops/shooter/shooter_lib_test.cc
@@ -35,12 +35,11 @@
plunger_latched_(false),
brake_piston_state_(true),
brake_delay_count_(0),
- shooter_queue_(
- ".y2014.control_loops.shooter_queue", 0xcbf22ba9,
- ".y2014.control_loops.shooter_queue.goal",
- ".y2014.control_loops.shooter_queue.position",
- ".y2014.control_loops.shooter_queue.output",
- ".y2014.control_loops.shooter_queue.status") {
+ shooter_queue_(".y2014.control_loops.shooter_queue",
+ ".y2014.control_loops.shooter_queue.goal",
+ ".y2014.control_loops.shooter_queue.position",
+ ".y2014.control_loops.shooter_queue.output",
+ ".y2014.control_loops.shooter_queue.status") {
Reinitialize(initial_position);
}
@@ -299,15 +298,13 @@
}
ShooterTestTemplated()
- : shooter_queue_(
- ".y2014.control_loops.shooter_queue", 0xcbf22ba9,
- ".y2014.control_loops.shooter_queue.goal",
- ".y2014.control_loops.shooter_queue.position",
- ".y2014.control_loops.shooter_queue.output",
- ".y2014.control_loops.shooter_queue.status"),
+ : shooter_queue_(".y2014.control_loops.shooter_queue",
+ ".y2014.control_loops.shooter_queue.goal",
+ ".y2014.control_loops.shooter_queue.position",
+ ".y2014.control_loops.shooter_queue.output",
+ ".y2014.control_loops.shooter_queue.status"),
shooter_motor_(&shooter_queue_),
- shooter_motor_plant_(0.2) {
- }
+ shooter_motor_plant_(0.2) {}
void VerifyNearGoal() {
shooter_queue_.goal.FetchLatest();
diff --git a/y2016/control_loops/shooter/shooter_lib_test.cc b/y2016/control_loops/shooter/shooter_lib_test.cc
index c5d5aa7..bba603f 100644
--- a/y2016/control_loops/shooter/shooter_lib_test.cc
+++ b/y2016/control_loops/shooter/shooter_lib_test.cc
@@ -53,7 +53,7 @@
::y2016::control_loops::shooter::MakeShooterPlant())),
shooter_plant_right_(new ShooterPlant(
::y2016::control_loops::shooter::MakeShooterPlant())),
- shooter_queue_(".y2016.control_loops.shooter", 0x78d8e372,
+ shooter_queue_(".y2016.control_loops.shooter",
".y2016.control_loops.shooter.goal",
".y2016.control_loops.shooter.position",
".y2016.control_loops.shooter.output",
@@ -101,7 +101,7 @@
class ShooterTest : public ::aos::testing::ControlLoopTest {
protected:
ShooterTest()
- : shooter_queue_(".y2016.control_loops.shooter", 0x78d8e372,
+ : shooter_queue_(".y2016.control_loops.shooter",
".y2016.control_loops.shooter.goal",
".y2016.control_loops.shooter.position",
".y2016.control_loops.shooter.output",
diff --git a/y2016/control_loops/superstructure/superstructure_lib_test.cc b/y2016/control_loops/superstructure/superstructure_lib_test.cc
index 824f291..e4d1301 100644
--- a/y2016/control_loops/superstructure/superstructure_lib_test.cc
+++ b/y2016/control_loops/superstructure/superstructure_lib_test.cc
@@ -88,7 +88,7 @@
pot_encoder_shoulder_(
constants::Values::kShoulderEncoderIndexDifference),
pot_encoder_wrist_(constants::Values::kWristEncoderIndexDifference),
- superstructure_queue_(".y2016.control_loops.superstructure", 0x0,
+ superstructure_queue_(".y2016.control_loops.superstructure",
".y2016.control_loops.superstructure.goal",
".y2016.control_loops.superstructure.status",
".y2016.control_loops.superstructure.output",
@@ -246,7 +246,7 @@
class SuperstructureTest : public ::aos::testing::ControlLoopTest {
protected:
SuperstructureTest()
- : superstructure_queue_(".y2016.control_loops.superstructure", 0x0,
+ : superstructure_queue_(".y2016.control_loops.superstructure",
".y2016.control_loops.superstructure.goal",
".y2016.control_loops.superstructure.status",
".y2016.control_loops.superstructure.output",
diff --git a/y2017/control_loops/superstructure/superstructure_lib_test.cc b/y2017/control_loops/superstructure/superstructure_lib_test.cc
index 894f99d..de47690 100644
--- a/y2017/control_loops/superstructure/superstructure_lib_test.cc
+++ b/y2017/control_loops/superstructure/superstructure_lib_test.cc
@@ -134,7 +134,7 @@
column_plant_(new ColumnPlant(
::y2017::control_loops::superstructure::column::MakeColumnPlant())),
- superstructure_queue_(".y2017.control_loops.superstructure", 0xdeadbeef,
+ superstructure_queue_(".y2017.control_loops.superstructure",
".y2017.control_loops.superstructure.goal",
".y2017.control_loops.superstructure.position",
".y2017.control_loops.superstructure.output",
@@ -432,7 +432,7 @@
class SuperstructureTest : public ::aos::testing::ControlLoopTest {
protected:
SuperstructureTest()
- : superstructure_queue_(".y2017.control_loops.superstructure", 0xdeadbeef,
+ : superstructure_queue_(".y2017.control_loops.superstructure",
".y2017.control_loops.superstructure.goal",
".y2017.control_loops.superstructure.position",
".y2017.control_loops.superstructure.output",
diff --git a/y2018/control_loops/superstructure/superstructure_lib_test.cc b/y2018/control_loops/superstructure/superstructure_lib_test.cc
index 62b20f8..0856a7d 100644
--- a/y2018/control_loops/superstructure/superstructure_lib_test.cc
+++ b/y2018/control_loops/superstructure/superstructure_lib_test.cc
@@ -196,7 +196,7 @@
constants::GetValues().right_intake.zeroing),
arm_(constants::GetValues().arm_proximal.zeroing,
constants::GetValues().arm_distal.zeroing),
- superstructure_queue_(".y2018.control_loops.superstructure", 0xdeadbeef,
+ superstructure_queue_(".y2018.control_loops.superstructure",
".y2018.control_loops.superstructure.goal",
".y2018.control_loops.superstructure.position",
".y2018.control_loops.superstructure.output",
@@ -268,7 +268,7 @@
class SuperstructureTest : public ::aos::testing::ControlLoopTest {
protected:
SuperstructureTest()
- : superstructure_queue_(".y2018.control_loops.superstructure", 0xdeadbeef,
+ : superstructure_queue_(".y2018.control_loops.superstructure",
".y2018.control_loops.superstructure.goal",
".y2018.control_loops.superstructure.position",
".y2018.control_loops.superstructure.output",