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_;
63 std::vector<RRTNode> goals_;
64 std::vector<RRTNode> nodes_;
65 std::vector<Obstacle> obstacles_;
66 std::vector<RRTNode> samples_;
67 std::vector<RRTNode> steered_;
69 /*! \brief Update and return elapsed time.
72 /*! \brief Return ``true`` if algorithm should stop.
74 Update counters (iteration, seconds, ...) and return if
75 the current iteration should be the last one.
80 std::tuple<bool, unsigned int, unsigned int>
81 collide(std::vector<std::tuple<double, double>> &poly);
82 virtual std::tuple<bool, unsigned int, unsigned int>
83 collide_steered_from(RRTNode &f);
84 virtual std::tuple<bool, unsigned int, unsigned int>
85 collide_two_nodes(RRTNode &f, RRTNode &t);
86 virtual double cost_build(RRTNode &f, RRTNode &t);
87 virtual double cost_search(RRTNode &f, RRTNode &t);
89 std::default_random_engine gen_;
90 std::normal_distribution<double> ndx_;
91 std::normal_distribution<double> ndy_;
92 std::normal_distribution<double> ndh_;
93 RRTNode *nn(RRTNode &t);
94 std::vector<RRTNode *> nv(RRTNode &t);
95 void steer(RRTNode &f, RRTNode &t);
96 /*! \brief Join steered nodes to RRT data structure
98 \param f RRT node to join steered nodes to.
100 void join_steered(RRTNode *f);
101 bool goal_found(RRTNode &f);
106 /*! \brief Return path found by RRT*.
108 std::vector<RRTNode *> path();
109 /*! \brief Run next RRT* iteration.
112 /*! \brief Set sampling info.
114 There is normal distribution sampling for `x`, `y`, and
115 `h` parameters of RRT node.
117 \param mx Mean x value.
118 \param dx Standard deviation of x.
119 \param my Mean y value.
120 \param dy Standard deviation of y.
121 \param mh Mean h value.
122 \param dh Standard deviation of h.
125 double mx, double dx,
126 double my, double dy,
131 unsigned int icnt() const { return this->icnt_; }
132 double scnt() const { return this->scnt_; }
133 bool gf() const { return this->gf_; }
134 void gf(bool f) { this->gf_ = f; }
135 std::vector<RRTNode> &goals() { return this->goals_; }
136 std::vector<RRTNode> &nodes() { return this->nodes_; }
137 std::vector<Obstacle> &obstacles() { return this->obstacles_; }
138 std::vector<RRTNode> &samples() { return this->samples_; }
139 std::vector<RRTNode> &steered() { return this->steered_; }
144 /*! \brief Compute cumulative cost of RRT node.
146 \param t RRT node to compute cumulative cost to.
148 double cc(RRTNode &t);