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/>.
30 #include "slotplanner.h"
32 #define NOFNODES 20000
35 #define IXSTEP (1.0 * ((VMAX) - (VMIN)) / IXSIZE)
36 #define IXI(x) ({ __typeof__ (x) _x = (x); \
37 std::abs((int) floor(_x / IXSTEP)); })
39 #define IYSTEP (1.0 * ((HMAX) - (HMIN)) / IYSIZE)
40 #define IYI(y) ({ __typeof__ (y) _y = (y); \
41 std::abs((int) floor(_y / IYSTEP)); })
45 std::vector<RRTNode *> nodes_;
47 bool changed_ = false;
53 std::vector<RRTNode *> nodes();
56 void add_node(RRTNode *n);
61 RRTNode *root_ = nullptr;
62 RRTNode *goal_ = nullptr;
63 std::vector<RRTNode *> goals_;
65 std::vector<RRTNode *> nodes_;
66 std::vector<RRTNode *> dnodes_;
67 std::queue<RRTNode *> firsts_;
68 PolygonObstacle frame_;
69 std::vector<RRTNode *> samples_;
70 std::vector<CircleObstacle> *cobstacles_;
71 std::vector<SegmentObstacle> *sobstacles_;
73 bool goal_found_ = false;
74 std::chrono::high_resolution_clock::time_point tstart_;
75 std::chrono::high_resolution_clock::time_point tend_;
77 std::vector<float> clog_; // costs of trajectories
78 std::vector<float> nlog_; // #nodes of RRT
79 std::vector<std::vector<RRTEdge *>> rlog_; // log tree
80 std::vector<float> slog_; // seconds of trajectories
81 std::vector<std::vector<RRTNode *>> tlog_; // trajectories
82 std::vector<RRTNode *> slot_cusp_; // cusp nodes in slot
84 std::default_random_engine gen_;
86 const float GOAL_FOUND_DISTANCE = 0.2;
87 const float GOAL_FOUND_ANGLE = M_PI / 32;
91 RRTBase(RRTNode *init, RRTNode *goal);
96 std::vector<RRTNode *> &goals();
97 std::vector<RRTNode *> &nodes();
98 std::vector<RRTNode *> &dnodes();
99 std::queue<RRTNode *> &firsts();
100 PolygonObstacle &frame();
101 std::vector<RRTNode *> &samples();
102 std::vector<RRTNode *> iy_[IYSIZE];
103 Cell ixy_[IXSIZE][IYSIZE];
104 std::vector<CircleObstacle> *co();
105 std::vector<SegmentObstacle> *so();
106 std::vector<float> &clog();
107 std::vector<float> &nlog();
108 std::vector<std::vector<RRTEdge *>> &rlog();
109 std::vector<float> &slog();
110 std::vector<std::vector<RRTNode *>> &tlog();
111 std::vector<RRTNode *> &slot_cusp();
114 std::vector<RRTNode *> traj_cusp();
117 void root(RRTNode *node);
118 void goal(RRTNode *node);
119 void goals(std::vector<RRTNode *> g);
120 bool logr(RRTNode *root);
121 float ocost(RRTNode *n);
122 bool tlog(std::vector<RRTNode *> t);
126 std::vector<CircleObstacle> *cobstacles,
127 std::vector<SegmentObstacle> *sobstacles);
128 bool add_iy(RRTNode *n);
129 bool add_ixy(RRTNode *n);
130 bool goal_found(bool f);
131 void slot_cusp(std::vector<RRTNode *> sc);
137 float (*cost)(RRTNode *, RRTNode *));
142 bool collide(RRTNode *init, RRTNode *goal);
144 std::vector<RRTNode *> &cusps,
145 std::vector<int> &npi);
147 std::vector<RRTNode *> &cusps,
148 std::vector<int> &npi);
150 std::vector<RRTNode *> &cusps,
151 std::vector<int> &npi);
153 bool rebase(RRTNode *nr);
154 std::vector<RRTNode *> findt();
155 std::vector<RRTNode *> findt(RRTNode *n);
158 SamplingInfo samplingInfo_;
159 bool useSamplingInfo_ = false;
161 float cost(RRTNode *init, RRTNode *goal);
162 RRTNode *nn(RRTNode *rs);
163 std::vector<RRTNode *> nv(RRTNode *node, float dist);
164 std::vector<RRTNode *> steer(RRTNode *init, RRTNode *goal);
165 std::vector<RRTNode *> steer(
170 // virtuals - implemented by child classes
171 virtual bool next() = 0;