10 #define GRID 1 // in meters
11 #define GRID_WIDTH 40 // in meters
12 #define GRID_HEIGHT 40 // 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 /*! Use Dijkstra-based path optimization, goal zone for interesting nodes. */
20 class RRTExt13 : public virtual RRTS {
23 std::vector<RRTNode *> orig_path_;
24 double orig_path_cost_ = 9999;
25 std::vector<RRTNode *> first_optimized_path_;
26 double first_optimized_path_cost_ = 9999;
27 void first_path_optimization();
28 void second_path_optimization();
31 void json(Json::Value jvi);
34 std::vector<RRTNode *> &orig_path()
36 return this->orig_path_;
38 double &orig_path_cost() { return this->orig_path_cost_; }
39 void orig_path_cost(double c) { this->orig_path_cost_ = c; }
40 std::vector<RRTNode *> &first_optimized_path()
42 return this->first_optimized_path_;
44 double &first_optimized_path_cost() {
45 return this->first_optimized_path_cost_;
47 void first_optimized_path_cost(double c) {
48 this->first_optimized_path_cost_ = c;
52 /*! \brief Different `steer` procedures.
54 Use sampling in control input for `steer1`. Use R&S steering for `steer2`.
56 class RRTExt12 : public virtual RRTS {
58 void steer1(RRTNode &f, RRTNode &t);
67 class RRTExt11 : public virtual RRTS {
69 bool goal_found(RRTNode &f);
72 /*! \brief Different costs extension.
74 Use different cost for bulding tree data structure and searching in the
75 structure. The cost function is from Elbanhawi, Mohamed, Milan Simic, and Reza
76 Jazar. “Randomized Bidirectional B-Spline Parameterization Motion Planning.”
77 IEEE Transactions on Intelligent Transportation Systems 17, no. 2 (February
78 2016): 406–19. https://doi.org/10.1109/TITS.2015.2477355.
81 class RRTExt10 : public virtual RRTS {
83 /*! \brief Reeds and Shepp path length.
85 double cost_build(RRTNode &f, RRTNode &t);
86 /*! \brief Heuristics distance.
88 double cost_search(RRTNode &f, RRTNode &t);
91 /*! \brief Use grid data structure to store RRT nodes.
93 This approach speeds up the search process for the nearest neighbor and
94 the near vertices procedures.
96 class RRTExt9 : public virtual RRTS {
100 bool changed_ = false;
101 std::vector<RRTNode *> nodes_;
103 void nn(RRTNode *t, RRTNode **nn, RRTS *p);
104 void store_node(RRTNode *n);
109 return this->changed_;
111 std::vector<RRTNode *> &nodes()
118 Cell grid_[GRID_MAX_XI][GRID_MAX_YI][GRID_MAX_HI];
124 double h_max_ = 2 * M_PI;
126 unsigned int xi(RRTNode n);
127 unsigned int yi(RRTNode n);
128 unsigned int hi(RRTNode n);
132 void store_node(RRTNode n);
133 RRTNode *nn(RRTNode &t);
134 std::vector<RRTNode *> nv(RRTNode &t);
137 /*! \brief Use k-d tree data structure to store RRT nodes.
139 This approach speeds up the search process for the nearest neighbor and
140 the near vertices procedures. This extension implements 3D K-d tree.
142 \see https://en.wikipedia.org/wiki/K-d_tree
144 class RRTExt8 : public virtual RRTS {
148 RRTNode *node_ = nullptr;
149 KdNode *left_ = nullptr;
150 KdNode *right_ = nullptr;
153 RRTNode *node() const { return this->node_; }
154 KdNode *&left() { return this->left_; }
155 KdNode *&right() { return this->right_; }
158 KdNode *kdroot_ = nullptr;
159 void delete_kd_nodes(KdNode *n);
160 void store_node(RRTNode *n, KdNode *&r, int l);
161 void nn(RRTNode *&n, RRTNode &t, KdNode *r, int l, double &d);
163 std::vector<RRTNode*>& n,
170 void delete_kd_nodes()
172 this->delete_kd_nodes(this->kdroot_);
173 this->kdroot_ = nullptr;
177 void store_node(RRTNode n);
178 RRTNode *nn(RRTNode &t);
179 std::vector<RRTNode *> nv(RRTNode &t);
182 /*! \brief Use k-d tree data structure to store RRT nodes.
184 This approach speeds up the search process for the nearest neighbor and
185 the near vertices procedures. This extension implements 2D K-d tree.
187 \see https://en.wikipedia.org/wiki/K-d_tree
189 class RRTExt7 : public virtual RRTS {
193 RRTNode *node_ = nullptr;
194 KdNode *left_ = nullptr;
195 KdNode *right_ = nullptr;
198 RRTNode *node() const { return this->node_; }
199 KdNode *&left() { return this->left_; }
200 KdNode *&right() { return this->right_; }
203 KdNode *kdroot_ = nullptr;
204 void delete_kd_nodes(KdNode *n);
205 void store_node(RRTNode *n, KdNode *&r, int l);
206 void nn(RRTNode *&n, RRTNode &t, KdNode *r, int l, double &d);
210 void store_node(RRTNode n);
211 RRTNode *nn(RRTNode &t);
212 std::vector<RRTNode *> nv(RRTNode &t);
215 /*! \brief Reeds and Shepp cost for building and search.
217 class RRTExt6 : public virtual RRTS {
219 /*! \brief Reeds and Shepp path length.
221 double cost_build(RRTNode &f, RRTNode &t);
222 /*! \brief Reeds and Shepp path length.
224 double cost_search(RRTNode &f, RRTNode &t);
227 /*! \brief Different costs extension.
229 Use different cost for bulding tree data structure and searching in the
230 structure. This one is complementary to `rrtext1.cc`.
232 class RRTExt5 : public virtual RRTS {
234 /*! \brief Reeds and Shepp path length.
236 double cost_build(RRTNode &f, RRTNode &t);
237 /*! \brief Euclidean distance.
239 double cost_search(RRTNode &f, RRTNode &t);
242 /*! \brief Use grid data structure to store RRT nodes.
244 This approach speeds up the search process for the nearest neighbor and
245 the near vertices procedures.
247 class RRTExt4 : public virtual RRTS {
251 bool changed_ = false;
252 std::vector<RRTNode *> nodes_;
254 void nn(RRTNode *t, RRTNode **nn, RRTS *p);
255 void store_node(RRTNode *n);
260 return this->changed_;
262 std::vector<RRTNode *> &nodes()
269 Cell grid_[GRID_MAX_XI][GRID_MAX_YI]; // [0, 0] is bottom left
275 unsigned int xi(RRTNode n);
276 unsigned int yi(RRTNode n);
280 void store_node(RRTNode n);
281 RRTNode *nn(RRTNode &t);
282 std::vector<RRTNode *> nv(RRTNode &t);
285 /*! \brief Use Dijkstra algorithm to find the shorter path.
287 class RRTExt3 : public virtual RRTS {
290 std::vector<RRTNode *> orig_path_;
291 double orig_path_cost_ = 9999;
292 std::vector<RRTNode *> first_optimized_path_;
293 double first_optimized_path_cost_ = 9999;
294 void first_path_optimization();
295 void second_path_optimization();
298 void json(Json::Value jvi);
301 std::vector<RRTNode *> &orig_path()
303 return this->orig_path_;
305 double &orig_path_cost() { return this->orig_path_cost_; }
306 void orig_path_cost(double c) { this->orig_path_cost_ = c; }
307 std::vector<RRTNode *> &first_optimized_path()
309 return this->first_optimized_path_;
311 double &first_optimized_path_cost() {
312 return this->first_optimized_path_cost_;
314 void first_optimized_path_cost(double c) {
315 this->first_optimized_path_cost_ = c;
319 /*! \brief Use cute_c2 for collision detection.
321 \see https://github.com/RandyGaul/cute_headers/blob/master/cute_c2.h
323 class RRTExt2 : public virtual RRTS {
327 std::vector<c2Poly> c2_obstacles_;
332 // Collide RRT procedures
333 std::tuple<bool, unsigned int, unsigned int>
334 collide_steered_from(RRTNode &f);
335 std::tuple<bool, unsigned int, unsigned int>
336 collide_tmp_steered_from(RRTNode &f);
338 std::tuple<bool, unsigned int, unsigned int>
339 collide_two_nodes(RRTNode &f, RRTNode &t);
342 c2Poly &c2_bc() { return this->c2_bc_; }
343 c2x &c2x_bc() { return this->c2x_bc_; }
344 std::vector<c2Poly> &c2_obstacles() {
345 return this->c2_obstacles_;
349 /*! \brief Different costs extension.
351 Use different cost for bulding tree data structure and searching in the
354 class RRTExt1 : public virtual RRTS {
356 /*! \brief Reeds and Shepp path length.
358 double cost_build(RRTNode &f, RRTNode &t);
359 /*! \brief Matej's heuristics.
361 double cost_search(RRTNode &f, RRTNode &t);
364 #endif /* RRTEXT_H */