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 #include "slotplanner.h"
31 #define NOFNODES 20000
34 #define IXSTEP (1.0 * ((VMAX) - (VMIN)) / IXSIZE)
35 #define IXI(x) ({ __typeof__ (x) _x = (x); \
36 std::abs((int) floor(_x / IXSTEP)); })
38 #define IYSTEP (1.0 * ((HMAX) - (HMIN)) / IYSIZE)
39 #define IYI(y) ({ __typeof__ (y) _y = (y); \
40 std::abs((int) floor(_y / IYSTEP)); })
44 std::vector<RRTNode *> nodes_;
46 bool changed_ = false;
52 std::vector<RRTNode *> nodes();
55 void add_node(RRTNode *n);
60 RRTNode *root_ = nullptr;
61 RRTNode *goal_ = nullptr;
62 std::vector<RRTNode *> goals_;
64 std::vector<RRTNode *> nodes_;
65 std::vector<RRTNode *> dnodes_;
66 PolygonObstacle frame_;
67 std::vector<RRTNode *> samples_;
68 std::vector<CircleObstacle> *cobstacles_;
69 std::vector<SegmentObstacle> *sobstacles_;
71 bool goal_found_ = false;
72 std::chrono::high_resolution_clock::time_point tstart_;
73 std::chrono::high_resolution_clock::time_point tend_;
75 std::vector<float> clog_; // costs of trajectories
76 std::vector<float> nlog_; // #nodes of RRT
77 std::vector<std::vector<RRTEdge *>> rlog_; // log tree
78 std::vector<float> slog_; // seconds of trajectories
79 std::vector<std::vector<RRTNode *>> tlog_; // trajectories
80 std::vector<RRTNode *> slot_cusp_; // cusp nodes in slot
82 std::default_random_engine gen_;
84 const float GOAL_FOUND_DISTANCE = 0.2;
85 const float GOAL_FOUND_ANGLE = M_PI / 32;
89 RRTBase(RRTNode *init, RRTNode *goal);
94 std::vector<RRTNode *> &goals();
95 std::vector<RRTNode *> &nodes();
96 std::vector<RRTNode *> &dnodes();
97 PolygonObstacle &frame();
98 std::vector<RRTNode *> &samples();
99 std::vector<RRTNode *> iy_[IYSIZE];
100 Cell ixy_[IXSIZE][IYSIZE];
101 std::vector<CircleObstacle> *co();
102 std::vector<SegmentObstacle> *so();
103 std::vector<float> &clog();
104 std::vector<float> &nlog();
105 std::vector<std::vector<RRTEdge *>> &rlog();
106 std::vector<float> &slog();
107 std::vector<std::vector<RRTNode *>> &tlog();
108 std::vector<RRTNode *> &slot_cusp();
111 std::vector<RRTNode *> traj_cusp();
114 void root(RRTNode *node);
115 void goal(RRTNode *node);
116 void goals(std::vector<RRTNode *> g);
117 bool logr(RRTNode *root);
118 float ocost(RRTNode *n);
119 bool tlog(std::vector<RRTNode *> t);
123 std::vector<CircleObstacle> *cobstacles,
124 std::vector<SegmentObstacle> *sobstacles);
125 bool add_iy(RRTNode *n);
126 bool add_ixy(RRTNode *n);
127 bool goal_found(bool f);
128 void slot_cusp(std::vector<RRTNode *> sc);
134 float (*cost)(RRTNode *, RRTNode *));
135 bool collide(RRTNode *init, RRTNode *goal);
137 std::vector<RRTNode *> &cusps,
138 std::vector<int> &npi);
140 std::vector<RRTNode *> &cusps,
141 std::vector<int> &npi);
143 std::vector<RRTNode *> &cusps,
144 std::vector<int> &npi);
146 bool rebase(RRTNode *nr);
147 std::vector<RRTNode *> findt();
148 std::vector<RRTNode *> findt(RRTNode *n);
151 SamplingInfo samplingInfo_;
152 bool useSamplingInfo_ = false;
154 float cost(RRTNode *init, RRTNode *goal);
155 RRTNode *nn(RRTNode *rs);
156 std::vector<RRTNode *> nv(RRTNode *node, float dist);
157 std::vector<RRTNode *> steer(RRTNode *init, RRTNode *goal);
158 std::vector<RRTNode *> steer(
163 // virtuals - implemented by child classes
164 virtual bool next() = 0;