2 This file is part of I am car.
4 I am car is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 I am car is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with I am car. If not, see <http://www.gnu.org/licenses/>.
29 #define NOFNODES 20000
32 #define IXSTEP (1.0 * ((VMAX) - (VMIN)) / IXSIZE)
33 #define IXI(x) ({ __typeof__ (x) _x = (x); \
34 (int) floor(_x / IXSTEP); })
36 #define IYSTEP (1.0 * ((HMAX) - (HMIN)) / IYSIZE)
37 #define IYI(y) ({ __typeof__ (y) _y = (y); \
38 (int) floor(_y / IYSTEP); })
42 std::vector<RRTNode *> nodes_;
44 bool changed_ = false;
50 std::vector<RRTNode *> nodes();
53 void add_node(RRTNode *n);
58 RRTNode *root_ = nullptr;
59 RRTNode *goal_ = nullptr;
61 std::vector<RRTNode *> nodes_;
62 std::vector<RRTNode *> dnodes_;
63 PolygonObstacle frame_;
64 std::vector<RRTNode *> samples_;
65 std::vector<CircleObstacle> *cobstacles_;
66 std::vector<SegmentObstacle> *sobstacles_;
68 bool goal_found_ = false;
69 std::chrono::high_resolution_clock::time_point tstart_;
70 std::chrono::high_resolution_clock::time_point tend_;
72 std::vector<float> clog_; // costs of trajectories
73 std::vector<float> nlog_; // #nodes of RRT
74 std::vector<std::vector<RRTEdge *>> rlog_; // log tree
75 std::vector<float> slog_; // seconds of trajectories
76 std::vector<std::vector<RRTNode *>> tlog_; // trajectories
78 const float GOAL_FOUND_DISTANCE = 0.2;
79 const float GOAL_FOUND_ANGLE = M_PI / 32;
83 RRTBase(RRTNode *init, RRTNode *goal);
88 std::vector<RRTNode *> &nodes();
89 std::vector<RRTNode *> &dnodes();
90 PolygonObstacle &frame();
91 std::vector<RRTNode *> &samples();
92 std::vector<RRTNode *> iy_[IYSIZE];
93 Cell ixy_[IXSIZE][IYSIZE];
94 std::vector<CircleObstacle> *co();
95 std::vector<SegmentObstacle> *so();
96 std::vector<float> &clog();
97 std::vector<float> &nlog();
98 std::vector<std::vector<RRTEdge *>> &rlog();
99 std::vector<float> &slog();
100 std::vector<std::vector<RRTNode *>> &tlog();
105 void root(RRTNode *node);
106 void goal(RRTNode *node);
107 bool logr(RRTNode *root);
108 float ocost(RRTNode *n);
109 bool tlog(std::vector<RRTNode *> t);
113 std::vector<CircleObstacle> *cobstacles,
114 std::vector<SegmentObstacle> *sobstacles);
115 bool add_iy(RRTNode *n);
116 bool add_ixy(RRTNode *n);
117 bool goal_found(bool f);
123 float (*cost)(RRTNode *, RRTNode *));
124 bool collide(RRTNode *init, RRTNode *goal);
126 std::vector<RRTNode *> &cusps,
127 std::vector<int> &npi);
129 std::vector<RRTNode *> &cusps,
130 std::vector<int> &npi);
132 std::vector<RRTNode *> &cusps,
133 std::vector<int> &npi);
135 bool rebase(RRTNode *nr);
136 std::vector<RRTNode *> findt();
137 std::vector<RRTNode *> findt(RRTNode *n);
141 float cost(RRTNode *init, RRTNode *goal);
142 RRTNode *nn(RRTNode *rs);
143 std::vector<RRTNode *> nv(RRTNode *node, float dist);
144 std::vector<RRTNode *> steer(RRTNode *init, RRTNode *goal);
145 std::vector<RRTNode *> steer(
150 // virtuals - implemented by child classes
151 virtual bool next() = 0;