diff --git a/Thing.h b/Thing.h index 2fac262..ebc546c 100644 --- a/Thing.h +++ b/Thing.h @@ -36,6 +36,7 @@ class Thing { Roboid, Humanoid, ExternalSensor, + DifferentialDrive }; #pragma region Init diff --git a/Things/DifferentialDrive.cpp b/Things/DifferentialDrive.cpp index ad7ad14..80567a1 100644 --- a/Things/DifferentialDrive.cpp +++ b/Things/DifferentialDrive.cpp @@ -1,10 +1,13 @@ #include "DifferentialDrive.h" namespace RoboidControl { -DifferentialDrive::DifferentialDrive() : Thing() {} -RoboidControl::DifferentialDrive::DifferentialDrive(Participant* participant) - : Thing(participant) {} + DifferentialDrive::DifferentialDrive() : Thing(Thing::Type::DifferentialDrive) {} + +DifferentialDrive::DifferentialDrive(Participant* participant, unsigned char thingId) + : Thing(participant, Thing::Type::DifferentialDrive, thingId) {} + +DifferentialDrive::DifferentialDrive(Thing* parent, unsigned char thingId) : Thing(parent, Thing::Type::DifferentialDrive, thingId) {} void DifferentialDrive::SetDriveDimensions(float wheelDiameter, float wheelSeparation) { diff --git a/Things/DifferentialDrive.h b/Things/DifferentialDrive.h index 03e6318..000d8fd 100644 --- a/Things/DifferentialDrive.h +++ b/Things/DifferentialDrive.h @@ -13,7 +13,14 @@ class DifferentialDrive : public Thing { DifferentialDrive(); /// @brief Create a differential drive with networking support /// @param participant The local participant - DifferentialDrive(Participant* participant); + /// @param thingId The ID of the thing, leave out or set to zero to generate + /// an ID + DifferentialDrive(Participant* participant, unsigned char thingId = 0); + /// @brief Create a new child differential drive + /// @param parent The parent thing + /// @param thingId The ID of the thing, leave out or set to zero to generate + /// an ID + DifferentialDrive(Thing* parent, unsigned char thingId = 0); /// @brief Configures the dimensions of the drive /// @param wheelDiameter The diameter of the wheels in meters @@ -33,7 +40,6 @@ class DifferentialDrive : public Thing { /// Positive moves the robot in the forward direction. /// @param speedRight The speed of the right wheel in degrees per second. /// Positive moves the robot in the forward direction. - void SetWheelVelocity(float speedLeft, float speedRight); /// @copydoc RoboidControl::Thing::Update(unsigned long) diff --git a/Things/DigitalSensor.cpp b/Things/DigitalSensor.cpp index 3f460cb..528bd7a 100644 --- a/Things/DigitalSensor.cpp +++ b/Things/DigitalSensor.cpp @@ -2,8 +2,21 @@ namespace RoboidControl { -//DigitalSensor::DigitalSensor() {} +DigitalSensor::DigitalSensor() : Thing(Type::Switch) {} -DigitalSensor::DigitalSensor(Participant* participant, unsigned char networkId, unsigned char thingId) : Thing(participant) {} +DigitalSensor::DigitalSensor(Participant* owner, unsigned char thingId) + : Thing(owner, Type::Switch, thingId) {} + +DigitalSensor::DigitalSensor(Thing* parent, unsigned char thingId) + : Thing(parent, Type::Switch) {} + +int DigitalSensor::GenerateBinary(char* bytes, unsigned char* ix) { + bytes[(*ix)++] = state ? 1 : 0; + return 1; +} + +void DigitalSensor::ProcessBinary(char* bytes) { + this->state |= (bytes[0] == 1); +} } // namespace RoboidControl diff --git a/Things/DigitalSensor.h b/Things/DigitalSensor.h index 5e4bc8a..95ab1b3 100644 --- a/Things/DigitalSensor.h +++ b/Things/DigitalSensor.h @@ -7,15 +7,30 @@ namespace RoboidControl { /// @brief A digital (on/off, 1/0, true/false) sensor class DigitalSensor : public Thing { public: + /// @brief Create a digital sensor without communication abilities + DigitalSensor(); + /// @brief Create a digital sensor for a participant + /// @param owner The owning participant + /// @param thingId The ID of the thing, leave out or set to zero to generate + /// an ID + DigitalSensor(Participant* owner, unsigned char thingId = 0); + /// @brief Create a new child digital sensor + /// @param parent The parent thing + /// @param thingId The ID of the thing, leave out or set to zero to generate + /// an ID + DigitalSensor(Thing* parent, unsigned char thingId = 0); + /// @brief The sigital state bool state = 0; - /// @brief The default constructor - //DigitalSensor(); - /// @brief Create a temperature sensor with the given ID - /// @param networkId The network ID of the sensor - /// @param thingId The ID of the thing - DigitalSensor(Participant* participant, unsigned char networkId, unsigned char thingId); + /// @brief Function used to generate binary data for this digital sensor + /// @param buffer The byte array for thw binary data + /// @param ix The starting position for writing the binary data + int GenerateBinary(char* bytes, unsigned char* ix) override; + /// @brief Function used to process binary data received for this digital + /// sensor + /// @param bytes The binary data to process + virtual void ProcessBinary(char* bytes) override; }; } // namespace RoboidControl diff --git a/Things/TemperatureSensor.h b/Things/TemperatureSensor.h index 8d58d9c..a447385 100644 --- a/Things/TemperatureSensor.h +++ b/Things/TemperatureSensor.h @@ -7,9 +7,6 @@ namespace RoboidControl { /// @brief A temperature sensor class TemperatureSensor : public Thing { public: - /// @brief The measured temperature - float temperature = 0; - /// @brief The default constructor //TemperatureSensor(); /// @brief Create a temperature sensor with the given ID @@ -17,6 +14,9 @@ class TemperatureSensor : public Thing { /// @param thingId The ID of the thing TemperatureSensor(Participant* participant, unsigned char thingId); + /// @brief The measured temperature + float temperature = 0; + /// @brief Manually override the measured temperature /// @param temperature The new temperature virtual void SetTemperature(float temperature); diff --git a/Things/TouchSensor.cpp b/Things/TouchSensor.cpp index be98aeb..cef0c9e 100644 --- a/Things/TouchSensor.cpp +++ b/Things/TouchSensor.cpp @@ -1,22 +1,22 @@ #include "TouchSensor.h" namespace RoboidControl { + TouchSensor::TouchSensor() : Thing(Thing::Type::TouchSensor) {} -TouchSensor::TouchSensor(Participant* participant) - : Thing(participant, Thing::Type::TouchSensor) {} +TouchSensor::TouchSensor(Participant* owner, unsigned char thingId) + : Thing(owner, Thing::Type::TouchSensor, thingId) {} -TouchSensor::TouchSensor(Thing* parent) : Thing(parent->owner) { +TouchSensor::TouchSensor(Thing* parent, unsigned char thingId) : Thing(parent->owner, Thing::Type::TouchSensor, thingId) { this->SetParent(parent); } int TouchSensor::GenerateBinary(char* bytes, unsigned char* ix) { - return 0; + bytes[(*ix)++] = touchedSomething ? 1 : 0; + return 1; } void TouchSensor::ProcessBinary(char* bytes) { - if (bytes[0] == 1) - std::cout << this->GetName() << " is Touching something!\n"; this->touchedSomething |= (bytes[0] == 1); } diff --git a/Things/TouchSensor.h b/Things/TouchSensor.h index 4e6d483..42d6a0b 100644 --- a/Things/TouchSensor.h +++ b/Things/TouchSensor.h @@ -6,31 +6,31 @@ namespace RoboidControl { /// @brief A sensor which can detect touches class TouchSensor : public Thing { +// Why finishing this release (0.3), I notice that this is equivalent to a digital sensor public: - // Inherit all constructors - using Thing::Thing; - - /// @brief Create a touch sensor with isolated participant + /// @brief Create a touch sensor without communication abilities TouchSensor(); - /// @brief Create a touch sensor - TouchSensor(Participant* participant); - /// @brief Create a temperature sensor with the given ID - /// @param networkId The network ID of the sensor - /// @param thingId The ID of the thing - TouchSensor(Thing* parent); - // TouchSensor(RemoteParticipant* participant, unsigned char networkId, - // unsigned char thingId); + /// @brief Create a touch sensor for a participant + /// @param owner The owning participant + /// @param thingId The ID of the thing, leave out or set to zero to generate + /// an ID + TouchSensor(Participant* owner, unsigned char thingId = 0); + /// @brief Create a new child touch sensor + /// @param parent The parent thing + /// @param thingId The ID of the thing, leave out or set to zero to generate + /// an ID + TouchSensor(Thing* parent, unsigned char thingId = 0); /// @brief Value which is true when the sensor is touching something, false /// otherwise bool touchedSomething = false; - /// @brief Function to create a binary message with the temperature + /// @brief Function used to generate binary data for this touch sensor /// @param buffer The byte array for thw binary data /// @param ix The starting position for writing the binary data int GenerateBinary(char* bytes, unsigned char* ix) override; - /// @brief Function to extract the temperature received in the binary message - /// @param bytes The binary data + /// @brief Function used to process binary data received for this touch sensor + /// @param bytes The binary data to process virtual void ProcessBinary(char* bytes) override; };