mirror of
https://github.com/BotChain-Robots/control.git
synced 2026-03-09 16:22:26 +01:00
Add default implementation in Module class
This commit is contained in:
@@ -19,11 +19,6 @@ class Hub final : public Module {
|
|||||||
uint8_t leader)
|
uint8_t leader)
|
||||||
: Module(device_id, module_type, connection_type, leader) {};
|
: Module(device_id, module_type, connection_type, leader) {};
|
||||||
|
|
||||||
double get_position() override;
|
|
||||||
std::string get_text() override;
|
|
||||||
void actuate(double position) override;
|
|
||||||
void actuate(double x, double y) override;
|
|
||||||
void actuate(const std::string &t) override;
|
|
||||||
std::vector<uint8_t> get_actuation_message() override;
|
std::vector<uint8_t> get_actuation_message() override;
|
||||||
void update_sensor_data(const Flatbuffers::sensor_value &value) override;
|
void update_sensor_data(const Flatbuffers::sensor_value &value) override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -44,11 +44,11 @@ class Module {
|
|||||||
std::chrono::time_point<std::chrono::system_clock> get_last_updated_time();
|
std::chrono::time_point<std::chrono::system_clock> get_last_updated_time();
|
||||||
|
|
||||||
// Not all modules implement all actuation/sensor values, some are no-ops
|
// Not all modules implement all actuation/sensor values, some are no-ops
|
||||||
virtual double get_position() = 0;
|
virtual double get_position();
|
||||||
virtual std::string get_text() = 0;
|
virtual std::string get_text();
|
||||||
virtual void actuate(double x) = 0;
|
virtual void actuate(double x);
|
||||||
virtual void actuate(const std::string &text) = 0;
|
virtual void actuate(const std::string &text);
|
||||||
virtual void actuate(double x, double y) = 0;
|
virtual void actuate(double x, double y);
|
||||||
|
|
||||||
void update_module_metadata(const Messaging::TopologyMessage &message);
|
void update_module_metadata(const Messaging::TopologyMessage &message);
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,7 @@ class BoundedPositionalActuator1D : public Actuator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
double get_position() override;
|
double get_position() override;
|
||||||
std::string get_text() override; // no-op
|
|
||||||
void actuate(double position) override;
|
void actuate(double position) override;
|
||||||
void actuate(const std::string &text) override; // no-op
|
|
||||||
void actuate(double x, double y) override; // no-op
|
|
||||||
|
|
||||||
std::vector<uint8_t> get_actuation_message() override;
|
std::vector<uint8_t> get_actuation_message() override;
|
||||||
void update_sensor_data(const Flatbuffers::sensor_value &value) override;
|
void update_sensor_data(const Flatbuffers::sensor_value &value) override;
|
||||||
|
|||||||
@@ -19,10 +19,7 @@ class OledActuator : public Actuator {
|
|||||||
m_text_message_builder(std::make_unique<Flatbuffers::TextControlMessageBuilder>()) {
|
m_text_message_builder(std::make_unique<Flatbuffers::TextControlMessageBuilder>()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
double get_position() override;
|
|
||||||
std::string get_text() override;
|
std::string get_text() override;
|
||||||
void actuate(double position) override;
|
|
||||||
void actuate(double x, double y) override; // no-op
|
|
||||||
void actuate(const std::string &text) override;
|
void actuate(const std::string &text) override;
|
||||||
|
|
||||||
std::vector<uint8_t> get_actuation_message() override;
|
std::vector<uint8_t> get_actuation_message() override;
|
||||||
|
|||||||
@@ -19,10 +19,7 @@ class PositionalActuator1D final : public Actuator {
|
|||||||
m_acm_builder(std::make_unique<Flatbuffers::AngleControlMessageBuilder>()) {};
|
m_acm_builder(std::make_unique<Flatbuffers::AngleControlMessageBuilder>()) {};
|
||||||
|
|
||||||
double get_position() override;
|
double get_position() override;
|
||||||
std::string get_text() override; // no-op
|
|
||||||
void actuate(double position) override;
|
void actuate(double position) override;
|
||||||
void actuate(const std::string &text) override; // no-op
|
|
||||||
void actuate(double x, double y) override; // no-op
|
|
||||||
|
|
||||||
std::vector<uint8_t> get_actuation_message() override;
|
std::vector<uint8_t> get_actuation_message() override;
|
||||||
void update_sensor_data(const Flatbuffers::sensor_value &value) override;
|
void update_sensor_data(const Flatbuffers::sensor_value &value) override;
|
||||||
|
|||||||
22
src/Hub.cpp
22
src/Hub.cpp
@@ -1,28 +1,6 @@
|
|||||||
#include "Hub.h"
|
#include "Hub.h"
|
||||||
#include "flatbuffers/SensorMessageBuilder.h"
|
#include "flatbuffers/SensorMessageBuilder.h"
|
||||||
|
|
||||||
double Hub::get_position() {
|
|
||||||
// no-op
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Hub::get_text() {
|
|
||||||
// no-op
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
void Hub::actuate(double /* position */) {
|
|
||||||
// no-op
|
|
||||||
}
|
|
||||||
|
|
||||||
void Hub::actuate(double /* x */, double /* y */) {
|
|
||||||
// no-op
|
|
||||||
}
|
|
||||||
|
|
||||||
void Hub::actuate(const std::string &text) {
|
|
||||||
// no-op
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<uint8_t> Hub::get_actuation_message() {
|
std::vector<uint8_t> Hub::get_actuation_message() {
|
||||||
// no-op
|
// no-op
|
||||||
return {};
|
return {};
|
||||||
|
|||||||
@@ -41,3 +41,25 @@ void Module::update_module_metadata(const Messaging::TopologyMessage &message) {
|
|||||||
m_neighbours.emplace_back(neighbour{id, static_cast<Orientation>(ori)});
|
m_neighbours.emplace_back(neighbour{id, static_cast<Orientation>(ori)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double Module::get_position() {
|
||||||
|
// no-op
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Module::get_text() {
|
||||||
|
// no-op
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void Module::actuate(double /* position */) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
void Module::actuate(double /* x */, double /* y */) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
void Module::actuate(const std::string &text) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,10 +10,6 @@ double BoundedPositionalActuator1D::get_position() {
|
|||||||
return m_current_position;
|
return m_current_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string BoundedPositionalActuator1D::get_text() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
void BoundedPositionalActuator1D::actuate(double position) {
|
void BoundedPositionalActuator1D::actuate(double position) {
|
||||||
if (position < m_min_value || position > m_max_value) {
|
if (position < m_min_value || position > m_max_value) {
|
||||||
return;
|
return;
|
||||||
@@ -22,12 +18,6 @@ void BoundedPositionalActuator1D::actuate(double position) {
|
|||||||
m_target_position = position;
|
m_target_position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoundedPositionalActuator1D::actuate(double x, double y) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void BoundedPositionalActuator1D::actuate(const std::string &text) {
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<uint8_t> BoundedPositionalActuator1D::get_actuation_message() {
|
std::vector<uint8_t> BoundedPositionalActuator1D::get_actuation_message() {
|
||||||
std::vector<uint8_t> message{};
|
std::vector<uint8_t> message{};
|
||||||
|
|
||||||
|
|||||||
@@ -3,20 +3,10 @@
|
|||||||
#include "util/Variant.h"
|
#include "util/Variant.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
double OledActuator::get_position() {
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string OledActuator::get_text() {
|
std::string OledActuator::get_text() {
|
||||||
return m_current_text;
|
return m_current_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OledActuator::actuate(double /* position */) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void OledActuator::actuate(double /* x */, double /* y */) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void OledActuator::actuate(const std::string &text) {
|
void OledActuator::actuate(const std::string &text) {
|
||||||
m_target_text = text;
|
m_target_text = text;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,20 +7,10 @@ double PositionalActuator1D::get_position() {
|
|||||||
return m_current_position;
|
return m_current_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string PositionalActuator1D::get_text() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
void PositionalActuator1D::actuate(double position) {
|
void PositionalActuator1D::actuate(double position) {
|
||||||
m_target_position = position;
|
m_target_position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PositionalActuator1D::actuate(double /* x */, double /* y */) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void PositionalActuator1D::actuate(const std::string &text) {
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<uint8_t> PositionalActuator1D::get_actuation_message() {
|
std::vector<uint8_t> PositionalActuator1D::get_actuation_message() {
|
||||||
std::vector<uint8_t> message{};
|
std::vector<uint8_t> message{};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user