10 /*! \brief RRT node basic class.
12 \param c Cumulative cost from RRT data structure root.
13 \param p Pointer to parent RRT node.
14 \param ch The vector of pointers to children RRT nodes.
16 class RRTNode : public BicycleCar {
19 RRTNode *p_ = nullptr;
22 double c() const { return this->c_; }
23 void c(double c) { this->c_ = c; }
25 RRTNode *p() const { return this->p_; }
26 void p(RRTNode *p) { this->p_ = p; }
29 RRTNode(const BicycleCar &bc);
32 /*! \brief Polygon obstacle basic class.
34 \param poly Border polygon of the obstacle.
38 std::vector<std::tuple<double, double>> poly_;
41 std::vector<std::tuple<double, double>> &poly()
49 /*! \brief RRT* algorithm basic class.
51 \param icnt RRT algorithm iterations counter.
52 \param goals The vector of goal nodes.
53 \param nodes The vector of all nodes in RRT data structure.
54 \param samples The vector of all samples of RRT algorithm.
58 unsigned int icnt_ = 0;
59 std::chrono::high_resolution_clock::time_point tstart_;
62 std::vector<RRTNode> goals_;
63 std::vector<RRTNode> nodes_;
64 std::vector<Obstacle> obstacles_;
65 std::vector<RRTNode> samples_;
66 std::vector<RRTNode> steered_;
68 /*! \brief Update and return elapsed time.
71 /*! \brief Return ``true`` if algorithm should stop.
73 Update counters (iteration, seconds, ...) and return if
74 the current iteration should be the last one.
79 std::tuple<bool, unsigned int, unsigned int>
80 collide(std::vector<std::tuple<double, double>> &poly);
81 virtual std::tuple<bool, unsigned int, unsigned int>
82 collide_steered_from(RRTNode &f);
83 virtual std::tuple<bool, unsigned int, unsigned int>
84 collide_two_nodes(RRTNode &f, RRTNode &t);
85 virtual double cost_build(RRTNode &f, RRTNode &t);
86 virtual double cost_search(RRTNode &f, RRTNode &t);
88 std::default_random_engine gen_;
89 std::normal_distribution<double> ndx_;
90 std::normal_distribution<double> ndy_;
91 std::normal_distribution<double> ndh_;
92 RRTNode *nn(RRTNode &t);
93 std::vector<RRTNode *> nv(RRTNode &t);
94 void steer(RRTNode &f, RRTNode &t);
95 /*! \brief Join steered nodes to RRT data structure
97 \param f RRT node to join steered nodes to.
99 void join_steered(RRTNode *f);
100 bool goal_found(RRTNode &f);
105 /*! \brief Return path found by RRT*.
107 std::vector<RRTNode *> path();
108 /*! \brief Run next RRT* iteration.
111 /*! \brief Set sampling info.
113 There is normal distribution sampling for `x`, `y`, and
114 `h` parameters of RRT node.
116 \param mx Mean x value.
117 \param dx Standard deviation of x.
118 \param my Mean y value.
119 \param dy Standard deviation of y.
120 \param mh Mean h value.
121 \param dh Standard deviation of h.
124 double mx, double dx,
125 double my, double dy,
130 unsigned int icnt() const { return this->icnt_; }
131 double scnt() const { return this->scnt_; }
132 std::vector<RRTNode> &goals() { return this->goals_; }
133 std::vector<RRTNode> &nodes() { return this->nodes_; }
134 std::vector<Obstacle> &obstacles() { return this->obstacles_; }
135 std::vector<RRTNode> &samples() { return this->samples_; }
136 std::vector<RRTNode> &steered() { return this->steered_; }
141 /*! \brief Compute cumulative cost of RRT node.
143 \param t RRT node to compute cumulative cost to.
145 double cc(RRTNode &t);