6 WVTEST_MAIN("RRT node basic tests")
12 WVTEST_MAIN("RRT* basic tests")
15 rrts.goals().push_back(BicycleCar());
16 rrts.goals().back().x(10);
17 rrts.goals().back().y(10);
18 rrts.goals().back().h(0);
19 WVPASSEQ_DOUBLE(cc(rrts.nodes().front()), 0, 0.00001);
20 WVPASSEQ(rrts.nodes().size(), 1);
22 WVPASSLT(1, rrts.nodes().size());
23 WVPASSEQ(rrts.samples().size(), 1);
24 WVPASSEQ(rrts.goals().size(), 1);
25 rrts.set_sample(0, 10, 0, 10, 0, 2 * M_PI);
27 o.poly().push_back(std::make_tuple(5, 5));
28 o.poly().push_back(std::make_tuple(6, 5));
29 o.poly().push_back(std::make_tuple(6, 6));
30 o.poly().push_back(std::make_tuple(5, 6));
31 o.poly().push_back(std::make_tuple(5, 5));
32 rrts.obstacles().push_back(o);
33 while (rrts.next()) {}
34 WVPASS(rrts.path().size() > 0);
36 rrts.nodes().size() > 0
37 && rrts.path().size() > 0
38 && &rrts.nodes().front() == rrts.path().front()
41 rrts.goals().size() > 0
42 && rrts.path().size() > 0
43 && &rrts.goals().front() == rrts.path().back()
47 WVTEST_MAIN("goal found zone")
49 class P : public RRTS {
51 bool goal_found(RRTNode &f) {
52 return RRTS::goal_found(f);
55 double tmp_double_1 = 0;
56 double tmp_double_2 = 0;
58 p.goals().push_back(BicycleCar());
59 BicycleCar &g = p.goals().front();
60 // TODO set g.x, g.y to different values
61 // TODO set g.h to cover all 4 quadrants
66 WVPASS(p.goal_found(n)); // pass the same pose
69 n.rotate(g.ccr().x(), g.ccr().y(), -M_PI/2);
70 WVPASSEQ_DOUBLE(n.h(), g.h() - M_PI/2, 0.00001);
71 tmp_double_1 = sqrt(pow(n.x() - g.x(), 2) + pow(n.y() - g.y(), 2));
72 tmp_double_2 = std::abs(g.mtr() * 2 * sin(-M_PI/2 / 2));
73 WVPASSEQ_DOUBLE(tmp_double_1, tmp_double_2, 0.00001);
74 WVPASS(p.goal_found(n)); // pass right corner case
75 n.rotate(g.ccr().x(), g.ccr().y(), -0.01);
76 WVPASS(!p.goal_found(n)); // fail right corner case
79 n.rotate(g.ccl().x(), g.ccl().y(), M_PI/2);
80 WVPASSEQ_DOUBLE(n.h(), g.h() + M_PI/2, 0.00001);
81 tmp_double_1 = sqrt(pow(n.x() - g.x(), 2) + pow(n.y() - g.y(), 2));
82 tmp_double_2 = std::abs(g.mtr() * 2 * sin(M_PI/2 / 2));
83 WVPASSEQ_DOUBLE(tmp_double_1, tmp_double_2, 0.00001);
84 WVPASS(p.goal_found(n)); // pass left corner case
85 n.rotate(g.ccl().x(), g.ccl().y(), 0.01);
86 WVPASS(!p.goal_found(n)); // fail left corner case
89 n.sp(std::abs(g.mtr() * 2 * sin(M_PI/2 / 2)));
92 WVPASS(p.goal_found(n)); // pass forward corner case
95 WVPASS(!p.goal_found(n)); // fail forward corner case
97 for (double a = 0; a > -M_PI/2; a -= 0.01) {
99 n.rotate(g.ccr().x(), g.ccr().y(), a);
100 WVPASS(p.goal_found(n)); // pass drivable border
102 for (double a = 0; a > -M_PI/2 + 0.1; a -= 0.01) {
103 // + 0.1 -- compensate for Euclid. dist. check
105 n.x(n.x() + 0.1*cos(n.h()));
106 n.y(n.y() + 0.1*sin(n.h()));
107 n.rotate(n.ccr().x(), n.ccr().y(), a);
108 WVPASS(p.goal_found(n)); // pass near drivable border
110 for (double a = 0; a > -M_PI/2; a -= 0.01) {
112 n.x(n.x() - 0.1*cos(n.h()));
113 n.y(n.y() - 0.1*sin(n.h()));
114 n.rotate(n.ccr().x(), n.ccr().y(), a);
115 WVPASS(!p.goal_found(n)); // fail near drivable border
117 for (double a = 0; a < M_PI / 2; a += 0.01) {
119 n.rotate(g.ccl().x(), g.ccl().y(), a);
120 WVPASS(p.goal_found(n)); // pass drivable border
122 for (double a = 0; a < M_PI / 2 - 0.1; a += 0.01) {
123 // - 0.1 -- compensate for Euclid. dist. check
125 n.x(n.x() + 0.1*cos(n.h()));
126 n.y(n.y() + 0.1*sin(n.h()));
127 n.rotate(n.ccl().x(), n.ccl().y(), a);
128 WVPASS(p.goal_found(n)); // pass near drivable border
130 for (double a = 0; a < M_PI / 2; a += 0.01) {
132 n.x(n.x() - 0.1*cos(n.h()));
133 n.y(n.y() - 0.1*sin(n.h()));
134 n.rotate(n.ccl().x(), n.ccl().y(), a);
135 WVPASS(!p.goal_found(n)); // fail near drivable border
139 n.sp(std::abs(g.mtr() * 2 * sin(M_PI/2 / 2)));
143 WVPASS(p.goal_found(n)); // pass backward corner case
146 WVPASS(!p.goal_found(n)); // fail backward corner case
149 n.rotate(g.ccr().x(), g.ccr().y(), M_PI/2);
150 WVPASSEQ_DOUBLE(n.h(), g.h() + M_PI/2, 0.00001);
151 tmp_double_1 = sqrt(pow(n.x() - g.x(), 2) + pow(n.y() - g.y(), 2));
152 tmp_double_2 = std::abs(g.mtr() * 2 * sin(-M_PI/2 / 2));
153 WVPASSEQ_DOUBLE(tmp_double_1, tmp_double_2, 0.00001);
154 WVPASS(p.goal_found(n)); // pass right corner case
155 n.rotate(g.ccr().x(), g.ccr().y(), 0.01);
156 WVPASS(!p.goal_found(n)); // fail right corner case
159 n.rotate(g.ccl().x(), g.ccl().y(), -M_PI/2);
160 WVPASSEQ_DOUBLE(n.h(), g.h() - M_PI/2, 0.00001);
161 tmp_double_1 = sqrt(pow(n.x() - g.x(), 2) + pow(n.y() - g.y(), 2));
162 tmp_double_2 = std::abs(g.mtr() * 2 * sin(M_PI/2 / 2));
163 WVPASSEQ_DOUBLE(tmp_double_1, tmp_double_2, 0.00001);
164 WVPASS(p.goal_found(n)); // pass left corner case
165 n.rotate(g.ccl().x(), g.ccl().y(), -0.01);
166 WVPASS(!p.goal_found(n)); // fail left corner case
168 for (double a = 0; a < M_PI / 2; a += 0.01) {
170 n.rotate(g.ccr().x(), g.ccr().y(), a);
171 WVPASS(p.goal_found(n)); // pass drivable border
173 for (double a = 0; a < M_PI / 2 - 0.1; a += 0.01) {
174 // - 0.1 -- compensate for Euclid. dist. check
176 n.x(n.x() - 0.1*cos(n.h()));
177 n.y(n.y() - 0.1*sin(n.h()));
178 n.rotate(n.ccr().x(), n.ccr().y(), a);
179 WVPASS(p.goal_found(n)); // pass near drivable border
181 for (double a = 0; a < M_PI / 2; a += 0.01) {
183 n.x(n.x() + 0.1*cos(n.h()));
184 n.y(n.y() + 0.1*sin(n.h()));
185 n.rotate(n.ccr().x(), n.ccr().y(), a);
186 WVPASS(!p.goal_found(n)); // fail near drivable border
188 for (double a = 0; a > -M_PI/2; a -= 0.01) {
190 n.rotate(g.ccl().x(), g.ccl().y(), a);
191 WVPASS(p.goal_found(n)); // pass drivable border
193 for (double a = 0; a > -M_PI/2 + 0.1; a -= 0.01) {
194 // + 0.1 -- compensate for Euclid. dist. check
196 n.x(n.x() - 0.1*cos(n.h()));
197 n.y(n.y() - 0.1*sin(n.h()));
198 n.rotate(n.ccl().x(), n.ccl().y(), a);
199 WVPASS(p.goal_found(n)); // pass near drivable border
201 for (double a = 0; a > -M_PI/2; a -= 0.01) {
203 n.x(n.x() + 0.1*cos(n.h()));
204 n.y(n.y() + 0.1*sin(n.h()));
205 n.rotate(n.ccl().x(), n.ccl().y(), a);
206 WVPASS(!p.goal_found(n)); // fail near drivable border