10 /*! \brief Possible type of RRT node.
12 \param cusp The node that is cusp (change in direction).
13 \param connected The node that branches generated steered path.
17 static const unsigned int cusp = 1 << 0;
18 static const unsigned int connected = 1 << 1;
21 /*! \brief RRT node basic class.
23 \param c Cumulative cost from RRT data structure root.
24 \param p Pointer to parent RRT node.
25 \param ch The vector of pointers to children RRT nodes.
27 class RRTNode : public BicycleCar {
30 RRTNode *p_ = nullptr;
34 double c() const { return this->c_; }
35 void c(double c) { this->c_ = c; }
37 RRTNode *p() const { return this->p_; }
38 void p(RRTNode *p) { this->p_ = p; }
40 bool t(unsigned int flag) { return this->t_ & flag; }
41 void set_t(unsigned int flag) { this->t_ |= flag; }
42 void clear_t(unsigned int flag) { this->t_ &= ~flag; }
45 RRTNode(const BicycleCar &bc);
48 /*! \brief Polygon obstacle basic class.
50 \param poly Border polygon of the obstacle.
54 std::vector<std::tuple<double, double>> poly_;
57 std::vector<std::tuple<double, double>> &poly()
65 /*! \brief RRT* algorithm basic class.
67 \param icnt RRT algorithm iterations counter.
68 \param goals The vector of goal nodes.
69 \param nodes The vector of all nodes in RRT data structure.
70 \param samples The vector of all samples of RRT algorithm.
74 unsigned int icnt_ = 0;
75 std::chrono::high_resolution_clock::time_point tstart_;
79 std::vector<RRTNode> goals_;
80 std::vector<RRTNode> nodes_;
81 std::vector<Obstacle> obstacles_;
82 std::vector<RRTNode> samples_;
83 std::vector<RRTNode> steered_;
85 /*! \brief Update and return elapsed time.
88 /*! \brief Return ``true`` if algorithm should stop.
90 Update counters (iteration, seconds, ...) and return if
91 the current iteration should be the last one.
94 /*! \brief Store RRT node to tree data structure.
96 void store_node(RRTNode n);
99 std::tuple<bool, unsigned int, unsigned int>
100 collide(std::vector<std::tuple<double, double>> &poly);
101 virtual std::tuple<bool, unsigned int, unsigned int>
102 collide_steered_from(RRTNode &f);
103 virtual std::tuple<bool, unsigned int, unsigned int>
104 collide_two_nodes(RRTNode &f, RRTNode &t);
105 virtual double cost_build(RRTNode &f, RRTNode &t);
106 virtual double cost_search(RRTNode &f, RRTNode &t);
108 std::default_random_engine gen_;
109 std::normal_distribution<double> ndx_;
110 std::normal_distribution<double> ndy_;
111 std::normal_distribution<double> ndh_;
112 RRTNode *nn(RRTNode &t);
113 std::vector<RRTNode *> nv(RRTNode &t);
114 void steer(RRTNode &f, RRTNode &t);
115 /*! \brief Join steered nodes to RRT data structure
117 \param f RRT node to join steered nodes to.
119 void join_steered(RRTNode *f);
120 bool goal_found(RRTNode &f);
125 /*! \brief Initialize RRT algorithm if needed.
128 /*! \brief Deinitialize RRT algorithm if needed.
130 virtual void deinit();
131 /*! \brief Return path found by RRT*.
133 virtual std::vector<RRTNode *> path();
134 /*! \brief Run next RRT* iteration.
137 /*! \brief Set sampling info.
139 There is normal distribution sampling for `x`, `y`, and
140 `h` parameters of RRT node.
142 \param mx Mean x value.
143 \param dx Standard deviation of x.
144 \param my Mean y value.
145 \param dy Standard deviation of y.
146 \param mh Mean h value.
147 \param dh Standard deviation of h.
150 double mx, double dx,
151 double my, double dy,
156 unsigned int icnt() const { return this->icnt_; }
157 double scnt() const { return this->scnt_; }
158 bool gf() const { return this->gf_; }
159 void gf(bool f) { this->gf_ = f; }
160 std::vector<RRTNode> &goals() { return this->goals_; }
161 std::vector<RRTNode> &nodes() { return this->nodes_; }
162 std::vector<Obstacle> &obstacles() { return this->obstacles_; }
163 std::vector<RRTNode> &samples() { return this->samples_; }
164 std::vector<RRTNode> &steered() { return this->steered_; }
169 /*! \brief Compute cumulative cost of RRT node.
171 \param t RRT node to compute cumulative cost to.
173 double cc(RRTNode &t);