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_;
85 std::normal_distribution<float> ndx_;
86 std::normal_distribution<float> ndy_;
87 std::normal_distribution<float> ndh_;
89 const float GOAL_FOUND_DISTANCE = 0.2;
90 const float GOAL_FOUND_ANGLE = M_PI / 32;
94 RRTBase(RRTNode *init, RRTNode *goal);
99 std::vector<RRTNode *> &goals();
100 std::vector<RRTNode *> &nodes();
101 std::vector<RRTNode *> &dnodes();
102 std::queue<RRTNode *> &firsts();
103 PolygonObstacle &frame();
104 std::vector<RRTNode *> &samples();
105 std::vector<RRTNode *> iy_[IYSIZE];
106 Cell ixy_[IXSIZE][IYSIZE];
107 std::vector<CircleObstacle> *co();
108 std::vector<SegmentObstacle> *so();
109 std::vector<float> &clog();
110 std::vector<float> &nlog();
111 std::vector<std::vector<RRTEdge *>> &rlog();
112 std::vector<float> &slog();
113 std::vector<std::vector<RRTNode *>> &tlog();
114 std::vector<RRTNode *> &slot_cusp();
117 std::vector<RRTNode *> traj_cusp();
120 void root(RRTNode *node);
121 void goal(RRTNode *node);
122 void goals(std::vector<RRTNode *> g);
123 bool logr(RRTNode *root);
124 float ocost(RRTNode *n);
125 bool tlog(std::vector<RRTNode *> t);
129 std::vector<CircleObstacle> *cobstacles,
130 std::vector<SegmentObstacle> *sobstacles);
131 bool add_iy(RRTNode *n);
132 bool add_ixy(RRTNode *n);
133 bool goal_found(bool f);
134 void slot_cusp(std::vector<RRTNode *> sc);
140 float (*cost)(RRTNode *, RRTNode *));
145 bool collide(RRTNode *init, RRTNode *goal);
147 std::vector<RRTNode *> &cusps,
148 std::vector<int> &npi);
150 std::vector<RRTNode *> &cusps,
151 std::vector<int> &npi);
153 std::vector<RRTNode *> &cusps,
154 std::vector<int> &npi);
156 bool rebase(RRTNode *nr);
157 std::vector<RRTNode *> findt();
158 std::vector<RRTNode *> findt(RRTNode *n);
161 void setSamplingInfo(SamplingInfo si);
163 float cost(RRTNode *init, RRTNode *goal);
164 RRTNode *nn(RRTNode *rs);
165 std::vector<RRTNode *> nv(RRTNode *node, float dist);
166 std::vector<RRTNode *> steer(RRTNode *init, RRTNode *goal);
167 std::vector<RRTNode *> steer(
172 // virtuals - implemented by child classes
173 virtual bool next() = 0;