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/>.
31 #include "slotplanner.h"
33 #define NOFNODES 20000
36 #define IXSTEP (1.0 * ((HMAX) - (HMIN)) / IXSIZE)
37 #define IXI(x) ({ __typeof__ (x) _x = (x); \
38 std::abs((int) floor(_x / IXSTEP)); })
40 #define IYSTEP (1.0 * ((VMAX) - (VMIN)) / IYSIZE)
42 __typeof__ (y) _y = (y); \
43 (int) floor((_y - VMIN) / IYSTEP); \
48 std::vector<RRTNode *> nodes_;
50 bool changed_ = false;
56 std::vector<RRTNode *> nodes();
59 void add_node(RRTNode *n);
64 RRTNode *root_ = nullptr;
65 RRTNode *goal_ = nullptr;
66 std::vector<RRTNode *> goals_;
68 std::vector<RRTNode *> nodes_;
69 std::vector<RRTNode *> dnodes_;
70 std::queue<RRTNode *> firsts_;
71 PolygonObstacle frame_;
72 std::vector<RRTNode *> samples_;
73 std::vector<CircleObstacle> *cobstacles_;
74 std::vector<SegmentObstacle> *sobstacles_;
76 bool goal_found_ = false;
77 std::chrono::high_resolution_clock::time_point tstart_;
78 std::chrono::high_resolution_clock::time_point tend_;
80 std::vector<float> clog_; // costs of trajectories
81 std::vector<float> nlog_; // #nodes of RRT
82 std::vector<std::vector<RRTEdge *>> rlog_; // log tree
83 std::vector<float> slog_; // seconds of trajectories
84 std::vector<std::vector<RRTNode *>> tlog_; // trajectories
85 std::vector<RRTNode *> slot_cusp_; // cusp nodes in slot
87 std::default_random_engine gen_;
88 std::normal_distribution<float> ndx_;
89 std::normal_distribution<float> ndy_;
90 std::normal_distribution<float> ndh_;
92 const float GOAL_FOUND_DISTANCE = 0.2;
93 const float GOAL_FOUND_ANGLE = M_PI / 32;
101 RRTBase(RRTNode *init, RRTNode *goal);
106 std::vector<RRTNode *> &goals();
107 std::vector<RRTNode *> &nodes();
108 std::vector<RRTNode *> &dnodes();
109 std::queue<RRTNode *> &firsts();
110 PolygonObstacle &frame();
111 std::vector<RRTNode *> &samples();
112 std::array<std::vector<RRTNode *>, IYSIZE> iy_;
113 Cell ixy_[IXSIZE][IYSIZE];
114 std::vector<CircleObstacle> *co();
115 std::vector<SegmentObstacle> *so();
116 std::vector<float> &clog();
117 std::vector<float> &nlog();
118 std::vector<std::vector<RRTEdge *>> &rlog();
119 std::vector<float> &slog();
120 std::vector<std::vector<RRTNode *>> &tlog();
121 std::vector<RRTNode *> &slot_cusp();
124 std::vector<RRTNode *> traj_cusp();
127 void root(RRTNode *node);
128 void goal(RRTNode *node);
129 void goals(std::vector<RRTNode *> g);
130 bool logr(RRTNode *root);
131 float ocost(RRTNode *n);
132 bool tlog(std::vector<RRTNode *> t);
136 std::vector<CircleObstacle> *cobstacles,
137 std::vector<SegmentObstacle> *sobstacles);
138 bool add_iy(RRTNode *n);
139 bool add_ixy(RRTNode *n);
140 bool goal_found(bool f);
141 void slot_cusp(std::vector<RRTNode *> sc);
147 float (*cost)(RRTNode *, RRTNode *));
152 bool collide(RRTNode *init, RRTNode *goal);
154 std::vector<RRTNode *> &cusps,
155 std::vector<int> &npi);
157 std::vector<RRTNode *> &cusps,
158 std::vector<int> &npi);
160 std::vector<RRTNode *> &cusps,
161 std::vector<int> &npi);
163 bool rebase(RRTNode *nr);
164 std::vector<RRTNode *> findt();
165 std::vector<RRTNode *> findt(RRTNode *n);
166 float XI(RRTNode *n);
167 float YI(RRTNode *n);
170 void setSamplingInfo(SamplingInfo si);
172 float cost(RRTNode *init, RRTNode *goal);
173 RRTNode *nn(RRTNode *rs);
174 std::vector<RRTNode *> nv(RRTNode *node, float dist);
175 std::vector<RRTNode *> steer(RRTNode *init, RRTNode *goal);
176 std::vector<RRTNode *> steer(
181 // virtuals - implemented by child classes
182 virtual bool next() = 0;