2 * SPDX-FileCopyrightText: 2021 Jiri Vlasak <jiri.vlasak.2@cvut.cz>
4 * SPDX-License-Identifier: GPL-3.0-only
7 /*! \brief RRT* structure and default procedures.
16 #include <json/json.h>
24 /*! Compute elapsed time class. */
27 std::chrono::high_resolution_clock::time_point tstart_;
33 /*! Store RRT node. */
34 class RRTNode : public virtual Pose, public virtual CarMove {
38 RRTNode* p_ = nullptr;
40 /*! Get cost to parent. */
43 /*! Set cost to parent. */
46 /*! Get cumulative cost from root. */
49 /*! Get parent node. */
52 /*! Set parent node. */
55 bool operator==(RRTNode const& n);
58 class RRTGoal : public virtual RRTNode, public virtual PoseRange {
60 using PoseRange::PoseRange;
63 /*! RRT* algorithm basic class. */
68 unsigned int icnt_ = 0;
70 std::default_random_engine gen_;
71 std::vector<RRTNode> nodes_;
72 std::vector<RRTNode> steered_;
73 std::vector<RRTNode*> path_;
74 RRTNode* nn_ = nullptr;
75 std::vector<RRTNode*> nv_;
79 double last_goal_cc_ = 0.0;
80 std::vector<RRTNode> last_path_;
81 void recompute_cc(RRTNode* g);
82 void recompute_path_cc();
83 double min_gamma_eta() const;
84 bool should_continue() const;
85 void join_steered(RRTNode* f);
89 bool goal_drivable_from(RRTNode const& f);
90 virtual void store(RRTNode n);
91 virtual double cost_build(RRTNode const& f, RRTNode const& t) const;
92 virtual double cost_search(RRTNode const& f, RRTNode const& t) const;
93 virtual void find_nn(RRTNode const& t);
94 virtual void find_nv(RRTNode const& t);
95 virtual void compute_path();
96 virtual void steer(RRTNode const& f, RRTNode const& t) = 0;
97 virtual bool collide_steered() = 0;
98 virtual RRTNode sample() = 0;
99 virtual bool should_finish() const = 0;
103 /*! Get iterations counter. */
104 unsigned int icnt() const;
106 /*! Set iterations counter. */
107 void icnt(unsigned int i);
109 /*! Return elapsed time. */
112 /*! Generate JSON output. */
113 Json::Value json() const;
115 /*! Load JSON input. */
116 void json(Json::Value jvi);
118 /*! Run next RRT* iteration. */
121 /*! Reset the algorithm. */
122 virtual void reset();
126 #endif /* RRTS_RRTS_H */