9 /*! \brief RRT node basic class.
11 \param c Cumulative cost from RRT data structure root.
12 \param p Pointer to parent RRT node.
13 \param ch The vector of pointers to children RRT nodes.
15 class RRTNode : public BicycleCar {
18 RRTNode *p_ = nullptr;
21 double c() const { return this->c_; }
22 void c(double c) { this->c_ = c; }
24 RRTNode *p() const { return this->p_; }
25 void p(RRTNode *p) { this->p_ = p; }
28 RRTNode(const BicycleCar &bc);
31 /*! \brief Polygon obstacle basic class.
33 \param poly Border polygon of the obstacle.
37 std::vector<std::tuple<double, double>> poly_;
40 std::vector<std::tuple<double, double>> &poly()
48 /*! \brief RRT* algorithm basic class.
50 \param icnt RRT algorithm iterations counter.
51 \param goals The vector of goal nodes.
52 \param nodes The vector of all nodes in RRT data structure.
53 \param samples The vector of all samples of RRT algorithm.
57 unsigned int icnt_ = 0;
59 std::vector<RRTNode> goals_;
60 std::vector<RRTNode> nodes_;
61 std::vector<Obstacle> obstacles_;
62 std::vector<RRTNode> samples_;
63 std::vector<RRTNode> steered_;
66 std::tuple<bool, unsigned int, unsigned int>
67 collide(std::vector<std::tuple<double, double>> &poly);
68 virtual std::tuple<bool, unsigned int, unsigned int>
69 collide_steered_from(RRTNode &f);
70 virtual std::tuple<bool, unsigned int, unsigned int>
71 collide_two_nodes(RRTNode &f, RRTNode &t);
72 virtual double cost_build(RRTNode &f, RRTNode &t);
73 virtual double cost_search(RRTNode &f, RRTNode &t);
75 std::default_random_engine gen_;
76 std::normal_distribution<double> ndx_;
77 std::normal_distribution<double> ndy_;
78 std::normal_distribution<double> ndh_;
79 RRTNode *nn(RRTNode &t);
80 std::vector<RRTNode *> nv(RRTNode &t);
81 void steer(RRTNode &f, RRTNode &t);
82 /*! \brief Join steered nodes to RRT data structure
84 \param f RRT node to join steered nodes to.
86 void join_steered(RRTNode *f);
87 bool goal_found(RRTNode &f);
92 /*! \brief Return path found by RRT*.
94 std::vector<RRTNode *> path();
95 /*! \brief Run next RRT* iteration.
98 /*! \brief Set sampling info.
100 There is normal distribution sampling for `x`, `y`, and
101 `h` parameters of RRT node.
103 \param mx Mean x value.
104 \param dx Standard deviation of x.
105 \param my Mean y value.
106 \param dy Standard deviation of y.
107 \param mh Mean h value.
108 \param dh Standard deviation of h.
111 double mx, double dx,
112 double my, double dy,
117 std::vector<RRTNode> &goals() { return this->goals_; }
118 std::vector<RRTNode> &nodes() { return this->nodes_; }
119 std::vector<Obstacle> &obstacles() { return this->obstacles_; }
120 std::vector<RRTNode> &samples() { return this->samples_; }
121 std::vector<RRTNode> &steered() { return this->steered_; }
126 /*! \brief Compute cumulative cost of RRT node.
128 \param t RRT node to compute cumulative cost to.
130 double cc(RRTNode &t);