Added namespaces

This commit is contained in:
Pascal Serrarens 2023-11-28 12:53:07 +01:00
parent 18f1279c95
commit 31e802b51b
17 changed files with 138 additions and 22 deletions

View File

@ -2,6 +2,9 @@
#include "Sensor.h" #include "Sensor.h"
namespace Passer {
namespace RoboidControl {
/// @brief A Sensor which can measure the magnetic field /// @brief A Sensor which can measure the magnetic field
class Accelerometer : public Sensor { class Accelerometer : public Sensor {
public: public:
@ -32,3 +35,7 @@ class Accelerometer : public Sensor {
/// @note the unity (m/s^2, 0..1) depends on the sensor. /// @note the unity (m/s^2, 0..1) depends on the sensor.
float GetAccelerationMagnitude(); float GetAccelerationMagnitude();
}; };
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -3,6 +3,9 @@
#include <math.h> #include <math.h>
namespace Passer {
namespace RoboidControl {
class Activation { class Activation {
public: public:
static float HeavisideStep(float inputValue, float bias = 0); // Range: {0,1} 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 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 #endif

View File

@ -3,6 +3,9 @@
#include "Encoder.h" #include "Encoder.h"
#include "Motor.h" #include "Motor.h"
namespace Passer {
namespace RoboidControl {
/// @brief A motor with speed control /// @brief A motor with speed control
/// It uses a feedback loop from an encoder to regulate the speed /// It uses a feedback loop from an encoder to regulate the speed
/// The speed is measured in revolutions per second. /// The speed is measured in revolutions per second.
@ -39,8 +42,7 @@ class ControlledMotor : public Thing {
float netDistance = 0; float netDistance = 0;
float startDistance = 0; float startDistance = 0;
enum Direction { Forward = 1, enum Direction { Forward = 1, Reverse = -1 };
Reverse = -1 };
Direction rotationDirection; Direction rotationDirection;
@ -48,3 +50,7 @@ class ControlledMotor : public Thing {
float targetDistance = 0; float targetDistance = 0;
float lastEncoderPosition = 0; float lastEncoderPosition = 0;
}; };
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -2,6 +2,9 @@
#include "Sensor.h" #include "Sensor.h"
namespace Passer {
namespace RoboidControl {
/// @brief A Sensor which can measure the distance to the nearest object /// @brief A Sensor which can measure the distance to the nearest object
class DistanceSensor : public Sensor { class DistanceSensor : public Sensor {
public: public:
@ -22,3 +25,7 @@ class DistanceSensor : public Sensor {
protected: protected:
float distance = 0; float distance = 0;
}; };
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -1,5 +1,8 @@
#pragma once #pragma once
namespace Passer {
namespace RoboidControl {
class Encoder { class Encoder {
public: public:
Encoder(); Encoder();
@ -14,3 +17,7 @@ class Encoder {
protected: protected:
unsigned char transitionsPerRotation; unsigned char transitionsPerRotation;
}; };
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -2,16 +2,22 @@
#include "Sensor.h" #include "Sensor.h"
namespace Passer {
namespace RoboidControl {
/// @brief A Sensor which can measure the magnetic field /// @brief A Sensor which can measure the magnetic field
class Magnetometer : public Sensor { class Magnetometer : public Sensor {
public: public:
Magnetometer(); 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 /// @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(); 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 /// @return The direction, negative is downward, positive is upward
/// @note The actual unit (degrees, radias, -1..1, ...) depends on the sensor. /// @note The actual unit (degrees, radias, -1..1, ...) depends on the sensor.
virtual float GetInclination(); virtual float GetInclination();
@ -20,4 +26,8 @@ class Magnetometer : public Sensor {
/// @return The strength. This values should always be positive /// @return The strength. This values should always be positive
/// @note The actual unit (tesla, 0..1, ...) depends on the sensor. /// @note The actual unit (tesla, 0..1, ...) depends on the sensor.
virtual unsigned float GetMagnitude(); virtual unsigned float GetMagnitude();
} };
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -3,6 +3,9 @@
#include <time.h> #include <time.h>
#include "Thing.h" #include "Thing.h"
namespace Passer {
namespace RoboidControl {
class Motor : public Thing { class Motor : public Thing {
public: public:
Motor(); Motor();
@ -23,3 +26,7 @@ class Motor : public Thing {
float targetDistance = 0; float targetDistance = 0;
time_t startTime = 0; time_t startTime = 0;
}; };
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -1,3 +1,10 @@
#include "Sensing.h" #include "Sensing.h"
namespace Passer {
namespace RoboidControl {
using Perception = Sensing; using Perception = Sensing;
}
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -7,6 +7,9 @@
#include "Vector2.h" #include "Vector2.h"
#include "Vector3.h" #include "Vector3.h"
namespace Passer {
namespace RoboidControl {
class Placement { class Placement {
public: public:
Placement(); Placement();
@ -22,3 +25,7 @@ class Placement {
Vector3 direction; Vector3 direction;
Thing* thing; Thing* thing;
}; };
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -6,6 +6,9 @@
#include <time.h> #include <time.h>
namespace Passer {
namespace RoboidControl {
class Propulsion { class Propulsion {
public: public:
/// @brief Setup sensing /// @brief Setup sensing
@ -52,3 +55,7 @@ class Propulsion {
time_t startTime; time_t startTime;
float lastUpdateTime; float lastUpdateTime;
}; };
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -3,6 +3,9 @@
#include "Thing.h" #include "Thing.h"
#include "Vector3.h" #include "Vector3.h"
namespace Passer {
namespace RoboidControl {
class Quadcopter : public Thing { class Quadcopter : public Thing {
public: public:
Quadcopter(); Quadcopter();
@ -24,3 +27,7 @@ class Quadcopter : public Thing {
float yawSpeed = 0.0F; float yawSpeed = 0.0F;
float rollSpeed = 0.0F; float rollSpeed = 0.0F;
}; };
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -1,5 +1,6 @@
#include "Roboid.h" #include "Roboid.h"
#include <Arduino.h> #include <Arduino.h>
Roboid::Roboid() { Roboid::Roboid() {
this->configuration = nullptr; this->configuration = nullptr;
this->thingCount = 0; this->thingCount = 0;
@ -14,7 +15,8 @@ Roboid::Roboid(Placement configuration[], unsigned int thingCount) {
} }
bool Roboid::Drive(Waypoint* waypoint, float currentTimeMs) { 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; return finished;
} }

View File

@ -5,6 +5,9 @@
#include "Placement.h" #include "Placement.h"
#include "Propulsion.h" #include "Propulsion.h"
namespace Passer {
namespace RoboidControl {
class Waypoint { class Waypoint {
public: public:
Waypoint(float forwardDistance, float rotation) { Waypoint(float forwardDistance, float rotation) {
@ -54,3 +57,7 @@ class Roboid {
Trajectory* trajectory; Trajectory* trajectory;
unsigned int waypointIx = 0; unsigned int waypointIx = 0;
}; };
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -5,11 +5,12 @@
#include <list> #include <list>
namespace Passer::RoboidControl {
class DistanceSensor; class DistanceSensor;
class Switch; class Switch;
class NewSensorPlacement : public Placement { class NewSensorPlacement : public Placement {};
};
struct SensorPlacement { struct SensorPlacement {
DistanceSensor* distanceSensor; DistanceSensor* distanceSensor;
@ -38,26 +39,30 @@ class Sensing {
/// @brief Distance to the closest object on the left /// @brief Distance to the closest object on the left
/// @return distance in meters, INFINITY when no object is detected. /// @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. /// @note An object dead straight (0 degrees) is not reported.
float DistanceLeft() { return DistanceLeft(180); } float DistanceLeft() { return DistanceLeft(180); }
/// @brief Distance to the closest object on the left /// @brief Distance to the closest object on the left
/// @param angle the maximum angle on the left used for detection. /// @param angle the maximum angle on the left used for detection.
/// @return distance in meters, INFINITY when no object is detected. /// @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 An object dead straight (0 degrees) is not reported.
/// @note When an object is beyond `angle` meters, it is not reported. /// @note When an object is beyond `angle` meters, it is not reported.
float DistanceLeft(float angle); float DistanceLeft(float angle);
/// @brief Distance to the closest object on the right /// @brief Distance to the closest object on the right
/// @return distance in meters, INFINITY when no object is detected /// @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 /// @note An object dead straight (0 degrees) is not reported
float DistanceRight() { return DistanceRight(180); } float DistanceRight() { return DistanceRight(180); }
/// @brief Distance to the closest object on the right /// @brief Distance to the closest object on the right
/// @param angle the maximum angle on the left used for detection. /// @param angle the maximum angle on the left used for detection.
/// @return distance in meters, INFINITY when no object is detected /// @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 An object dead straight (0 degrees) is not reported.
/// @note When an object is beyond `angle` meters, it is not reported. /// @note When an object is beyond `angle` meters, it is not reported.
float DistanceRight(float angle); float DistanceRight(float angle);
@ -88,3 +93,7 @@ class Sensing {
float rangeMaximum; float rangeMaximum;
float* depthMap = nullptr; float* depthMap = nullptr;
}; };
} // namespace Passer::RoboidControl
using namespace Passer::RoboidControl;

View File

@ -2,9 +2,16 @@
#include "Thing.h" #include "Thing.h"
namespace Passer {
namespace RoboidControl {
/// @brief A sensor is a thing which can perform measurements in the environment /// @brief A sensor is a thing which can perform measurements in the environment
class Sensor : public Thing { class Sensor : public Thing {
public: public:
Sensor(); Sensor();
bool isDistanceSensor = false; bool isDistanceSensor = false;
}; };
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -1,5 +1,8 @@
#pragma once #pragma once
namespace Passer {
namespace RoboidControl {
/// @brief A thing is a functional component on a robot /// @brief A thing is a functional component on a robot
class Thing { class Thing {
public: public:
@ -14,3 +17,7 @@ class Thing {
// bool isMotor; // bool isMotor;
// bool isControlledMotor; // bool isControlledMotor;
}; };
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

@ -1 +1 @@
Subproject commit 493a3f748907b4fb7e64177f94b7cb98a951af4c Subproject commit 80c89a8232aa77cabaee9f739ef6fdd3e5508260