5#include "TinyRobotics/coordinates/Coordinate.h"
6#include "TinyRobotics/utils/AllocatorPSRAM.h"
7#include "TinyRobotics/utils/Common.h"
8#include "TinyRobotics/utils/Optional.h"
10namespace tinyrobotics {
13
14
15
16
17
18
19
20
21
22template <
typename CoordinateT>
25 CoordinateT coordinate;
26 unsigned long timestamp;
30
31
32
33
34
35
36
37
38
39template <
typename CoordinateT>
42 CoordinateT coordinate;
47
48
49
50
51
52
53
54
55
56
66 template <
typename... Args>
67 Path(
const Args&... args) {
68 addWaypoints(args...);
75 void addWaypoint(
const CoordinateT& waypoint) { waypoints.push_back(waypoint); }
78 void addWaypoints(
const std::vector<CoordinateT>& new_waypoints) {
79 waypoints.insert(waypoints.end(), new_waypoints.begin(), new_waypoints.end());
86 template <
typename First,
typename... Rest>
87 void addWaypoints(
const First& first,
const Rest&... rest) {
89 addWaypoints(rest...);
93 void setWaypoints(
const std::vector<CoordinateT>& new_waypoints) {
94 waypoints = new_waypoints;
98 bool setWaypoint(
int pos,
const CoordinateT& waypoint) {
99 if (pos >= 0 && pos < waypoints.size()) {
100 waypoints[pos] = waypoint;
107 std::vector<CoordinateT, AllocatorT>
getWaypoints()
const {
return waypoints; }
110 std::optional<CoordinateT>
getWaypoint(size_t index)
const {
111 if (index < waypoints.size()) {
112 return waypoints[index];
119 if (!waypoints.empty()) {
120 return waypoints.back();
127 if (!waypoints.empty()) {
128 waypoints.erase(waypoints.begin());
135 CoordinateT&
operator[](size_t index) {
return waypoints[index]; }
138 const CoordinateT&
operator[](size_t index)
const {
return waypoints[index]; }
141 size_t size()
const {
return waypoints.size(); }
144 bool isEmpty()
const {
return waypoints.empty(); }
147 void reverse() { std::reverse(waypoints.begin(), waypoints.end()); }
150 void clear() { waypoints.clear(); }
154 float total_distance = 0.0f;
155 for (size_t i = 1; i < waypoints.size(); ++i) {
156 total_distance += waypoints[i - 1].distance(waypoints[i]);
158 return total_distance;
162 std::vector<CoordinateT, AllocatorT> waypoints;
Custom allocator that uses ESP32's PSRAM for memory allocation.
Definition: AllocatorPSRAM.h:21
A generic 3D coordinate class for robotics, navigation, and spatial calculations.
Definition: Coordinate.h:57
A simple path class that holds a sequence of waypoints. Each waypoint is e.g. a coordinate (e....
Definition: Path.h:59
std::optional< CoordinateT > getLastWaypoint() const
Get the last waypoint (returns std::nullopt if empty)
Definition: Path.h:118
void addWaypoints()
Helper for variadic addWaypoints (base case)
Definition: Path.h:83
Path(const Args &... args)
Construct a path from a variable number of waypoints.
Definition: Path.h:67
void addWaypoint(const CoordinateT &waypoint)
Add a single waypoint to the path.
Definition: Path.h:75
void addWaypoints(const std::vector< CoordinateT > &new_waypoints)
Add multiple waypoints from a vector.
Definition: Path.h:78
size_t size() const
Get the number of waypoints.
Definition: Path.h:141
void reverse()
Reverse the order of waypoints.
Definition: Path.h:147
bool removeHead()
Remove the first waypoint in the path (e.g., after reaching it). Returns true if a waypoint was remov...
Definition: Path.h:126
std::optional< CoordinateT > getWaypoint(size_t index) const
Get a waypoint by index (returns std::nullopt if out of bounds)
Definition: Path.h:110
void setWaypoints(const std::vector< CoordinateT > &new_waypoints)
Replace all waypoints with a new vector.
Definition: Path.h:93
float distance() const
Calculate the total distance.
Definition: Path.h:153
void addWaypoints(const First &first, const Rest &... rest)
Helper for variadic addWaypoints (recursive case)
Definition: Path.h:87
Path()=default
Default constructor.
CoordinateT & operator[](size_t index)
Non-const index operator.
Definition: Path.h:135
Path(const std::vector< CoordinateT > &waypoints)
Construct a path from a vector of waypoints.
Definition: Path.h:72
bool setWaypoint(int pos, const CoordinateT &waypoint)
Set a waypoint at a specific position.
Definition: Path.h:98
void clear()
Remove all waypoints.
Definition: Path.h:150
bool isEmpty() const
Check if the path is empty.
Definition: Path.h:144
std::vector< CoordinateT, AllocatorT > getWaypoints() const
Get all waypoints as a vector.
Definition: Path.h:107
const CoordinateT & operator[](size_t index) const
Const index operator.
Definition: Path.h:138
Represents a waypoint with an associated timestamp.
Definition: Path.h:23
Represents a waypoint with an associated speed.
Definition: Path.h:40