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
21 /*! \brief Random sampling in the circuit between root and goal.
23 * \see https://stackoverflow.com/questions/5837572/generate-a-random-point-within-a-circle-uniformly/50746409#50746409
25 class RRTExt14 : public virtual RRTS {
28 double circle_r_ = 0.0;
29 std::uniform_real_distribution<double> udr_;
30 std::uniform_real_distribution<double> udt_;
31 std::uniform_real_distribution<double> udh_;
38 /*! Use Dijkstra-based path optimization, goal zone for interesting nodes. */
39 class RRTExt13 : public virtual RRTS {
43 std::vector<RRTNode *> orig_path_;
44 double orig_path_cost_ = 9999;
45 std::vector<RRTNode *> first_optimized_path_;
46 double first_optimized_path_cost_ = 9999;
47 void first_path_optimization();
48 void second_path_optimization();
51 void json(Json::Value jvi);
54 std::vector<RRTNode *> &orig_path()
56 return this->orig_path_;
58 double &orig_path_cost() { return this->orig_path_cost_; }
59 void orig_path_cost(double c) { this->orig_path_cost_ = c; }
60 std::vector<RRTNode *> &first_optimized_path()
62 return this->first_optimized_path_;
64 double &first_optimized_path_cost() {
65 return this->first_optimized_path_cost_;
67 void first_optimized_path_cost(double c) {
68 this->first_optimized_path_cost_ = c;
72 /*! \brief Different `steer` procedures.
74 Use sampling in control input for `steer1`. Use R&S steering for `steer2`.
76 class RRTExt12 : public virtual RRTS {
78 void steer1(RRTNode &f, RRTNode &t);
87 class RRTExt11 : public virtual RRTS {
89 bool goal_found(RRTNode &f);
92 /*! \brief Different costs extension.
94 Use different cost for bulding tree data structure and searching in the
95 structure. The cost function is from Elbanhawi, Mohamed, Milan Simic, and Reza
96 Jazar. “Randomized Bidirectional B-Spline Parameterization Motion Planning.”
97 IEEE Transactions on Intelligent Transportation Systems 17, no. 2 (February
98 2016): 406–19. https://doi.org/10.1109/TITS.2015.2477355.
101 class RRTExt10 : public virtual RRTS {
103 /*! \brief Reeds and Shepp path length.
105 double cost_build(RRTNode &f, RRTNode &t);
106 /*! \brief Heuristics distance.
108 double cost_search(RRTNode &f, RRTNode &t);
111 /*! \brief Use grid data structure to store RRT nodes.
113 This approach speeds up the search process for the nearest neighbor and
114 the near vertices procedures.
116 class RRTExt9 : public virtual RRTS {
120 bool changed_ = false;
121 std::vector<RRTNode *> nodes_;
123 void nn(RRTNode *t, RRTNode **nn, RRTS *p);
124 void store_node(RRTNode *n);
129 return this->changed_;
131 std::vector<RRTNode *> &nodes()
138 Cell grid_[GRID_MAX_XI][GRID_MAX_YI][GRID_MAX_HI];
144 double h_max_ = 2 * M_PI;
146 unsigned int xi(RRTNode n);
147 unsigned int yi(RRTNode n);
148 unsigned int hi(RRTNode n);
152 void store_node(RRTNode n);
153 RRTNode *nn(RRTNode &t);
154 std::vector<RRTNode *> nv(RRTNode &t);
157 /*! \brief Use k-d tree data structure to store RRT nodes.
159 This approach speeds up the search process for the nearest neighbor and
160 the near vertices procedures. This extension implements 3D K-d tree.
162 \see https://en.wikipedia.org/wiki/K-d_tree
164 class RRTExt8 : public virtual RRTS {
168 RRTNode *node_ = nullptr;
169 KdNode *left_ = nullptr;
170 KdNode *right_ = nullptr;
173 RRTNode *node() const { return this->node_; }
174 KdNode *&left() { return this->left_; }
175 KdNode *&right() { return this->right_; }
178 KdNode *kdroot_ = nullptr;
179 void delete_kd_nodes(KdNode *n);
180 void store_node(RRTNode *n, KdNode *&r, int l);
181 void nn(RRTNode *&n, RRTNode &t, KdNode *r, int l, double &d);
183 std::vector<RRTNode*>& n,
190 void delete_kd_nodes()
192 this->delete_kd_nodes(this->kdroot_);
193 this->kdroot_ = nullptr;
198 void store_node(RRTNode n);
199 RRTNode *nn(RRTNode &t);
200 std::vector<RRTNode *> nv(RRTNode &t);
203 /*! \brief Use k-d tree data structure to store RRT nodes.
205 This approach speeds up the search process for the nearest neighbor and
206 the near vertices procedures. This extension implements 2D K-d tree.
208 \see https://en.wikipedia.org/wiki/K-d_tree
210 class RRTExt7 : public virtual RRTS {
214 RRTNode *node_ = nullptr;
215 KdNode *left_ = nullptr;
216 KdNode *right_ = nullptr;
219 RRTNode *node() const { return this->node_; }
220 KdNode *&left() { return this->left_; }
221 KdNode *&right() { return this->right_; }
224 KdNode *kdroot_ = nullptr;
225 void delete_kd_nodes(KdNode *n);
226 void store_node(RRTNode *n, KdNode *&r, int l);
227 void nn(RRTNode *&n, RRTNode &t, KdNode *r, int l, double &d);
231 void store_node(RRTNode n);
232 RRTNode *nn(RRTNode &t);
233 std::vector<RRTNode *> nv(RRTNode &t);
236 /*! \brief Reeds and Shepp cost for building and search.
238 class RRTExt6 : public virtual RRTS {
240 /*! \brief Reeds and Shepp path length.
242 double cost_build(RRTNode &f, RRTNode &t);
243 /*! \brief Reeds and Shepp path length.
245 double cost_search(RRTNode &f, RRTNode &t);
248 /*! \brief Different costs extension.
250 Use different cost for bulding tree data structure and searching in the
251 structure. This one is complementary to `rrtext1.cc`.
253 class RRTExt5 : public virtual RRTS {
255 /*! \brief Reeds and Shepp path length.
257 double cost_build(RRTNode &f, RRTNode &t);
258 /*! \brief Euclidean distance.
260 double cost_search(RRTNode &f, RRTNode &t);
263 /*! \brief Use grid data structure to store RRT nodes.
265 This approach speeds up the search process for the nearest neighbor and
266 the near vertices procedures.
268 class RRTExt4 : public virtual RRTS {
272 bool changed_ = false;
273 std::vector<RRTNode *> nodes_;
275 void nn(RRTNode *t, RRTNode **nn, RRTS *p);
276 void store_node(RRTNode *n);
281 return this->changed_;
283 std::vector<RRTNode *> &nodes()
290 Cell grid_[GRID_MAX_XI][GRID_MAX_YI]; // [0, 0] is bottom left
296 unsigned int xi(RRTNode n);
297 unsigned int yi(RRTNode n);
301 void store_node(RRTNode n);
302 RRTNode *nn(RRTNode &t);
303 std::vector<RRTNode *> nv(RRTNode &t);
306 /*! \brief Use Dijkstra algorithm to find the shorter path.
308 class RRTExt3 : public virtual RRTS {
312 std::vector<RRTNode *> orig_path_;
313 double orig_path_cost_ = 9999;
314 std::vector<RRTNode *> first_optimized_path_;
315 double first_optimized_path_cost_ = 9999;
316 void first_path_optimization();
317 void second_path_optimization();
320 void json(Json::Value jvi);
323 std::vector<RRTNode *> &orig_path()
325 return this->orig_path_;
327 double &orig_path_cost() { return this->orig_path_cost_; }
328 void orig_path_cost(double c) { this->orig_path_cost_ = c; }
329 std::vector<RRTNode *> &first_optimized_path()
331 return this->first_optimized_path_;
333 double &first_optimized_path_cost() {
334 return this->first_optimized_path_cost_;
336 void first_optimized_path_cost(double c) {
337 this->first_optimized_path_cost_ = c;
341 /*! \brief Use cute_c2 for collision detection.
343 \see https://github.com/RandyGaul/cute_headers/blob/master/cute_c2.h
345 class RRTExt2 : public virtual RRTS {
349 std::vector<c2Poly> c2_obstacles_;
350 bool collide(RRTNode const& n);
351 bool collide_steered();
354 Json::Value json() const;
355 void json(Json::Value jvi);
358 /*! \brief Different costs extension.
360 Use different cost for bulding tree data structure and searching in the
363 class RRTExt1 : public virtual RRTS {
365 /*! \brief Reeds and Shepp path length.
367 double cost_build(RRTNode &f, RRTNode &t);
368 /*! \brief Matej's heuristics.
370 double cost_search(RRTNode &f, RRTNode &t);
374 #endif /* RRTS_RRTEXT_H */