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);
67 class RRTGoal : public virtual RRTNode, public virtual PoseRange {
69 using PoseRange::PoseRange;
72 /*! RRT* algorithm basic class. */
77 unsigned int icnt_ = 0;
78 unsigned int _imax = 1000;
80 std::default_random_engine gen_;
81 std::vector<RRTNode> nodes_;
82 std::vector<RRTNode> steered_;
83 std::vector<RRTNode*> path_;
84 RRTNode* nn_ = nullptr;
85 std::vector<RRTNode*> nv_;
89 double last_goal_cc_ = 0.0;
90 std::vector<RRTNode> last_path_;
91 void recompute_cc(RRTNode* g);
92 void recompute_path_cc();
93 double min_gamma_eta() const;
94 bool should_continue() const;
95 void join_steered(RRTNode* f);
99 bool goal_drivable_from(RRTNode const& f);
100 virtual void store(RRTNode n);
101 virtual double cost_build(RRTNode const& f, RRTNode const& t) const;
102 virtual double cost_search(RRTNode const& f, RRTNode const& t) const;
103 virtual void find_nn(RRTNode const& t);
104 virtual void find_nv(RRTNode const& t);
105 virtual void compute_path();
106 virtual void steer(RRTNode const& f, RRTNode const& t) = 0;
107 virtual bool collide_steered() = 0;
108 virtual RRTNode sample() = 0;
109 virtual bool should_finish() const = 0;
113 /*! Set internal bicycle car. */
116 /*! Set maximum number of iterations before reset. */
117 void set_imax_reset(unsigned int i);
120 void set_goal(double x, double y, double b, double e);
123 void set_start(double x, double y, double h);
126 std::vector<Pose> get_path() const;
128 /*! Get path cost. */
129 double get_path_cost() const;
131 /*! Get iterations counter. */
132 unsigned int icnt() const;
134 /*! Set iterations counter. */
135 void icnt(unsigned int i);
137 /*! Return elapsed time. */
143 /*! Generate JSON output. */
144 Json::Value json() const;
146 /*! Load JSON input. */
147 void json(Json::Value jvi);
149 /*! Run next RRT* iteration. */
152 /*! Reset the algorithm. */
153 virtual void reset();
157 #endif /* RRTS_RRTS_H */