-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSeanetProcessing.cpp
665 lines (614 loc) · 24.9 KB
/
SeanetProcessing.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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
// Prevent Visual Studio Intellisense from defining _WIN32 and _MSC_VER when we use
// Visual Studio to edit Linux or Borland C++ code.
#ifdef __linux__
# undef _WIN32
#endif // __linux__
#if defined(__GNUC__) || defined(__BORLANDC__)
# undef _MSC_VER
#endif // defined(__GNUC__) || defined(__BORLANDC__)
#include "SeanetProcessing.h"
int AdLow = 0, AdSpan = 0, Steps = 0, NSteps = 0, NBins = 0;
HDCTRL Hdctrl;
double StepAngleSize = 0;
int index_scanlines_prev = 0;
int index_scanlines = 0;
struct timeval* tvs = NULL;
double* angles = NULL;
unsigned char* scanlines = NULL;
struct timeval* tvstsort = NULL;
double* anglestsort = NULL;
unsigned char* wtftsort = NULL;
unsigned char* wtfasort = NULL;
THREAD_PROC_RETURN_VALUE SeanetProcessingThread(void* pParam)
{
CHRONO chrono_period;
int nbnew = 0;
int i = 0, j = 0, k = 0;
size_t nb_alpha_mes_total = 0;
#ifndef DISABLE_OPENCV_SUPPORT
COORDSYSTEM2IMG csMap2Img;
#endif // !DISABLE_OPENCV_SUPPORT
struct timeval tv;
double angle = 0;
unsigned char scanline[MAX_NB_BYTES_SEANET];
//unsigned char threshold = 70;
double minDist = 0, maxDist = 0;
UNREFERENCED_PARAMETER(pParam);
#ifndef DISABLE_OPENCV_SUPPORT
// Missing error checking...
IplImage* overlayimage = cvCreateImage(cvSize(videoimgwidth, videoimgheight), IPL_DEPTH_8U, 3);
#ifndef USE_OPENCV_HIGHGUI_CPP_API
cvSet(overlayimage, CV_RGB(0, 0, 0), NULL);
#else
cv::Mat overlayimagemat;
overlayimagemat = cv::cvarrToMat(overlayimage);
overlayimagemat = cv::Mat::zeros(overlayimagemat.size(), overlayimagemat.type());
#endif // !USE_OPENCV_HIGHGUI_CPP_API
#endif // !DISABLE_OPENCV_SUPPORT
tvstsort = (struct timeval*)calloc(MAX_NUMBER_OF_STEPS_SEANET, sizeof(struct timeval));
anglestsort = (double*)calloc(MAX_NUMBER_OF_STEPS_SEANET, sizeof(double));
wtftsort = (unsigned char*)calloc(MAX_NUMBER_OF_STEPS_SEANET*MAX_NB_BYTES_SEANET, sizeof(unsigned char));
wtfasort = (unsigned char*)calloc(MAX_NUMBER_OF_STEPS_SEANET*MAX_NB_BYTES_SEANET, sizeof(unsigned char));
if ((tvstsort == NULL)||(anglestsort == NULL)||(wtftsort == NULL)||(wtfasort == NULL))
{
printf("Unable to allocate data.\n");
free(wtfasort);
free(wtftsort);
free(anglestsort);
free(tvstsort);
if (!bExit) bExit = TRUE; // Unexpected program exit...
return 0;
}
memset(scanline, 0, sizeof(scanline));
StartChrono(&chrono_period);
for (;;)
{
StopChronoQuick(&chrono_period);
StartChrono(&chrono_period);
uSleep(1000*50);
#ifndef DISABLE_OPENCV_SUPPORT
#ifndef USE_OPENCV_HIGHGUI_CPP_API
cvSet(overlayimage, CV_RGB(0, 0, 0), NULL);
#else
overlayimagemat = cv::Mat::zeros(overlayimagemat.size(), overlayimagemat.type());
#endif // !USE_OPENCV_HIGHGUI_CPP_API
#endif // !DISABLE_OPENCV_SUPPORT
if (!bDisableSeanet)
{
// Get the last scanlines from the device.
EnterCriticalSection(&SeanetConnectingCS);
if (angles != NULL)
{
EnterCriticalSection(&SeanetDataCS);
// Example :
// NSteps = 256
// index_scanline_prev = 253
// index_scanline = 3
// 253, 254, 255, 0, 1, 2 are new (6)
nbnew = index_scanlines-index_scanlines_prev >= 0? index_scanlines-index_scanlines_prev: NSteps+(index_scanlines-index_scanlines_prev);
memmove(tvstsort+nbnew, tvstsort, (NSteps-nbnew)*sizeof(struct timeval));
memmove(anglestsort+nbnew, anglestsort, (NSteps-nbnew)*sizeof(double));
memmove(wtftsort+nbnew*NBins, wtftsort, (NSteps-nbnew)*NBins);
for (i = nbnew-1; i >= 0; i--)
{
int index = (index_scanlines_prev+(nbnew-1-i))%NSteps;
tvstsort[i] = tvs[index];
anglestsort[i] = angles[index];
memcpy(wtftsort+i*NBins, scanlines+index*NBins, NBins);
memcpy(wtfasort+(int)(angles[index]/StepAngleSize)*NBins, scanlines+index*NBins, NBins);
}
index_scanlines_prev = index_scanlines;
LeaveCriticalSection(&SeanetDataCS);
EnterCriticalSection(&StateVariablesCS);
for (i = nbnew-1; i >= 0; i--)
{
tv = tvstsort[i];
angle = anglestsort[i]; // Angle of the transducer in degrees.
memcpy(scanline, wtftsort+i*NBins, NBins);
alpha_mes_seanet = sdir*fmod_2PI(-M_PI*angle/180.0)+Center(alphashat); // Angle of the transducer in rad, corrected.
minDist = 0.75;
maxDist = rangescale-d_max_err;
d_all_mes_seanet.clear();
//GetFirstObstacleDist(scanline, threshold, minDist, maxDist, NBins, rangescale, &d_mes_seanet);
//d_all_mes_seanet.push_back(d_mes_seanet);
//GetLastObstacleDist(scanline, threshold, minDist, maxDist, NBins, rangescale, &d_mes_seanet);
//d_all_mes_seanet.push_back(d_mes_seanet);
//GetAllObstaclesDist(scanline, threshold, minDist, maxDist, NBins, rangescale, d_all_mes_seanet);
//GetAllObstaclesDist2(scanline, 75, minDist, maxDist, NBins, rangescale, AdLow, AdSpan, Hdctrl.bits.adc8on, d_all_mes_seanet);
//GetAllObstaclesDist3(scanline, 50, 5, minDist, maxDist, NBins, rangescale, d_all_mes_seanet);
//GetAllObstaclesDist4(scanline, 125, 5, minDist, maxDist, NBins, rangescale, AdLow, AdSpan, Hdctrl.bits.adc8on, d_all_mes_seanet);
GetAllObstaclesDist5(scanline, 224, 2, minDist, maxDist, NBins, rangescale, (unsigned char)AdLow, (unsigned char)AdSpan, Hdctrl.bits.adc8on, d_all_mes_seanet);
d_mes_seanet = Center(d_all_mes_seanet[0]);
alpha_mes_seanet_vector.push_back(alpha_mes_seanet);
d_mes_seanet_vector.push_back(d_mes_seanet);
d_all_mes_seanet_vector.push_back(d_all_mes_seanet);
t_seanet_history_vector.push_back(tv.tv_sec+0.000001*tv.tv_usec);
xhat_seanet_history_vector.push_back(xhat);
yhat_seanet_history_vector.push_back(yhat);
psihat_seanet_history_vector.push_back(psihat);
vrxhat_seanet_history_vector.push_back(vrxhat);
if ((int)alpha_mes_seanet_vector.size() > NSteps)
{
alpha_mes_seanet_vector.pop_front();
d_mes_seanet_vector.pop_front();
d_all_mes_seanet_vector.pop_front();
t_seanet_history_vector.pop_front();
xhat_seanet_history_vector.pop_front();
yhat_seanet_history_vector.pop_front();
psihat_seanet_history_vector.pop_front();
vrxhat_seanet_history_vector.pop_front();
}
}
#ifndef DISABLE_OPENCV_SUPPORT
switch (fSeanetOverlayImg & SONAR_IMG_TYPE_MASK)
{
case SONAR_IMG_NORMAL:
switch (fSeanetOverlayImg & SONAR_IMG_CORRECTIONS_MASK)
{
case SONAR_IMG_LEVER_ARMS:
DrawSonar(0, 0, M_PI/2.0, StepAngleSize, NBins, (unsigned char)AdLow, (unsigned char)AdSpan, Hdctrl.bits.adc8on, overlayimage);
break;
case SONAR_IMG_LEVER_ARMS_PSI:
DrawSonar(0, 0, Center(psihat), StepAngleSize, NBins, (unsigned char)AdLow, (unsigned char)AdSpan, Hdctrl.bits.adc8on, overlayimage);
break;
case SONAR_IMG_LEVER_ARMS_PSI_POS:
DrawSonar(Center(xhat), Center(yhat), Center(psihat), StepAngleSize, NBins, (unsigned char)AdLow, (unsigned char)AdSpan, Hdctrl.bits.adc8on, overlayimage);
break;
case SONAR_IMG_LEVER_ARMS_HIST_PSI:
DrawSonar(0, 0, Center(psihat), StepAngleSize, NBins, (unsigned char)AdLow, (unsigned char)AdSpan, Hdctrl.bits.adc8on, overlayimage);
break;
case SONAR_IMG_LEVER_ARMS_HIST_PSI_POS:
DrawSonar(Center(xhat), Center(yhat), Center(psihat), StepAngleSize, NBins, (unsigned char)AdLow, (unsigned char)AdSpan, Hdctrl.bits.adc8on, overlayimage);
break;
default:
DrawSonar(0, 0, M_PI/2.0, StepAngleSize, NBins, (unsigned char)AdLow, (unsigned char)AdSpan, Hdctrl.bits.adc8on, overlayimage);
break;
}
break;
case SONAR_IMG_WATERFALL:
DrawSonarWaterfall(NSteps, NBins, (unsigned char)AdLow, (unsigned char)AdSpan, Hdctrl.bits.adc8on, overlayimage);
break;
default:
break;
}
#endif // !DISABLE_OPENCV_SUPPORT
LeaveCriticalSection(&StateVariablesCS);
}
LeaveCriticalSection(&SeanetConnectingCS);
}
if ((robid & SIMULATOR_ROBID_MASK)||(!bDisableHokuyo)||(!bDisableRPLIDAR)||(!bDisablePololu[0])||(!bDisablePololu[1])||(!bDisablePololu[2])||
(!bDisableBlueView[0])||(!bDisableBlueView[1])||(!bDisableVideo[0])||(!bDisableVideo[1])||(!bDisableVideo[2])||(!bDisableVideo[3])||(!bDisableVideo[4]))
{
EnterCriticalSection(&StateVariablesCS);
#ifndef DISABLE_OPENCV_SUPPORT
InitCS2ImgEx(&csMap2Img, &csMap, overlayimage->width, overlayimage->height, BEST_RATIO_COORDSYSTEM2IMG);
switch (fSeanetOverlayImg & SONAR_IMG_TYPE_MASK)
{
case SONAR_IMG_NORMAL:
switch (fSeanetOverlayImg & SONAR_IMG_CORRECTIONS_MASK)
{
case SONAR_IMG_LEVER_ARMS:
cvCircle(overlayimage, cvPoint(XCS2JImg(&csMap2Img, 0), YCS2IImg(&csMap2Img, 0)), 4, CV_RGB_CvScalar(255, 255, 255), CV_FILLED, 8, 0);
break;
case SONAR_IMG_LEVER_ARMS_PSI:
cvCircle(overlayimage, cvPoint(XCS2JImg(&csMap2Img, 0), YCS2IImg(&csMap2Img, 0)), 4, CV_RGB_CvScalar(255, 255, 255), CV_FILLED, 8, 0);
break;
case SONAR_IMG_LEVER_ARMS_PSI_POS:
cvCircle(overlayimage, cvPoint(XCS2JImg(&csMap2Img, Center(xhat)), YCS2IImg(&csMap2Img, Center(yhat))), 4, CV_RGB_CvScalar(255, 255, 255), CV_FILLED, 8, 0);
break;
case SONAR_IMG_LEVER_ARMS_HIST_PSI:
cvCircle(overlayimage, cvPoint(XCS2JImg(&csMap2Img, 0), YCS2IImg(&csMap2Img, 0)), 4, CV_RGB_CvScalar(255, 255, 255), CV_FILLED, 8, 0);
break;
case SONAR_IMG_LEVER_ARMS_HIST_PSI_POS:
cvCircle(overlayimage, cvPoint(XCS2JImg(&csMap2Img, Center(xhat)), YCS2IImg(&csMap2Img, Center(yhat))), 4, CV_RGB_CvScalar(255, 255, 255), CV_FILLED, 8, 0);
break;
default:
cvCircle(overlayimage, cvPoint(XCS2JImg(&csMap2Img, 0), YCS2IImg(&csMap2Img, 0)), 4, CV_RGB_CvScalar(255, 255, 255), CV_FILLED, 8, 0);
break;
}
break;
case SONAR_IMG_WATERFALL:
break;
default:
break;
}
#endif // !DISABLE_OPENCV_SUPPORT
LeaveCriticalSection(&StateVariablesCS);
}
EnterCriticalSection(&StateVariablesCS);
#pragma region FUSION
nb_alpha_mes_total = alpha_mes_simulator_vector.size()+alpha_mes_seanet_vector.size()+alpha_mes_hokuyo_vector.size()+alpha_mes_rplidar_vector.size()+alpha_mes_srf02_vector.size();
for (k = 0; k < MAX_NB_POLOLU; k++)
{
nb_alpha_mes_total += alpha_mes_pololu_vector[k].size();
}
for (k = 0; k < MAX_NB_BLUEVIEW; k++)
{
nb_alpha_mes_total += alpha_mes_blueview_vector[k].size();
}
for (k = 0; k < MAX_NB_VIDEO; k++)
{
nb_alpha_mes_total += alpha_mes_video_vector[k].size();
}
for (i = 0; i < (int)alpha_mes_simulator_vector.size(); i++)
{
alpha_mes = alpha_mes_simulator;
d_mes = d_mes_simulator;
d_all_mes.clear();
for (j = 0; j < (int)d_all_mes_simulator.size(); j++)
{
d_all_mes.push_back(d_all_mes_simulator[j]);
}
alpha_mes_vector.push_back(alpha_mes_simulator_vector[i]);
d_mes_vector.push_back(d_mes_simulator_vector[i]);
d_all_mes_vector.push_back(d_all_mes_simulator_vector[i]);
t_history_vector.push_back(t_simulator_history_vector[i]);
xhat_history_vector.push_back(xhat_simulator_history_vector[i]);
yhat_history_vector.push_back(yhat_simulator_history_vector[i]);
psihat_history_vector.push_back(psihat_simulator_history_vector[i]);
vrxhat_history_vector.push_back(vrxhat_simulator_history_vector[i]);
if (alpha_mes_vector.size() > nb_alpha_mes_total)
{
alpha_mes_vector.pop_front();
d_mes_vector.pop_front();
d_all_mes_vector.pop_front();
t_history_vector.pop_front();
xhat_history_vector.pop_front();
yhat_history_vector.pop_front();
psihat_history_vector.pop_front();
vrxhat_history_vector.pop_front();
}
}
for (i = 0; i < (int)alpha_mes_seanet_vector.size(); i++)
{
alpha_mes = alpha_mes_seanet;
d_mes = d_mes_seanet;
d_all_mes.clear();
for (j = 0; j < (int)d_all_mes_seanet.size(); j++)
{
d_all_mes.push_back(d_all_mes_seanet[j]);
}
alpha_mes_vector.push_back(alpha_mes_seanet_vector[i]);
d_mes_vector.push_back(d_mes_seanet_vector[i]);
d_all_mes_vector.push_back(d_all_mes_seanet_vector[i]);
t_history_vector.push_back(t_seanet_history_vector[i]);
xhat_history_vector.push_back(xhat_seanet_history_vector[i]);
yhat_history_vector.push_back(yhat_seanet_history_vector[i]);
psihat_history_vector.push_back(psihat_seanet_history_vector[i]);
vrxhat_history_vector.push_back(vrxhat_seanet_history_vector[i]);
if (alpha_mes_vector.size() > nb_alpha_mes_total)
{
alpha_mes_vector.pop_front();
d_mes_vector.pop_front();
d_all_mes_vector.pop_front();
t_history_vector.pop_front();
xhat_history_vector.pop_front();
yhat_history_vector.pop_front();
psihat_history_vector.pop_front();
vrxhat_history_vector.pop_front();
}
}
for (i = 0; i < (int)alpha_mes_hokuyo_vector.size(); i++)
{
alpha_mes = alpha_mes_hokuyo;
d_mes = d_mes_hokuyo;
d_all_mes.clear();
for (j = 0; j < (int)d_all_mes_hokuyo.size(); j++)
{
d_all_mes.push_back(d_all_mes_hokuyo[j]);
}
alpha_mes_vector.push_back(alpha_mes_hokuyo_vector[i]);
d_mes_vector.push_back(d_mes_hokuyo_vector[i]);
d_all_mes_vector.push_back(d_all_mes_hokuyo_vector[i]);
t_history_vector.push_back(t_hokuyo_history_vector[i]);
xhat_history_vector.push_back(xhat_hokuyo_history_vector[i]);
yhat_history_vector.push_back(yhat_hokuyo_history_vector[i]);
psihat_history_vector.push_back(psihat_hokuyo_history_vector[i]);
vrxhat_history_vector.push_back(vrxhat_hokuyo_history_vector[i]);
if (alpha_mes_vector.size() > nb_alpha_mes_total)
{
alpha_mes_vector.pop_front();
d_mes_vector.pop_front();
d_all_mes_vector.pop_front();
t_history_vector.pop_front();
xhat_history_vector.pop_front();
yhat_history_vector.pop_front();
psihat_history_vector.pop_front();
vrxhat_history_vector.pop_front();
}
}
for (i = 0; i < (int)alpha_mes_rplidar_vector.size(); i++)
{
alpha_mes = alpha_mes_rplidar;
d_mes = d_mes_rplidar;
d_all_mes.clear();
for (j = 0; j < (int)d_all_mes_rplidar.size(); j++)
{
d_all_mes.push_back(d_all_mes_rplidar[j]);
}
alpha_mes_vector.push_back(alpha_mes_rplidar_vector[i]);
d_mes_vector.push_back(d_mes_rplidar_vector[i]);
d_all_mes_vector.push_back(d_all_mes_rplidar_vector[i]);
t_history_vector.push_back(t_rplidar_history_vector[i]);
xhat_history_vector.push_back(xhat_rplidar_history_vector[i]);
yhat_history_vector.push_back(yhat_rplidar_history_vector[i]);
psihat_history_vector.push_back(psihat_rplidar_history_vector[i]);
vrxhat_history_vector.push_back(vrxhat_rplidar_history_vector[i]);
if (alpha_mes_vector.size() > nb_alpha_mes_total)
{
alpha_mes_vector.pop_front();
d_mes_vector.pop_front();
d_all_mes_vector.pop_front();
t_history_vector.pop_front();
xhat_history_vector.pop_front();
yhat_history_vector.pop_front();
psihat_history_vector.pop_front();
vrxhat_history_vector.pop_front();
}
}
for (i = 0; i < (int)alpha_mes_srf02_vector.size(); i++)
{
alpha_mes = alpha_mes_srf02;
d_mes = d_mes_srf02;
d_all_mes.clear();
for (j = 0; j < (int)d_all_mes_srf02.size(); j++)
{
d_all_mes.push_back(d_all_mes_srf02[j]);
}
alpha_mes_vector.push_back(alpha_mes_srf02_vector[i]);
d_mes_vector.push_back(d_mes_srf02_vector[i]);
d_all_mes_vector.push_back(d_all_mes_srf02_vector[i]);
t_history_vector.push_back(t_srf02_history_vector[i]);
xhat_history_vector.push_back(xhat_srf02_history_vector[i]);
yhat_history_vector.push_back(yhat_srf02_history_vector[i]);
psihat_history_vector.push_back(psihat_srf02_history_vector[i]);
vrxhat_history_vector.push_back(vrxhat_srf02_history_vector[i]);
if (alpha_mes_vector.size() > nb_alpha_mes_total)
{
alpha_mes_vector.pop_front();
d_mes_vector.pop_front();
d_all_mes_vector.pop_front();
t_history_vector.pop_front();
xhat_history_vector.pop_front();
yhat_history_vector.pop_front();
psihat_history_vector.pop_front();
vrxhat_history_vector.pop_front();
}
}
for (k = 0; k < MAX_NB_POLOLU; k++)
{
for (i = 0; i < (int)alpha_mes_pololu_vector[k].size(); i++)
{
alpha_mes = alpha_mes_pololu[k];
d_mes = d_mes_pololu[k];
d_all_mes.clear();
for (j = 0; j < (int)d_all_mes_pololu[k].size(); j++)
{
d_all_mes.push_back(d_all_mes_pololu[k][j]);
}
alpha_mes_vector.push_back(alpha_mes_pololu_vector[k][i]);
d_mes_vector.push_back(d_mes_pololu_vector[k][i]);
d_all_mes_vector.push_back(d_all_mes_pololu_vector[k][i]);
t_history_vector.push_back(t_pololu_history_vector[k][i]);
xhat_history_vector.push_back(xhat_pololu_history_vector[k][i]);
yhat_history_vector.push_back(yhat_pololu_history_vector[k][i]);
psihat_history_vector.push_back(psihat_pololu_history_vector[k][i]);
vrxhat_history_vector.push_back(vrxhat_pololu_history_vector[k][i]);
if (alpha_mes_vector.size() > nb_alpha_mes_total)
{
alpha_mes_vector.pop_front();
d_mes_vector.pop_front();
d_all_mes_vector.pop_front();
t_history_vector.pop_front();
xhat_history_vector.pop_front();
yhat_history_vector.pop_front();
psihat_history_vector.pop_front();
vrxhat_history_vector.pop_front();
}
}
}
for (k = 0; k < MAX_NB_BLUEVIEW; k++)
{
for (i = 0; i < (int)alpha_mes_blueview_vector[k].size(); i++)
{
alpha_mes = alpha_mes_blueview[k];
d_mes = d_mes_blueview[k];
d_all_mes.clear();
for (j = 0; j < (int)d_all_mes_blueview[k].size(); j++)
{
d_all_mes.push_back(d_all_mes_blueview[k][j]);
}
alpha_mes_vector.push_back(alpha_mes_blueview_vector[k][i]);
d_mes_vector.push_back(d_mes_blueview_vector[k][i]);
d_all_mes_vector.push_back(d_all_mes_blueview_vector[k][i]);
t_history_vector.push_back(t_blueview_history_vector[k][i]);
xhat_history_vector.push_back(xhat_blueview_history_vector[k][i]);
yhat_history_vector.push_back(yhat_blueview_history_vector[k][i]);
psihat_history_vector.push_back(psihat_blueview_history_vector[k][i]);
vrxhat_history_vector.push_back(vrxhat_blueview_history_vector[k][i]);
if (alpha_mes_vector.size() > nb_alpha_mes_total)
{
alpha_mes_vector.pop_front();
d_mes_vector.pop_front();
d_all_mes_vector.pop_front();
t_history_vector.pop_front();
xhat_history_vector.pop_front();
yhat_history_vector.pop_front();
psihat_history_vector.pop_front();
vrxhat_history_vector.pop_front();
}
}
}
for (k = 0; k < MAX_NB_VIDEO; k++)
{
for (i = 0; i < (int)alpha_mes_video_vector[k].size(); i++)
{
alpha_mes = alpha_mes_video[k];
d_mes = d_mes_video[k];
d_all_mes.clear();
for (j = 0; j < (int)d_all_mes_video[k].size(); j++)
{
d_all_mes.push_back(d_all_mes_video[k][j]);
}
alpha_mes_vector.push_back(alpha_mes_video_vector[k][i]);
d_mes_vector.push_back(d_mes_video_vector[k][i]);
d_all_mes_vector.push_back(d_all_mes_video_vector[k][i]);
t_history_vector.push_back(t_video_history_vector[k][i]);
xhat_history_vector.push_back(xhat_video_history_vector[k][i]);
yhat_history_vector.push_back(yhat_video_history_vector[k][i]);
psihat_history_vector.push_back(psihat_video_history_vector[k][i]);
vrxhat_history_vector.push_back(vrxhat_video_history_vector[k][i]);
if (alpha_mes_vector.size() > nb_alpha_mes_total)
{
alpha_mes_vector.pop_front();
d_mes_vector.pop_front();
d_all_mes_vector.pop_front();
t_history_vector.pop_front();
xhat_history_vector.pop_front();
yhat_history_vector.pop_front();
psihat_history_vector.pop_front();
vrxhat_history_vector.pop_front();
}
}
}
#pragma endregion
#ifndef DISABLE_OPENCV_SUPPORT
switch (fSeanetOverlayImg & SONAR_IMG_DISTANCES_MASK)
{
case SONAR_IMG_FIRST_DISTANCES:
j = 0;
switch (fSeanetOverlayImg & SONAR_IMG_CORRECTIONS_MASK)
{
case SONAR_IMG_LEVER_ARMS:
for (i = 0; i < (int)d_all_mes_vector.size(); i++)
{
// Might be infinity, but does not seem to be a problem...
DrawObstacleDistError(0, 0, alpha_mes_vector[i]+M_PI/2.0, Center(d_all_mes_vector[i][j]), 0.5*Width(d_all_mes_vector[i][j])+d_max_err, colorsonarlidar, overlayimage);
}
break;
case SONAR_IMG_LEVER_ARMS_PSI:
for (i = 0; i < (int)d_all_mes_vector.size(); i++)
{
// Might be infinity, but does not seem to be a problem...
DrawObstacleDistError(0, 0, alpha_mes_vector[i]+Center(psihat), Center(d_all_mes_vector[i][j]), 0.5*Width(d_all_mes_vector[i][j])+d_max_err, colorsonarlidar, overlayimage);
}
break;
case SONAR_IMG_LEVER_ARMS_PSI_POS:
for (i = 0; i < (int)d_all_mes_vector.size(); i++)
{
// Might be infinity, but does not seem to be a problem...
DrawObstacleDistError(Center(xhat), Center(yhat), alpha_mes_vector[i]+Center(psihat), Center(d_all_mes_vector[i][j]), 0.5*Width(d_all_mes_vector[i][j])+d_max_err, colorsonarlidar, overlayimage);
}
break;
case SONAR_IMG_LEVER_ARMS_HIST_PSI:
for (i = 0; i < (int)d_all_mes_vector.size(); i++)
{
// Might be infinity, but does not seem to be a problem...
DrawObstacleDistError(0, 0, alpha_mes_vector[i]+Center(psihat_history_vector[i]), Center(d_all_mes_vector[i][j]), 0.5*Width(d_all_mes_vector[i][j])+d_max_err, colorsonarlidar, overlayimage);
}
break;
case SONAR_IMG_LEVER_ARMS_HIST_PSI_POS:
for (i = 0; i < (int)d_all_mes_vector.size(); i++)
{
// Might be infinity, but does not seem to be a problem...
DrawObstacleDistError(Center(xhat_history_vector[i]), Center(yhat_history_vector[i]), alpha_mes_vector[i]+Center(psihat_history_vector[i]), Center(d_all_mes_vector[i][j]), 0.5*Width(d_all_mes_vector[i][j])+d_max_err, colorsonarlidar, overlayimage);
}
break;
default:
for (i = 0; i < (int)d_all_mes_vector.size(); i++)
{
// Might be infinity, but does not seem to be a problem...
DrawObstacleDistError(0, 0, alpha_mes_vector[i]+M_PI/2.0, Center(d_all_mes_vector[i][j]), 0.5*Width(d_all_mes_vector[i][j])+d_max_err, colorsonarlidar, overlayimage);
}
break;
}
break;
case SONAR_IMG_ALL_DISTANCES:
switch (fSeanetOverlayImg & SONAR_IMG_CORRECTIONS_MASK)
{
case SONAR_IMG_LEVER_ARMS:
for (i = 0; i < (int)d_all_mes_vector.size(); i++)
{
for (j = 0; j < (int)d_all_mes_vector[i].size(); j++)
{
// Might be infinity, but does not seem to be a problem...
DrawObstacleDistError(0, 0, alpha_mes_vector[i]+M_PI/2.0, Center(d_all_mes_vector[i][j]), 0.5*Width(d_all_mes_vector[i][j])+d_max_err, colorsonarlidar, overlayimage);
}
}
break;
case SONAR_IMG_LEVER_ARMS_PSI:
for (i = 0; i < (int)d_all_mes_vector.size(); i++)
{
for (j = 0; j < (int)d_all_mes_vector[i].size(); j++)
{
// Might be infinity, but does not seem to be a problem...
DrawObstacleDistError(0, 0, alpha_mes_vector[i]+Center(psihat), Center(d_all_mes_vector[i][j]), 0.5*Width(d_all_mes_vector[i][j])+d_max_err, colorsonarlidar, overlayimage);
}
}
break;
case SONAR_IMG_LEVER_ARMS_PSI_POS:
for (i = 0; i < (int)d_all_mes_vector.size(); i++)
{
for (j = 0; j < (int)d_all_mes_vector[i].size(); j++)
{
// Might be infinity, but does not seem to be a problem...
DrawObstacleDistError(Center(xhat), Center(yhat), alpha_mes_vector[i]+Center(psihat), Center(d_all_mes_vector[i][j]), 0.5*Width(d_all_mes_vector[i][j])+d_max_err, colorsonarlidar, overlayimage);
}
}
break;
case SONAR_IMG_LEVER_ARMS_HIST_PSI:
for (i = 0; i < (int)d_all_mes_vector.size(); i++)
{
for (j = 0; j < (int)d_all_mes_vector[i].size(); j++)
{
// Might be infinity, but does not seem to be a problem...
DrawObstacleDistError(0, 0, alpha_mes_vector[i]+Center(psihat_history_vector[i]), Center(d_all_mes_vector[i][j]), 0.5*Width(d_all_mes_vector[i][j])+d_max_err, colorsonarlidar, overlayimage);
}
}
break;
case SONAR_IMG_LEVER_ARMS_HIST_PSI_POS:
for (i = 0; i < (int)d_all_mes_vector.size(); i++)
{
for (j = 0; j < (int)d_all_mes_vector[i].size(); j++)
{
// Might be infinity, but does not seem to be a problem...
DrawObstacleDistError(Center(xhat_history_vector[i]), Center(yhat_history_vector[i]), alpha_mes_vector[i]+Center(psihat_history_vector[i]), Center(d_all_mes_vector[i][j]), 0.5*Width(d_all_mes_vector[i][j])+d_max_err, colorsonarlidar, overlayimage);
}
}
break;
default:
for (i = 0; i < (int)d_all_mes_vector.size(); i++)
{
for (j = 0; j < (int)d_all_mes_vector[i].size(); j++)
{
// Might be infinity, but does not seem to be a problem...
DrawObstacleDistError(0, 0, alpha_mes_vector[i]+M_PI/2.0, Center(d_all_mes_vector[i][j]), 0.5*Width(d_all_mes_vector[i][j])+d_max_err, colorsonarlidar, overlayimage);
}
}
break;
}
break;
default:
break;
}
#endif // !DISABLE_OPENCV_SUPPORT
LeaveCriticalSection(&StateVariablesCS);
#ifndef DISABLE_OPENCV_SUPPORT
EnterCriticalSection(&SeanetOverlayImgCS);
CopyResizeScale(overlayimage, SeanetOverlayImg, bCropOnResize);
LeaveCriticalSection(&SeanetOverlayImgCS);
#endif // !DISABLE_OPENCV_SUPPORT
//printf("SeanetProcessingThread period : %f s.\n", GetTimeElapsedChronoQuick(&chrono_period));
if (bExit) break;
}
StopChronoQuick(&chrono_period);
free(wtfasort);
free(wtftsort);
free(anglestsort);
free(tvstsort);
#ifndef DISABLE_OPENCV_SUPPORT
cvReleaseImage(&overlayimage);
#endif // !DISABLE_OPENCV_SUPPORT
if (!bExit) bExit = TRUE; // Unexpected program exit...
return 0;
}