10 #define GRID 1 // in meters
11 #define GRID_WIDTH 20 // in meters
12 #define GRID_HEIGHT 50 // in meters
13 #define GRID_MAX_XI ((unsigned int) floor(GRID_WIDTH / GRID)) // min is 0
14 #define GRID_MAX_YI ((unsigned int) floor(GRID_HEIGHT / GRID)) // min is 0
17 #define GRID_MAX_HI 60
19 /*! \brief Use grid data structure to store RRT nodes.
21 This approach speeds up the search process for the nearest neighbor and
22 the near vertices procedures.
24 class RRTExt9 : public virtual RRTS {
28 bool changed_ = false;
29 std::vector<RRTNode *> nodes_;
31 void nn(RRTNode *t, RRTNode **nn, RRTS *p);
32 void store_node(RRTNode *n);
37 return this->changed_;
39 std::vector<RRTNode *> &nodes()
46 Cell grid_[GRID_MAX_XI][GRID_MAX_YI][GRID_MAX_HI];
47 unsigned int x_min_ = 0;
48 unsigned int x_max_ = 0;
49 unsigned int y_min_ = 0;
50 unsigned int y_max_ = 0;
51 unsigned int h_min_ = 0;
52 unsigned int h_max_ = 2 * M_PI;
54 unsigned int xi(RRTNode n);
55 unsigned int yi(RRTNode n);
56 unsigned int hi(RRTNode n);
60 void store_node(RRTNode n);
61 RRTNode *nn(RRTNode &t);
62 std::vector<RRTNode *> nv(RRTNode &t);
65 /*! \brief Use k-d tree data structure to store RRT nodes.
67 This approach speeds up the search process for the nearest neighbor and
68 the near vertices procedures. This extension implements 3D K-d tree.
70 \see https://en.wikipedia.org/wiki/K-d_tree
72 class RRTExt8 : public virtual RRTS {
76 RRTNode *node_ = nullptr;
77 KdNode *left_ = nullptr;
78 KdNode *right_ = nullptr;
81 RRTNode *node() const { return this->node_; }
82 KdNode *&left() { return this->left_; }
83 KdNode *&right() { return this->right_; }
86 KdNode *kdroot_ = nullptr;
87 void delete_kd_nodes(KdNode *n);
88 void store_node(RRTNode *n, KdNode *&r, int l);
89 void nn(RRTNode *&n, RRTNode &t, KdNode *r, int l, double &d);
93 void store_node(RRTNode n);
94 RRTNode *nn(RRTNode &t);
95 std::vector<RRTNode *> nv(RRTNode &t);
98 /*! \brief Use k-d tree data structure to store RRT nodes.
100 This approach speeds up the search process for the nearest neighbor and
101 the near vertices procedures. This extension implements 2D K-d tree.
103 \see https://en.wikipedia.org/wiki/K-d_tree
105 class RRTExt7 : public virtual RRTS {
109 RRTNode *node_ = nullptr;
110 KdNode *left_ = nullptr;
111 KdNode *right_ = nullptr;
114 RRTNode *node() const { return this->node_; }
115 KdNode *&left() { return this->left_; }
116 KdNode *&right() { return this->right_; }
119 KdNode *kdroot_ = nullptr;
120 void delete_kd_nodes(KdNode *n);
121 void store_node(RRTNode *n, KdNode *&r, int l);
122 void nn(RRTNode *&n, RRTNode &t, KdNode *r, int l, double &d);
126 void store_node(RRTNode n);
127 RRTNode *nn(RRTNode &t);
128 std::vector<RRTNode *> nv(RRTNode &t);
131 /*! \brief Reeds and Shepp cost for building and search.
133 class RRTExt6 : public virtual RRTS {
135 /*! \brief Reeds and Shepp path length.
137 double cost_build(RRTNode &f, RRTNode &t);
138 /*! \brief Reeds and Shepp path length.
140 double cost_search(RRTNode &f, RRTNode &t);
143 /*! \brief Different costs extension.
145 Use different cost for bulding tree data structure and searching in the
146 structure. This one is complementary to `rrtext1.cc`.
148 class RRTExt5 : public virtual RRTS {
150 /*! \brief Reeds and Shepp path length.
152 double cost_build(RRTNode &f, RRTNode &t);
153 /*! \brief Euclidean distance.
155 double cost_search(RRTNode &f, RRTNode &t);
158 /*! \brief Use grid data structure to store RRT nodes.
160 This approach speeds up the search process for the nearest neighbor and
161 the near vertices procedures.
163 class RRTExt4 : public virtual RRTS {
167 bool changed_ = false;
168 std::vector<RRTNode *> nodes_;
170 void nn(RRTNode *t, RRTNode **nn, RRTS *p);
171 void store_node(RRTNode *n);
176 return this->changed_;
178 std::vector<RRTNode *> &nodes()
185 Cell grid_[GRID_MAX_XI][GRID_MAX_YI]; // [0, 0] is bottom left
186 unsigned int x_min_ = 0;
187 unsigned int x_max_ = 0;
188 unsigned int y_min_ = 0;
189 unsigned int y_max_ = 0;
191 unsigned int xi(RRTNode n);
192 unsigned int yi(RRTNode n);
196 void store_node(RRTNode n);
197 RRTNode *nn(RRTNode &t);
198 std::vector<RRTNode *> nv(RRTNode &t);
201 /*! \brief Use Dijkstra algorithm to find the shorter path.
203 class RRTExt3 : public virtual RRTS {
205 std::vector<RRTNode *> orig_path_;
206 double orig_path_cost_;
208 std::vector<RRTNode *> path();
211 std::vector<RRTNode *> &orig_path()
213 return this->orig_path_;
215 double &orig_path_cost() { return this->orig_path_cost_; }
216 void orig_path_cost(double c) { this->orig_path_cost_ = c; }
219 /*! \brief Use cute_c2 for collision detection.
221 \see https://github.com/RandyGaul/cute_headers/blob/master/cute_c2.h
223 class RRTExt2 : public virtual RRTS {
227 std::vector<c2Poly> c2_obstacles_;
232 // Collide RRT procedures
233 std::tuple<bool, unsigned int, unsigned int>
234 collide_steered_from(RRTNode &f);
236 std::tuple<bool, unsigned int, unsigned int>
237 collide_two_nodes(RRTNode &f, RRTNode &t);
240 c2Poly &c2_bc() { return this->c2_bc_; }
241 c2x &c2x_bc() { return this->c2x_bc_; }
242 std::vector<c2Poly> &c2_obstacles() {
243 return this->c2_obstacles_;
247 /*! \brief Different costs extension.
249 Use different cost for bulding tree data structure and searching in the
252 class RRTExt1 : public virtual RRTS {
254 /*! \brief Reeds and Shepp path length.
256 double cost_build(RRTNode &f, RRTNode &t);
257 /*! \brief Matej's heuristics.
259 double cost_search(RRTNode &f, RRTNode &t);
262 #endif /* RRTEXT_H */