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"
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();
};
};
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -3,6 +3,9 @@
#include <math.h>
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

View File

@ -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;
};
};
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -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;

View File

@ -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;

View File

@ -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();
}
};
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -3,6 +3,9 @@
#include <time.h>
#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;

View File

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

View File

@ -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;

View File

@ -6,6 +6,9 @@
#include <time.h>
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;

View File

@ -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;
};
};
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -1,5 +1,6 @@
#include "Roboid.h"
#include <Arduino.h>
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;
}

View File

@ -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;
};
};
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -5,11 +5,12 @@
#include <list>
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;

View File

@ -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;
};
};
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -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;
};
};
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

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