-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutoRRT.h
44 lines (34 loc) · 1.21 KB
/
AutoRRT.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef AUTORRT_H
#define AUTORRT_H
#include <Arduino.h>
#include <vector>
#include <utility>
#include <cmath>
#include <limits>
class AutoRRT {
public:
struct Node {
float x, y;
Node* parent;
Node(float x, float y, Node* parent = nullptr) : x(x), y(y), parent(parent) {}
};
AutoRRT(float startX, float startY, float goalX, float goalY, float stepSize, float goalRadius);
void setBounds(float minX, float maxX, float minY, float maxY);
void addObstacle(float x, float y, float radius);
bool planPath(size_t maxIterations);
std::vector<std::pair<float, float>> getPath() const;
private:
Node* getRandomNode();
Node* getNearestNode(Node* randomNode);
bool isCollisionFree(const Node* fromNode, const Node* toNode) const;
bool isGoalReached(const Node* node) const;
float calculateDistance(float x1, float y1, float x2, float y2) const;
Node* createNode(float x, float y, Node* parent = nullptr);
void cleanupNodes();
float startX, startY, goalX, goalY, stepSize, goalRadius;
float minX, maxX, minY, maxY;
std::vector<Node*> nodes;
std::vector<std::pair<float, float>> obstacles;
std::vector<std::pair<float, float>> path;
};
#endif