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 class RRTExt16 : public virtual RRTS {
23 void steer(RRTNode const& f, RRTNode const& t);
26 class RRTExt15 : public virtual RRTS {
28 std::vector<double> log_path_cost_;
30 Json::Value json() const;
31 void json(Json::Value jvi);
35 /*! \brief Random sampling in the circuit between root and goal.
37 * \see https://stackoverflow.com/questions/5837572/generate-a-random-point-within-a-circle-uniformly/50746409#50746409
39 class RRTExt14 : public virtual RRTS {
42 double circle_r_ = 0.0;
43 std::uniform_real_distribution<double> udr_;
44 std::uniform_real_distribution<double> udt_;
45 std::uniform_real_distribution<double> udh_;
52 /*! Use Dijkstra-based path optimization, goal zone for interesting nodes. */
53 class RRTExt13 : public virtual RRTS {
57 RRTNode* node = nullptr;
61 DijkstraNode(RRTNode* n);
63 class DijkstraNodeComparator {
65 int operator() (DijkstraNode const& n1, DijkstraNode const& n2);
67 std::vector<RRTNode*> opath_;
68 double ogoal_cc_ = 0.0;
70 std::vector<DijkstraNode> dn_;
71 void pick_interesting();
72 void dijkstra_forward();
73 void dijkstra_backward();
77 Json::Value json() const;
78 void json(Json::Value jvi);
82 /*! \brief Different `steer` procedures.
84 Use sampling in control input for `steer1`. Use R&S steering for `steer2`.
86 class RRTExt12 : public virtual RRTS {
88 void steer1(RRTNode &f, RRTNode &t);
97 class RRTExt11 : public virtual RRTS {
99 bool goal_found(RRTNode &f);
102 /*! \brief Different costs extension.
104 * Use different cost for bulding tree data structure and searching in the
105 * structure. The cost function is from Elbanhawi, Mohamed, Milan Simic, and
106 * Reza Jazar. “Randomized Bidirectional B-Spline Parameterization Motion
107 * Planning.” IEEE Transactions on Intelligent Transportation Systems 17, no. 2
108 * (February 2016): 406–19. https://doi.org/10.1109/TITS.2015.2477355.
110 class RRTExt10 : public virtual RRTS {
112 double cost_build(RRTNode const& f, RRTNode const& t) const;
113 double cost_search(RRTNode const& f, RRTNode const& t) const;
116 /*! \brief Use grid data structure to store RRT nodes.
118 This approach speeds up the search process for the nearest neighbor and
119 the near vertices procedures.
121 class RRTExt9 : public virtual RRTS {
125 bool changed_ = false;
126 std::vector<RRTNode *> nodes_;
128 void nn(RRTNode *t, RRTNode **nn, RRTS *p);
129 void store_node(RRTNode *n);
134 return this->changed_;
136 std::vector<RRTNode *> &nodes()
143 Cell grid_[GRID_MAX_XI][GRID_MAX_YI][GRID_MAX_HI];
149 double h_max_ = 2 * M_PI;
151 unsigned int xi(RRTNode n);
152 unsigned int yi(RRTNode n);
153 unsigned int hi(RRTNode n);
157 void store_node(RRTNode n);
158 RRTNode *nn(RRTNode &t);
159 std::vector<RRTNode *> nv(RRTNode &t);
162 /*! \brief Use k-d tree data structure to store RRT nodes.
164 * This approach speeds up the search process for the nearest neighbor and the
165 * near vertices procedures. This extension implements 3D K-d tree.
167 * \see https://en.wikipedia.org/wiki/K-d_tree
169 class RRTExt8 : public virtual RRTS {
173 RRTNode* node = nullptr;
174 KdNode* left = nullptr;
175 KdNode* right = nullptr;
178 KdNode* kdroot_ = nullptr;
179 std::vector<KdNode> kdnodes_;
180 void store(RRTNode* n, KdNode*& ref, unsigned int lvl);
181 void find_nn(RRTNode const& t, KdNode const* const r, unsigned int lvl);
182 void find_nv(RRTNode const& t, KdNode const* const r, unsigned int lvl);
186 void store(RRTNode n);
187 void find_nn(RRTNode const& t);
188 void find_nv(RRTNode const& t);
191 /*! \brief Use k-d tree data structure to store RRT nodes.
193 This approach speeds up the search process for the nearest neighbor and
194 the near vertices procedures. This extension implements 2D K-d tree.
196 \see https://en.wikipedia.org/wiki/K-d_tree
198 class RRTExt7 : public virtual RRTS {
202 RRTNode *node_ = nullptr;
203 KdNode *left_ = nullptr;
204 KdNode *right_ = nullptr;
207 RRTNode *node() const { return this->node_; }
208 KdNode *&left() { return this->left_; }
209 KdNode *&right() { return this->right_; }
212 KdNode *kdroot_ = nullptr;
213 void delete_kd_nodes(KdNode *n);
214 void store_node(RRTNode *n, KdNode *&r, int l);
215 void nn(RRTNode *&n, RRTNode &t, KdNode *r, int l, double &d);
219 void store_node(RRTNode n);
220 RRTNode *nn(RRTNode &t);
221 std::vector<RRTNode *> nv(RRTNode &t);
224 /*! \brief Reeds and Shepp cost for building and search.
226 class RRTExt6 : public virtual RRTS {
228 /*! \brief Reeds and Shepp path length.
230 double cost_build(RRTNode &f, RRTNode &t);
231 /*! \brief Reeds and Shepp path length.
233 double cost_search(RRTNode &f, RRTNode &t);
236 /*! \brief Different costs extension.
238 Use different cost for bulding tree data structure and searching in the
239 structure. This one is complementary to `rrtext1.cc`.
241 class RRTExt5 : public virtual RRTS {
243 /*! \brief Reeds and Shepp path length.
245 double cost_build(RRTNode &f, RRTNode &t);
246 /*! \brief Euclidean distance.
248 double cost_search(RRTNode &f, RRTNode &t);
251 /*! \brief Use grid data structure to store RRT nodes.
253 This approach speeds up the search process for the nearest neighbor and
254 the near vertices procedures.
256 class RRTExt4 : public virtual RRTS {
260 bool changed_ = false;
261 std::vector<RRTNode *> nodes_;
263 void nn(RRTNode *t, RRTNode **nn, RRTS *p);
264 void store_node(RRTNode *n);
269 return this->changed_;
271 std::vector<RRTNode *> &nodes()
278 Cell grid_[GRID_MAX_XI][GRID_MAX_YI]; // [0, 0] is bottom left
284 unsigned int xi(RRTNode n);
285 unsigned int yi(RRTNode n);
289 void store_node(RRTNode n);
290 RRTNode *nn(RRTNode &t);
291 std::vector<RRTNode *> nv(RRTNode &t);
294 /*! \brief Use Dijkstra algorithm to find the shorter path.
296 class RRTExt3 : public virtual RRTS {
300 std::vector<RRTNode *> orig_path_;
301 double orig_path_cost_ = 9999;
302 std::vector<RRTNode *> first_optimized_path_;
303 double first_optimized_path_cost_ = 9999;
304 void first_path_optimization();
305 void second_path_optimization();
308 void json(Json::Value jvi);
311 std::vector<RRTNode *> &orig_path()
313 return this->orig_path_;
315 double &orig_path_cost() { return this->orig_path_cost_; }
316 void orig_path_cost(double c) { this->orig_path_cost_ = c; }
317 std::vector<RRTNode *> &first_optimized_path()
319 return this->first_optimized_path_;
321 double &first_optimized_path_cost() {
322 return this->first_optimized_path_cost_;
324 void first_optimized_path_cost(double c) {
325 this->first_optimized_path_cost_ = c;
329 /*! \brief Use cute_c2 for collision detection.
331 \see https://github.com/RandyGaul/cute_headers/blob/master/cute_c2.h
333 class RRTExt2 : public virtual RRTS {
337 std::vector<c2Poly> c2_obstacles_;
338 bool collide(RRTNode const& n);
339 bool collide_steered();
342 Json::Value json() const;
343 void json(Json::Value jvi);
346 /*! \brief Different costs extension.
348 Use different cost for bulding tree data structure and searching in the
351 class RRTExt1 : public virtual RRTS {
353 /*! \brief Reeds and Shepp path length.
355 double cost_build(RRTNode &f, RRTNode &t);
356 /*! \brief Matej's heuristics.
358 double cost_search(RRTNode &f, RRTNode &t);
362 #endif /* RRTS_RRTEXT_H */