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;
39 unsigned int cusp_ = 0;
41 /*! Get cost to parent. */
44 /*! Set cost to parent. */
47 /*! Get cumulative cost from root. */
50 /*! Get parent node. */
53 /*! Set parent node. */
56 /*! Get number of backward-forward direction changes. */
57 unsigned int cusp() const;
59 /*! Set number of backward-forward direction changes. */
60 void cusp(RRTNode const& p);
62 bool operator==(RRTNode const& n);
65 class RRTGoal : public virtual RRTNode, public virtual PoseRange {
67 using PoseRange::PoseRange;
70 /*! RRT* algorithm basic class. */
75 unsigned int icnt_ = 0;
77 std::default_random_engine gen_;
78 std::vector<RRTNode> nodes_;
79 std::vector<RRTNode> steered_;
80 std::vector<RRTNode*> path_;
81 RRTNode* nn_ = nullptr;
82 std::vector<RRTNode*> nv_;
86 double last_goal_cc_ = 0.0;
87 std::vector<RRTNode> last_path_;
88 void recompute_cc(RRTNode* g);
89 void recompute_path_cc();
90 double min_gamma_eta() const;
91 bool should_continue() const;
92 void join_steered(RRTNode* f);
96 bool goal_drivable_from(RRTNode const& f);
97 virtual void store(RRTNode n);
98 virtual double cost_build(RRTNode const& f, RRTNode const& t) const;
99 virtual double cost_search(RRTNode const& f, RRTNode const& t) const;
100 virtual void find_nn(RRTNode const& t);
101 virtual void find_nv(RRTNode const& t);
102 virtual void compute_path();
103 virtual void steer(RRTNode const& f, RRTNode const& t) = 0;
104 virtual bool collide_steered() = 0;
105 virtual RRTNode sample() = 0;
106 virtual bool should_finish() const = 0;
110 /*! Get iterations counter. */
111 unsigned int icnt() const;
113 /*! Set iterations counter. */
114 void icnt(unsigned int i);
116 /*! Return elapsed time. */
119 /*! Generate JSON output. */
120 Json::Value json() const;
122 /*! Load JSON input. */
123 void json(Json::Value jvi);
125 /*! Run next RRT* iteration. */
128 /*! Reset the algorithm. */
129 virtual void reset();
133 #endif /* RRTS_RRTS_H */