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/>.
23 #define IS_NEAR(a, b) ({ __typeof__ (a) _a = (a); \
24 __typeof__ (b) _b = (b); \
25 pow(pow(_b->x() - _a->x(), 2) + \
26 pow(_b->y() - _a->y(), 2), 0.5) < 0.2 && \
27 std::abs(_b->h() - _a->h()) < M_PI / 32 ? true : false; })
29 template <typename T> int sgn(T val) {
30 return (T(0) < val) - (val < T(0));
35 float dcost_ = 0; // direct cost (of edge) to parent
36 float ccost_ = 0; // cumulative cost from root
37 float ocost_ = 0; // distance to the nearest obstacle
38 char tree_ = '0'; // tree affinity
40 RRTNode *parent_ = nullptr;
41 std::vector<RRTNode *> children_;
43 bool visited_ = false; // for DFS
52 RRTNode(float x, float y);
53 RRTNode(float x, float y, float h);
54 RRTNode(float x, float y, float h, float t);
55 RRTNode(float x, float y, float h, float t, float s);
69 std::vector<RRTNode *> &children();
70 RRTNode *parent() const;
78 bool add_child(RRTNode *node, float cost);
79 bool add_child(RRTNode *node, float cost, float time);
80 bool rem_child(RRTNode *node);
82 float ccost(float cost);
83 float dcost(float cost);
84 float ocost(float cost);
88 bool parent(RRTNode *parent);
92 static bool comp_ccost(RRTNode *n1, RRTNode *n2);
103 RRTEdge(RRTNode *init, RRTNode *goal);
105 RRTNode *init() const;
106 RRTNode *goal() const;