From 31e802b51bf4e87ebbc3e43713580ea1d3e154bc Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 28 Nov 2023 12:53:07 +0100 Subject: [PATCH] Added namespaces --- Accelerometer.h | 9 ++++++++- Activation.h | 16 ++++++++++++++-- ControlledMotor.h | 12 +++++++++--- DistanceSensor.h | 7 +++++++ Encoder.h | 7 +++++++ Magnetometer.h | 18 ++++++++++++++---- Motor.h | 7 +++++++ Perception.h | 7 +++++++ Placement.h | 7 +++++++ Propulsion.h | 7 +++++++ Quadcopter.h | 9 ++++++++- Roboid.cpp | 4 +++- Roboid.h | 9 ++++++++- Sensing.h | 21 +++++++++++++++------ Sensor.h | 9 ++++++++- Thing.h | 9 ++++++++- VectorAlgebra | 2 +- 17 files changed, 138 insertions(+), 22 deletions(-) diff --git a/Accelerometer.h b/Accelerometer.h index 44addc8..eb2b611 100644 --- a/Accelerometer.h +++ b/Accelerometer.h @@ -2,6 +2,9 @@ #include "Sensor.h" +namespace Passer { +namespace RoboidControl { + /// @brief A Sensor which can measure the magnetic field class Accelerometer : public Sensor { public: @@ -31,4 +34,8 @@ class Accelerometer : public Sensor { /// @return The magnitude. This value is never negative. /// @note the unity (m/s^2, 0..1) depends on the sensor. float GetAccelerationMagnitude(); -}; \ No newline at end of file +}; + +} // namespace RoboidControl +} // namespace Passer +using namespace Passer::RoboidControl; \ No newline at end of file diff --git a/Activation.h b/Activation.h index 255e953..7ff0b0b 100644 --- a/Activation.h +++ b/Activation.h @@ -3,6 +3,9 @@ #include +namespace Passer { +namespace RoboidControl { + class Activation { public: static float HeavisideStep(float inputValue, float bias = 0); // Range: {0,1} @@ -13,9 +16,18 @@ class Activation { static float Linear(float inputValue, float bias = 0, float range = 0); - static float Quadratic(float inputValue, float bias = 0, float range = 0); // minValue = bias + static float Quadratic(float inputValue, + float bias = 0, + float range = 0); // minValue = bias - static float ParticleLife(float minValue, float maxValue, float attraction, float inputValue); // minValue = bias + static float ParticleLife(float minValue, + float maxValue, + float attraction, + float inputValue); // minValue = bias }; +} // namespace RoboidControl +} // namespace Passer +using namespace Passer::RoboidControl; + #endif \ No newline at end of file diff --git a/ControlledMotor.h b/ControlledMotor.h index d60c948..a732949 100644 --- a/ControlledMotor.h +++ b/ControlledMotor.h @@ -3,6 +3,9 @@ #include "Encoder.h" #include "Motor.h" +namespace Passer { +namespace RoboidControl { + /// @brief A motor with speed control /// It uses a feedback loop from an encoder to regulate the speed /// The speed is measured in revolutions per second. @@ -39,12 +42,15 @@ class ControlledMotor : public Thing { float netDistance = 0; float startDistance = 0; - enum Direction { Forward = 1, - Reverse = -1 }; + enum Direction { Forward = 1, Reverse = -1 }; Direction rotationDirection; bool driving = false; float targetDistance = 0; float lastEncoderPosition = 0; -}; \ No newline at end of file +}; + +} // namespace RoboidControl +} // namespace Passer +using namespace Passer::RoboidControl; \ No newline at end of file diff --git a/DistanceSensor.h b/DistanceSensor.h index 87b3e26..6f6d16b 100644 --- a/DistanceSensor.h +++ b/DistanceSensor.h @@ -2,6 +2,9 @@ #include "Sensor.h" +namespace Passer { +namespace RoboidControl { + /// @brief A Sensor which can measure the distance to the nearest object class DistanceSensor : public Sensor { public: @@ -22,3 +25,7 @@ class DistanceSensor : public Sensor { protected: float distance = 0; }; + +} // namespace RoboidControl +} // namespace Passer +using namespace Passer::RoboidControl; \ No newline at end of file diff --git a/Encoder.h b/Encoder.h index 4573901..ce218ad 100644 --- a/Encoder.h +++ b/Encoder.h @@ -1,5 +1,8 @@ #pragma once +namespace Passer { +namespace RoboidControl { + class Encoder { public: Encoder(); @@ -14,3 +17,7 @@ class Encoder { protected: unsigned char transitionsPerRotation; }; + +} // namespace RoboidControl +} // namespace Passer +using namespace Passer::RoboidControl; \ No newline at end of file diff --git a/Magnetometer.h b/Magnetometer.h index ee9cf88..300a3f7 100644 --- a/Magnetometer.h +++ b/Magnetometer.h @@ -2,16 +2,22 @@ #include "Sensor.h" +namespace Passer { +namespace RoboidControl { + /// @brief A Sensor which can measure the magnetic field class Magnetometer : public Sensor { public: Magnetometer(); - /// @brief Returns the direction of the magnetic field relative to the forward direction + /// @brief Returns the direction of the magnetic field relative to the forward + /// direction /// @return The direction, negative is to the left, positive is to the right - /// @note The actual unit (degrees, radians, -1..1, ...) depends on the sensor. + /// @note The actual unit (degrees, radians, -1..1, ...) depends on the + /// sensor. virtual float GetDirection(); - /// @brief Returns the inclination of the magnetic field relative to the horizontal plane + /// @brief Returns the inclination of the magnetic field relative to the + /// horizontal plane /// @return The direction, negative is downward, positive is upward /// @note The actual unit (degrees, radias, -1..1, ...) depends on the sensor. virtual float GetInclination(); @@ -20,4 +26,8 @@ class Magnetometer : public Sensor { /// @return The strength. This values should always be positive /// @note The actual unit (tesla, 0..1, ...) depends on the sensor. virtual unsigned float GetMagnitude(); -} \ No newline at end of file +}; + +} // namespace RoboidControl +} // namespace Passer +using namespace Passer::RoboidControl; \ No newline at end of file diff --git a/Motor.h b/Motor.h index e42fb05..f322ee9 100644 --- a/Motor.h +++ b/Motor.h @@ -3,6 +3,9 @@ #include #include "Thing.h" +namespace Passer { +namespace RoboidControl { + class Motor : public Thing { public: Motor(); @@ -23,3 +26,7 @@ class Motor : public Thing { float targetDistance = 0; time_t startTime = 0; }; + +} // namespace RoboidControl +} // namespace Passer +using namespace Passer::RoboidControl; \ No newline at end of file diff --git a/Perception.h b/Perception.h index 2158882..7390d9b 100644 --- a/Perception.h +++ b/Perception.h @@ -1,3 +1,10 @@ #include "Sensing.h" +namespace Passer { +namespace RoboidControl { + using Perception = Sensing; + +} +} // namespace Passer +using namespace Passer::RoboidControl; \ No newline at end of file diff --git a/Placement.h b/Placement.h index ecdf17b..c1d67f9 100644 --- a/Placement.h +++ b/Placement.h @@ -7,6 +7,9 @@ #include "Vector2.h" #include "Vector3.h" +namespace Passer { +namespace RoboidControl { + class Placement { public: Placement(); @@ -22,3 +25,7 @@ class Placement { Vector3 direction; Thing* thing; }; + +} // namespace RoboidControl +} // namespace Passer +using namespace Passer::RoboidControl; \ No newline at end of file diff --git a/Propulsion.h b/Propulsion.h index dad7296..53e2f68 100644 --- a/Propulsion.h +++ b/Propulsion.h @@ -6,6 +6,9 @@ #include +namespace Passer { +namespace RoboidControl { + class Propulsion { public: /// @brief Setup sensing @@ -52,3 +55,7 @@ class Propulsion { time_t startTime; float lastUpdateTime; }; + +} // namespace RoboidControl +} // namespace Passer +using namespace Passer::RoboidControl; \ No newline at end of file diff --git a/Quadcopter.h b/Quadcopter.h index 1d307b4..d5a2214 100644 --- a/Quadcopter.h +++ b/Quadcopter.h @@ -3,6 +3,9 @@ #include "Thing.h" #include "Vector3.h" +namespace Passer { +namespace RoboidControl { + class Quadcopter : public Thing { public: Quadcopter(); @@ -23,4 +26,8 @@ class Quadcopter : public Thing { float pitchSpeed = 0.0F; float yawSpeed = 0.0F; float rollSpeed = 0.0F; -}; \ No newline at end of file +}; + +} // namespace RoboidControl +} // namespace Passer +using namespace Passer::RoboidControl; \ No newline at end of file diff --git a/Roboid.cpp b/Roboid.cpp index 7bf37ef..8e33ec0 100644 --- a/Roboid.cpp +++ b/Roboid.cpp @@ -1,5 +1,6 @@ #include "Roboid.h" #include + Roboid::Roboid() { this->configuration = nullptr; this->thingCount = 0; @@ -14,7 +15,8 @@ Roboid::Roboid(Placement configuration[], unsigned int thingCount) { } bool Roboid::Drive(Waypoint* waypoint, float currentTimeMs) { - bool finished = propulsion.Drive(waypoint->point, waypoint->rotation, currentTimeMs); + bool finished = + propulsion.Drive(waypoint->point, waypoint->rotation, currentTimeMs); return finished; } diff --git a/Roboid.h b/Roboid.h index 3b10ec4..14586fa 100644 --- a/Roboid.h +++ b/Roboid.h @@ -5,6 +5,9 @@ #include "Placement.h" #include "Propulsion.h" +namespace Passer { +namespace RoboidControl { + class Waypoint { public: Waypoint(float forwardDistance, float rotation) { @@ -53,4 +56,8 @@ class Roboid { public: Trajectory* trajectory; unsigned int waypointIx = 0; -}; \ No newline at end of file +}; +} // namespace RoboidControl +} // namespace Passer + +using namespace Passer::RoboidControl; \ No newline at end of file diff --git a/Sensing.h b/Sensing.h index d8fb1a6..c8d012b 100644 --- a/Sensing.h +++ b/Sensing.h @@ -5,11 +5,12 @@ #include +namespace Passer::RoboidControl { + class DistanceSensor; class Switch; -class NewSensorPlacement : public Placement { -}; +class NewSensorPlacement : public Placement {}; struct SensorPlacement { DistanceSensor* distanceSensor; @@ -38,26 +39,30 @@ class Sensing { /// @brief Distance to the closest object on the left /// @return distance in meters, INFINITY when no object is detected. - /// @note An object is on the left when the `angle` is between -180 and 0 degrees. + /// @note An object is on the left when the `angle` is between -180 and 0 + /// degrees. /// @note An object dead straight (0 degrees) is not reported. float DistanceLeft() { return DistanceLeft(180); } /// @brief Distance to the closest object on the left /// @param angle the maximum angle on the left used for detection. /// @return distance in meters, INFINITY when no object is detected. - /// @note An object is on the left when the `angle` is between -`angle` and 0 degrees. + /// @note An object is on the left when the `angle` is between -`angle` and 0 + /// degrees. /// @note An object dead straight (0 degrees) is not reported. /// @note When an object is beyond `angle` meters, it is not reported. float DistanceLeft(float angle); /// @brief Distance to the closest object on the right /// @return distance in meters, INFINITY when no object is detected - /// @note An object is on the right when the `angle` is between 0 and 180 degrees + /// @note An object is on the right when the `angle` is between 0 and 180 + /// degrees /// @note An object dead straight (0 degrees) is not reported float DistanceRight() { return DistanceRight(180); } /// @brief Distance to the closest object on the right /// @param angle the maximum angle on the left used for detection. /// @return distance in meters, INFINITY when no object is detected - /// @note An object is on the left when the `angle` is between 0 and `angle` degrees. + /// @note An object is on the left when the `angle` is between 0 and `angle` + /// degrees. /// @note An object dead straight (0 degrees) is not reported. /// @note When an object is beyond `angle` meters, it is not reported. float DistanceRight(float angle); @@ -88,3 +93,7 @@ class Sensing { float rangeMaximum; float* depthMap = nullptr; }; + +} // namespace Passer::RoboidControl + +using namespace Passer::RoboidControl; \ No newline at end of file diff --git a/Sensor.h b/Sensor.h index 1f47259..ae81628 100644 --- a/Sensor.h +++ b/Sensor.h @@ -2,9 +2,16 @@ #include "Thing.h" +namespace Passer { +namespace RoboidControl { + /// @brief A sensor is a thing which can perform measurements in the environment class Sensor : public Thing { public: Sensor(); bool isDistanceSensor = false; -}; \ No newline at end of file +}; + +} // namespace RoboidControl +} // namespace Passer +using namespace Passer::RoboidControl; \ No newline at end of file diff --git a/Thing.h b/Thing.h index 8e0561d..0c86697 100644 --- a/Thing.h +++ b/Thing.h @@ -1,5 +1,8 @@ #pragma once +namespace Passer { +namespace RoboidControl { + /// @brief A thing is a functional component on a robot class Thing { public: @@ -13,4 +16,8 @@ class Thing { // bool isSensor; // bool isMotor; // bool isControlledMotor; -}; \ No newline at end of file +}; + +} // namespace RoboidControl +} // namespace Passer +using namespace Passer::RoboidControl; \ No newline at end of file diff --git a/VectorAlgebra b/VectorAlgebra index 493a3f7..80c89a8 160000 --- a/VectorAlgebra +++ b/VectorAlgebra @@ -1 +1 @@ -Subproject commit 493a3f748907b4fb7e64177f94b7cb98a951af4c +Subproject commit 80c89a8232aa77cabaee9f739ef6fdd3e5508260