-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrrt_star.h
66 lines (46 loc) · 1.43 KB
/
rrt_star.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef RRTSTAR_H
#define RRTSTAR_H
#include <iostream>
#include <vector>
#include <cmath>
#include <limits>
#include <cstdlib>
#include <ctime>
#include "env.h"
#include "collision.h"
// struct Point {
// double q1, q2, q3;
// };
struct Node {
State position;
Node* parent;
double cost;
std::vector<Node*> children;
Node() : position({0, 0, 0}), parent(nullptr), cost(0.0) {}
Node(State pos, Node* p = nullptr) : position(pos), parent(p), cost(0.0) {}
};
class RRTStar {
private:
CollisionChecker collisionChecker;
std::vector<Node*> nodes;
State lower_bound = State(-M_PI/2,-M_PI/2,-M_PI/2), upper_bound=State(M_PI/2,M_PI/2,M_PI/2), start, goal;
unsigned int max_iter;
double goal_max_dist;
double step_size;
double search_radius;
Node* nearest_to_goal=nullptr;
double Distance(const State &a, const State &b);
State RandomPoint();
Node* Nearest(const State &point);
State Steer(const State &nearest, const State &random_point);
std::vector<Node*> Near(const State &point);
void AttachNewNode(Node* new_node, std::vector<Node*>& near_nodes);
void Rewire(Node* new_node, std::vector<Node*>& near_nodes);
bool Reached();
public:
RRTStar( State& start, State& goal, unsigned int iter, double step, double radius, CollisionChecker &collisionChecker);
~RRTStar();
void Generate();
std::vector<State> GetPath();
};
#endif // RRTSTAR_H