-
Notifications
You must be signed in to change notification settings - Fork 0
/
WaypointNavigationTest.cpp
349 lines (307 loc) · 12.9 KB
/
WaypointNavigationTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#include "WaypointNavigationTest.hpp"
#include "WaypointNavigation.hpp"
#include <Eigen/Geometry>
#include <iostream>
using namespace Eigen;
using namespace waypoint_navigation_lib;
int main() {
WaypointNavigation pathTracker;
base::Waypoint lpoint;
base::commands::Motion2D mc;
// = = = Robot = = =
base::samples::RigidBodyState robotPose;
robotPose.cov_position = Eigen::Matrix3d::Identity() * 0.001;
robotPose.orientation.setIdentity();
robotPose.position = Eigen::Vector3d(0,0,0);
pathTracker.setPose(robotPose);
//
std::cout << "Test PT" << std::endl;
lpoint.heading = 45.0/180.0*M_PI;
lpoint.position = Eigen::Vector3d(1,1,0);
lpoint.tol_position = 0.1;
pathTracker.setLookaheadPoint(lpoint);
pathTracker.getMovementCommand(mc);
std::cout << "tv = " << mc.translation;
std::cout << ", rv = " << mc.rotation << std::endl << std::endl;
std::cout << "Test Ackermann" << std::endl;
lpoint.heading = 10.0/180.0*M_PI;
lpoint.position = Eigen::Vector3d(1,0.1,0);
lpoint.tol_position = 0.1;
pathTracker.setLookaheadPoint(lpoint);
pathTracker.getMovementCommand(mc);
std::cout << "tv = " << mc.translation;
std::cout << ", rv = " << mc.rotation << std::endl << std::endl;
std::cout << "Test Trajectory" << std::endl;
robotPose.orientation
= Eigen::Quaterniond( Eigen::AngleAxisd(10.0/180.0*M_PI, Eigen::Vector3d::UnitZ()));
pathTracker.setPose(robotPose);
uint N = 3;
std::vector<base::Waypoint> trajectory(N);
std::vector<base::Waypoint*> ptrajectory(N);
for (size_t i = 0; i < N; i++)
{
trajectory.at(i).position = Eigen::Vector3d(i+1.0,.5,0);
trajectory.at(i).heading = 15.0/180.0*M_PI;
trajectory.at(i).tol_position = 0.1;
trajectory.at(i).tol_heading = 5.0 /180*M_PI;
ptrajectory.at(i) = &trajectory.at(i);
//trajectory.push_back(lpoint);
}
std::cout << "Trajectory created" << std::endl;
pathTracker.setTrajectory(ptrajectory);
std::cout << "Trajectory set" << std::endl;
pathTracker.setNavigationState(DRIVING);
std::cout << "Robot = (" << robotPose.position.x() <<","
<< robotPose.position.y() <<","
<< robotPose.position.z() <<")"
<< "yaw = " << robotPose.getYaw()*180/M_PI << "deg." << std::endl;
while(pathTracker.getNavigationState() != TARGET_REACHED ){
// = = = Get motion commands = = =
pathTracker.update(mc);
/*
std::cout << "tv = " << mc.translation;
std::cout << ", rv = " << mc.rotation << std::endl;
*/
// = = = Simulate motion commands = = =
double dt = 0.1;
double yaw = robotPose.getYaw();
Eigen::AngleAxisd toWCF, robotRot;
toWCF = Eigen::AngleAxisd(yaw, Eigen::Vector3d::UnitZ());
if ( fabs(mc.translation) < 0.000001 ){
// Point turn
//std::cout << "PT of " << (mc.rotation*dt)*180/M_PI << "deg" << std::endl;
robotRot = AngleAxisd(mc.rotation*dt, Eigen::Vector3d::UnitZ());
robotPose.orientation = Eigen::Quaterniond(robotRot) * robotPose.orientation;
} else if ( fabs(mc.rotation) < 0.000001){
// Straight line
//std::cout << "SL" << std::endl;
robotPose.position += (mc.translation*dt)*(toWCF*Eigen::Vector3d::UnitX());
} else {
// Ackermann
// std::cout << "ACK" << std::endl;
Eigen::Vector3d turnCenter;
turnCenter << 0.0, mc.translation/mc.rotation, 0.0;
turnCenter = toWCF*(turnCenter) + robotPose.position;
robotRot = AngleAxisd(mc.rotation*dt, Eigen::Vector3d::UnitZ());
robotPose.position = robotRot*(robotPose.position - turnCenter) + turnCenter;
robotPose.orientation = Eigen::Quaterniond(robotRot)*robotPose.orientation;
}
std::cout << "Robot = (" << robotPose.position.x() <<","
<< robotPose.position.y() <<","
<< robotPose.position.z() <<"), "
<< "yaw = "<< robotPose.getYaw()*180/M_PI << " deg."
<< std::endl << std::endl;
pathTracker.setPose(robotPose);
}
robotPose.position = Eigen::Vector3d(1.5, 0.0, 0);
pathTracker.setPose(robotPose);
pathTracker.setNavigationState(OUT_OF_BOUNDARIES);
// Confuse the segment ;)
pathTracker.setCurrentSegment(1);
std::cout<< "-------------------------------------" << std::endl
<< "Lost segment test (set to previous by mistake)" << std::endl
<< std::endl;
for (int i = 0; i < 3; i++){
pathTracker.update(mc);
}
}
/*
double tv, rv;
std::cout << "----- Orientation tests" << std::endl << std::endl;
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
std::cout << "----- Orientation test 2 " << std::endl << std::endl;
robotPose.orientation = Eigen::Quaterniond(Eigen::AngleAxisd(0.0/180*M_PI, Eigen::Vector3d::UnitZ()));;
targetPose.heading = 85.0/180.0*M_PI;
robotPose.position = Eigen::Vector3d(0,0,0);
targetPose.position = Eigen::Vector3d(1,1,0);
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
// NEW tests
//test case target in front of robot
std::cout << "----- FWD TEST" << std::endl << std::endl;
robotPose.orientation.setIdentity();
targetPose.heading = 0;
robotPose.position = Eigen::Vector3d(0,0,0);
targetPose.position = Eigen::Vector3d(1,0,0);
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
assert(tv > 0 && fabs(rv) < 0.001);
std::cout << "Test 1 PASSED" << std::endl << std::endl;
// NEW tests
//test case target in front of robot
std::cout << "----- BWD TEST" << std::endl << std::endl;
robotPose.orientation.setIdentity();
targetPose.heading = 0;
robotPose.position = Eigen::Vector3d(0,0,0);
targetPose.position = Eigen::Vector3d(-1,0,0);
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
assert(tv < 0 && fabs(rv) < 0.001);
std::cout << "Test 2 PASSED" << std::endl << std::endl;
robotPose.orientation.setIdentity();
robotPose.position = Eigen::Vector3d(0,0,0);
targetPose.heading = 0;
// Ackermann to 1st Quadrant
std::cout << "----- ACKERMANN 1q" << std::endl << std::endl;
targetPose.heading = 80.0/180.0*M_PI;
targetPose.position = Eigen::Vector3d(1,1,0);
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
assert(tv > 0 && rv > 0);
std::cout << "Test 3.1 (1st Q Ackermann) PASSED" << std::endl << std::endl;
// Ackermann to 2st Quadrant
std::cout << "----- ACKERMANN 2q" << std::endl << std::endl;
targetPose.heading = - 80/180.0*M_PI;
targetPose.position = Eigen::Vector3d(-1,1,0);
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
assert(tv < 0 && rv < 0);
std::cout << "Test 3.2 (2nd Q Ackermann) PASSED" << std::endl << std::endl;
// Ackermann to 3rd Quadrant
std::cout << "----- ACKERMANN 3q" << std::endl << std::endl;
targetPose.heading = 80/180.0*M_PI;
targetPose.position = Eigen::Vector3d(-1,-1,0);
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
assert(tv < 0 && rv > 0);
std::cout << "Test 3.3 (3rd Q Ackermann) PASSED" << std::endl << std::endl;
// Ackermann to 4th Quadrant
std::cout << "----- ACKERMANN 4q" << std::endl << std::endl;
targetPose.heading = - 80/180.0*M_PI;
targetPose.position = Eigen::Vector3d(1,-1,0);
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
assert(tv > 0 && rv < 0);
std::cout << "Test 3.4 (4th Q Ackermann) PASSED" << std::endl << std::endl;
std::cout << "----- No operation " << std::endl << std::endl;
robotPose.position = Eigen::Vector3d(0,0,0);
robotPose.orientation.setIdentity();
targetPose.position = Eigen::Vector3d(0,0,0);
targetPose.heading = 0;
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
assert(fabs(tv) < 0.00001 && fabs(rv) < 0.00001);
std::cout << "Test 4 PASSED" << std::endl << std::endl;
std::cout << "----- Ackerman non diagonal" << std::endl << std::endl;
robotPose.orientation.setIdentity();
targetPose.heading = 0;
robotPose.position = Eigen::Vector3d(0,0,0);
targetPose.position = Eigen::Vector3d(5,6,0);
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
std::cout << "Tv: " << tv << " Rv: " << rv << std::endl;
assert(fabs(tv) > 0 && rv > 0);
std::cout << "Test 5 PASSED" << std::endl << std::endl;
//test case robot needs to be alligned
robotPose.orientation = Quaterniond(AngleAxisd(M_PI/4.0, Vector3d::UnitZ()));
targetPose.heading = M_PI/2.0;
robotPose.position = Eigen::Vector3d(0,0,0);
targetPose.position = Eigen::Vector3d(0,0,0);
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
std::cout << "Tv: " << tv << " Rv: " << rv << std::endl;
assert(fabs(tv) < 0.001 && rv > 0);
std::cout << "Test 7 PASSED" << std::endl << std::endl;
*/
/*
//test case target in front of robot
robotPose.orientation.setIdentity();
targetPose.heading = 0;
robotPose.position = Eigen::Vector3d(0,0,0);
targetPose.position = Eigen::Vector3d(1,0,0);
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
std::cout << "Tv: " << tv << " Rv: " << rv << std::endl;
assert(tv > 0 && fabs(rv) < 0.001);
std::cout << "Test 1 PASSED" << std::endl << std::endl;
//test case target left of robot
robotPose.orientation.setIdentity();
targetPose.heading = 0;
robotPose.position = Eigen::Vector3d(0,0,0);
targetPose.position = Eigen::Vector3d(0,1,0);
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
std::cout << "Tv: " << tv << " Rv: " << rv << std::endl;
assert(fabs(tv) < 0.001 && rv > 0);
std::cout << "Test 2 PASSED" << std::endl << std::endl;
//test case target right of robot
robotPose.orientation.setIdentity();
targetPose.heading = 0;
robotPose.position = Eigen::Vector3d(0,0,0);
targetPose.position = Eigen::Vector3d(0,-1,0);
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
std::cout << "Tv: " << tv << " Rv: " << rv << std::endl;
assert(fabs(tv) < 0.001 && rv < 0);
std::cout << "Test 3 PASSED" << std::endl << std::endl;
//test case target right of robot
robotPose.orientation.setIdentity();
targetPose.heading = 0;
robotPose.position = Eigen::Vector3d(0,0,0);
targetPose.position = Eigen::Vector3d(.1,-1,0);
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
std::cout << "Tv: " << tv << " Rv: " << rv << std::endl;
assert(fabs(tv) < 0.001 && rv < 0);
std::cout << "Test 4 PASSED" << std::endl << std::endl;
//test case target equals own position
robotPose.position = Eigen::Vector3d(0,0,0);
robotPose.orientation.setIdentity();
targetPose.position = Eigen::Vector3d(0,0,0);
targetPose.heading = 0;
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
std::cout << "Tv: " << tv << " Rv: " << rv << std::endl;
assert(fabs(tv) < 0.001 && fabs(rv) < 0.001);
std::cout << "Test 5 PASSED" << std::endl << std::endl;
//test case robot needs to be alligned
robotPose.orientation.setIdentity();
targetPose.heading = M_PI/2.0;
robotPose.position = Eigen::Vector3d(0,0,0);
targetPose.position = Eigen::Vector3d(0,0,0);
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
std::cout << "Tv: " << tv << " Rv: " << rv << std::endl;
assert(fabs(tv) < 0.001 && rv > 0);
std::cout << "Test 6 PASSED" << std::endl << std::endl;
//test case robot needs to be alligned
robotPose.orientation = Quaterniond(AngleAxisd(M_PI/4.0, Vector3d::UnitZ()));
targetPose.heading = M_PI/2.0;
robotPose.position = Eigen::Vector3d(0,0,0);
targetPose.position = Eigen::Vector3d(0,0,0);
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
std::cout << "Tv: " << tv << " Rv: " << rv << std::endl;
assert(fabs(tv) < 0.001 && rv > 0);
std::cout << "Test 7 PASSED" << std::endl << std::endl;
//test case robot is in front of target and rear points toward target
robotPose.orientation.setIdentity();
targetPose.heading = 0;
robotPose.position = Eigen::Vector3d(1,0,0);
targetPose.position = Eigen::Vector3d(0,0,0);
lp.setPose(robotPose);
lp.setTargetPose(targetPose);
lp.getMovementCommand(tv, rv);
std::cout << "Tv: " << tv << " Rv: " << rv << std::endl;
assert((fabs(tv) < 0.001) && ((rv > 0.3) || (rv < -0.3)));
std::cout << "Test 8 PASSED" << std::endl << std::endl;
*/