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 {
22 std::vector<RRTNode *> orig_path_;
23 double orig_path_cost_ = 9999;
24 std::vector<RRTNode *> first_optimized_path_;
25 double first_optimized_path_cost_ = 9999;
27 std::vector<RRTNode *> first_path_optimization();
28 std::vector<RRTNode *> second_path_optimization();
29 std::vector<RRTNode *> path();
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);
165 void store_node(RRTNode n);
166 RRTNode *nn(RRTNode &t);
167 std::vector<RRTNode *> nv(RRTNode &t);
170 /*! \brief Use k-d tree data structure to store RRT nodes.
172 This approach speeds up the search process for the nearest neighbor and
173 the near vertices procedures. This extension implements 2D K-d tree.
175 \see https://en.wikipedia.org/wiki/K-d_tree
177 class RRTExt7 : public virtual RRTS {
181 RRTNode *node_ = nullptr;
182 KdNode *left_ = nullptr;
183 KdNode *right_ = nullptr;
186 RRTNode *node() const { return this->node_; }
187 KdNode *&left() { return this->left_; }
188 KdNode *&right() { return this->right_; }
191 KdNode *kdroot_ = nullptr;
192 void delete_kd_nodes(KdNode *n);
193 void store_node(RRTNode *n, KdNode *&r, int l);
194 void nn(RRTNode *&n, RRTNode &t, KdNode *r, int l, double &d);
198 void store_node(RRTNode n);
199 RRTNode *nn(RRTNode &t);
200 std::vector<RRTNode *> nv(RRTNode &t);
203 /*! \brief Reeds and Shepp cost for building and search.
205 class RRTExt6 : public virtual RRTS {
207 /*! \brief Reeds and Shepp path length.
209 double cost_build(RRTNode &f, RRTNode &t);
210 /*! \brief Reeds and Shepp path length.
212 double cost_search(RRTNode &f, RRTNode &t);
215 /*! \brief Different costs extension.
217 Use different cost for bulding tree data structure and searching in the
218 structure. This one is complementary to `rrtext1.cc`.
220 class RRTExt5 : public virtual RRTS {
222 /*! \brief Reeds and Shepp path length.
224 double cost_build(RRTNode &f, RRTNode &t);
225 /*! \brief Euclidean distance.
227 double cost_search(RRTNode &f, RRTNode &t);
230 /*! \brief Use grid data structure to store RRT nodes.
232 This approach speeds up the search process for the nearest neighbor and
233 the near vertices procedures.
235 class RRTExt4 : public virtual RRTS {
239 bool changed_ = false;
240 std::vector<RRTNode *> nodes_;
242 void nn(RRTNode *t, RRTNode **nn, RRTS *p);
243 void store_node(RRTNode *n);
248 return this->changed_;
250 std::vector<RRTNode *> &nodes()
257 Cell grid_[GRID_MAX_XI][GRID_MAX_YI]; // [0, 0] is bottom left
263 unsigned int xi(RRTNode n);
264 unsigned int yi(RRTNode n);
268 void store_node(RRTNode n);
269 RRTNode *nn(RRTNode &t);
270 std::vector<RRTNode *> nv(RRTNode &t);
273 /*! \brief Use Dijkstra algorithm to find the shorter path.
275 class RRTExt3 : public virtual RRTS {
277 std::vector<RRTNode *> orig_path_;
278 double orig_path_cost_ = 9999;
279 std::vector<RRTNode *> first_optimized_path_;
280 double first_optimized_path_cost_ = 9999;
282 std::vector<RRTNode *> first_path_optimization();
283 std::vector<RRTNode *> second_path_optimization();
284 std::vector<RRTNode *> path();
286 void json(Json::Value jvi);
289 std::vector<RRTNode *> &orig_path()
291 return this->orig_path_;
293 double &orig_path_cost() { return this->orig_path_cost_; }
294 void orig_path_cost(double c) { this->orig_path_cost_ = c; }
295 std::vector<RRTNode *> &first_optimized_path()
297 return this->first_optimized_path_;
299 double &first_optimized_path_cost() {
300 return this->first_optimized_path_cost_;
302 void first_optimized_path_cost(double c) {
303 this->first_optimized_path_cost_ = c;
307 /*! \brief Use cute_c2 for collision detection.
309 \see https://github.com/RandyGaul/cute_headers/blob/master/cute_c2.h
311 class RRTExt2 : public virtual RRTS {
315 std::vector<c2Poly> c2_obstacles_;
320 // Collide RRT procedures
321 std::tuple<bool, unsigned int, unsigned int>
322 collide_steered_from(RRTNode &f);
323 std::tuple<bool, unsigned int, unsigned int>
324 collide_tmp_steered_from(RRTNode &f);
326 std::tuple<bool, unsigned int, unsigned int>
327 collide_two_nodes(RRTNode &f, RRTNode &t);
330 c2Poly &c2_bc() { return this->c2_bc_; }
331 c2x &c2x_bc() { return this->c2x_bc_; }
332 std::vector<c2Poly> &c2_obstacles() {
333 return this->c2_obstacles_;
337 /*! \brief Different costs extension.
339 Use different cost for bulding tree data structure and searching in the
342 class RRTExt1 : public virtual RRTS {
344 /*! \brief Reeds and Shepp path length.
346 double cost_build(RRTNode &f, RRTNode &t);
347 /*! \brief Matej's heuristics.
349 double cost_search(RRTNode &f, RRTNode &t);
352 #endif /* RRTEXT_H */