]> rtime.felk.cvut.cz Git - hubacji1/iamcar.git/blob - incl/rrtbase.h
Add deleted nodes vector to RRTBase
[hubacji1/iamcar.git] / incl / rrtbase.h
1 /*
2 This file is part of I am car.
3
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.
8
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.
13
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/>.
16 */
17
18 #ifndef RRTBASE_H
19 #define RRTBASE_H
20
21 #include <chrono>
22 #include <cmath>
23 #include <vector>
24 #include "obstacle.h"
25 #include "rrtnode.h"
26
27 #define IYSIZE 200
28 #define IYSTEP 0.4
29
30 class RRTBase {
31         private:
32                 RRTNode *root_ = nullptr;
33                 RRTNode *goal_ = nullptr;
34
35                 std::vector<RRTNode *> nodes_;
36                 std::vector<RRTNode *> dnodes_;
37                 std::vector<RRTNode *> samples_;
38                 std::vector<CircleObstacle> *cobstacles_;
39                 std::vector<SegmentObstacle> *sobstacles_;
40
41                 bool goal_found_ = false;
42                 std::chrono::high_resolution_clock::time_point tstart_;
43                 std::chrono::high_resolution_clock::time_point tend_;
44
45                 std::vector<float> clog_; // costs of trajectories
46                 std::vector<float> nlog_; // #nodes of RRT
47                 std::vector<float> slog_; // seconds of trajectories
48                 std::vector<std::vector<RRTNode *>> tlog_; // trajectories
49         public:
50                 const float GOAL_FOUND_DISTANCE = 0.2;
51                 const float GOAL_FOUND_ANGLE = M_PI / 32;
52
53                 ~RRTBase();
54                 RRTBase();
55                 RRTBase(RRTNode *init, RRTNode *goal);
56
57                 // getter
58                 RRTNode *root();
59                 RRTNode *goal();
60                 std::vector<RRTNode *> &nodes();
61                 std::vector<RRTNode *> &dnodes();
62                 std::vector<RRTNode *> &samples();
63                 std::vector<RRTNode *> iy_[IYSIZE];
64                 std::vector<CircleObstacle> *cos();
65                 std::vector<SegmentObstacle> *sos();
66                 std::vector<float> &clog();
67                 std::vector<float> &nlog();
68                 std::vector<float> &slog();
69                 std::vector<std::vector<RRTNode *>> &tlog();
70                 bool goal_found();
71                 float elapsed();
72
73                 // setter
74                 bool tlog(std::vector<RRTNode *> t);
75                 void tstart();
76                 void tend();
77                 bool link_obstacles(
78                                 std::vector<CircleObstacle> *cobstacles,
79                                 std::vector<SegmentObstacle> *sobstacles);
80                 bool add_iy(RRTNode *n);
81
82                 // other
83                 bool goal_found(
84                                 RRTNode *node,
85                                 float (*cost)(RRTNode *, RRTNode *));
86                 bool collide(RRTNode *init, RRTNode *goal);
87                 std::vector<RRTNode *> findt();
88                 std::vector<RRTNode *> findt(RRTNode *n);
89
90                 // virtuals - implemented by child classes
91                 virtual bool next() = 0;
92 };
93
94 #endif