2 * SPDX-FileCopyrightText: 2021 Jiri Vlasak <jiri.vlasak.2@cvut.cz>
4 * SPDX-License-Identifier: GPL-3.0-only
7 /*! \brief RRT* extensions.
9 * The extensions are used to implement or change the default behavior of the
13 * \defgroup ext-col Collision detection extensions
14 * \defgroup ext-store Node storage and searching tree extensions
15 * \defgroup ext-cost Cost extensions
16 * \defgroup ext-opt Path optimization extensions
17 * \defgroup ext-sampl Random sampling extensions
18 * \defgroup ext-steer Steering procedure extensions
19 * \defgroup ext-aux Auxilliary extensions
30 #define GRID 1 // in meters
31 #define GRID_WIDTH 40 // in meters
32 #define GRID_HEIGHT 40 // in meters
33 #define GRID_MAX_XI ((unsigned int) floor(GRID_WIDTH / GRID)) // min is 0
34 #define GRID_MAX_YI ((unsigned int) floor(GRID_HEIGHT / GRID)) // min is 0
37 #define GRID_MAX_HI 60
41 /*! \brief Collision check based on enlarged occupancy grid.
45 class RRTExt21 : public virtual RRTS {
47 unsigned int _grid_width = 0;
48 unsigned int _grid_height = 0;
49 float _grid_res = 0.0;
50 int8_t const *_grid_data = nullptr;
51 double _origin_x = 0.0;
52 double _origin_y = 0.0;
53 bool collide(RRTNode const &n);
54 bool collide_steered();
56 void set_grid_to_check(unsigned int w, unsigned int h, float r,
57 int8_t const *d, double x, double y);
60 /*! \brief Use Dubins paths-based steering procedure.
63 * \see https://github.com/AndrewWalker/Dubins-Curves
65 class RRTExt19 : public virtual RRTS {
67 void steer(RRTNode const &f, RRTNode const &t);
70 /*! \brief Finish when more than 1000 iterations.
74 class RRTExt18 : public virtual RRTS {
76 bool should_finish() const;
79 /*! \brief Finish when goal found or more than 1000 iterations.
83 class RRTExt17 : public virtual RRTS {
85 bool should_finish() const;
88 /*! \brief Use Reeds & Shepp steering procedure.
92 class RRTExt16 : public virtual RRTS {
94 void steer(RRTNode const& f, RRTNode const& t);
97 /*! \brief Random sampling in the circuit between root and goal.
100 * \see https://stackoverflow.com/questions/5837572/generate-a-random-point-within-a-circle-uniformly/50746409#50746409
102 class RRTExt14 : public virtual RRTS {
105 double circle_r_ = 0.0;
106 std::uniform_real_distribution<double> udr_;
107 std::uniform_real_distribution<double> udt_;
108 std::uniform_real_distribution<double> udh_;
115 /*! \brief Use Dijkstra algorithm to find path between interesting nodes.
117 * The search for interesting nodes starts at root, the last drivable nodes is
118 * added to interesting nodes until goal is reached.
122 class RRTExt13 : public virtual RRTS {
126 RRTNode* node = nullptr;
131 DijkstraNode(RRTNode* n);
133 class DijkstraNodeComparator {
135 int operator() (DijkstraNode const& n1, DijkstraNode const& n2);
137 class DijkstraNodeBackwardComparator {
139 int operator() (DijkstraNode const& n1, DijkstraNode const& n2);
141 std::vector<RRTNode*> opath_;
142 double ogoal_cc_ = 0.0;
144 std::vector<DijkstraNode> dn_;
145 void interesting_forward();
146 void interesting_backward();
147 void dijkstra_forward();
148 void dijkstra_backward();
152 Json::Value json() const;
153 void json(Json::Value jvi);
157 /*! \brief Reeds & Shepp (build) and Euclidean + abs angle (search).
159 * Use Reeds & Shepp path length for building tree data structure and Euclidean
160 * distance + (abs) heading difference + 0.1 * backward-forward direction
161 * changes for searching it.
164 * \see https://doi.org/10.1109/TITS.2015.2477355
166 class RRTExt10 : public virtual RRTS {
168 double cost_build(RRTNode const& f, RRTNode const& t) const;
169 double cost_search(RRTNode const& f, RRTNode const& t) const;
172 /*! \brief Use 3D k-d tree data structure to store RRT nodes.
174 * This approach speeds up the search process for the nearest neighbor and the
175 * near vertices procedures. This extension implements 3D K-d tree.
178 * \see https://en.wikipedia.org/wiki/K-d_tree
180 class RRTExt8 : public virtual RRTS {
184 RRTNode* node = nullptr;
185 KdNode* left = nullptr;
186 KdNode* right = nullptr;
189 KdNode* kdroot_ = nullptr;
190 std::vector<KdNode> _kdnodes;
191 void store(RRTNode* n, KdNode*& ref, unsigned int lvl);
192 void find_nn(RRTNode const& t, KdNode const* const r, unsigned int lvl);
193 void find_nv(RRTNode const& t, KdNode const* const r, unsigned int lvl);
197 void store(RRTNode n);
198 void find_nn(RRTNode const& t);
199 void find_nv(RRTNode const& t);
202 /*! \brief Use cute_c2 library for collision detection.
205 * \see https://github.com/RandyGaul/cute_headers/blob/master/cute_c2.h
207 class RRTExt2 : public virtual RRTS {
211 std::vector<c2Poly> c2_obstacles_;
212 bool collide(RRTNode const& n);
213 bool collide_steered();
216 Json::Value json() const;
217 void json(Json::Value jvi);
222 #endif /* RRTS_RRTEXT_H */