-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplanningwalk.cpp
695 lines (687 loc) · 20.3 KB
/
planningwalk.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
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
#include <iostream>
#include <vector>
#include "shortIR.cpp"
#include "motion.cpp"
#include <math.h>
const float slp = 0.5;
const float forward_speed = 1.0;
const float forward_side_dis_threshold = 12;
const float forward_front_dis_threshold = 10;
const float block_size = 3.5;
const float grid_size = 16;
const float size_of_field = 21;//grid*grid ,48 means 49 *49
const float middle_of_field = (size_of_field-1)/2;
const float probability_decrease_const=1; //every plan, how much probability it decreased
const float passible_const = 0.3; //if it is passible, how much probability I have to times
const float passible_threshold = 0.6; //how much is count as passible
const float not_passible_const = 0.8; //if it is a wall, how much possibility you add to it
const float camera_center =24; //24 inch away from the center of the robot
const float start_weight = 4;
const float stuck_threshold = 7;
class Grid {
float x_center;
float y_center;
int myi;
int myj;
int weight;
float passible;
public:
Grid(float _x_center, float _y_center, int _i, int _j) {
passible = 0;
x_center = _x_center;
y_center = _y_center;
weight = start_weight;
myi = _i;
myj = _j;
}
int i() {return myi;}
int j() {return myj;}
float x() {return x_center;}
float y() {return y_center;}
int w() {return weight;}
void more_passible() {
passible = passible*probability_decrease_const;
}
void is_passible() {
passible = passible*passible_const;
}
void update() {
weight--;
}
void is_not_passible() {
if ((passible+not_passible_const)>=1) passible = 1;
else passible = passible + not_passible_const;
}
bool Passible() {
return (passible<passible_threshold);
}
float dis(Grid other){
return sqrt(pow((other.x()-x()),2.0)+pow((other.y()-y()),2.0))+2;
}
bool equalTo(int i_,int j_){
return ((i()==i_)&&(j()==j_));
}
bool inside(Grid other, float angle) { //this angle is in degree
if (angle == 0){
return (other.i()<=i())&&(other.j() ==j());
}
else {
if (angle == 90) {
return (other.i()==i())&&(other.j()>=j());
}
else {
if (angle == 180) {
return (other.j()==j())&&(other.i()>=i());
}
else {
if (angle == 270){
return (other.j()<=j())&&(other.i()==i());
}
}
}
}
if (angle<90) {
if ((other.j()<j())||(other.i()>i())) return false;
else {
bool i1 = ((other.j()-j()-0.5)/tan(angle*3.14/180))>(i()-other.i()-0.5);
bool i2 = ((other.j()-j()-0.5)/tan(angle*3.14/180))<(i()-other.i()+0.5);
bool i3 = ((i()-other.i()-0.5)*tan(angle*3.14/180))>(other.j()-j()-0.5);
bool i4 = ((i()-other.i()-0.5)*tan(angle*3.14/180))<(other.j()-j()+0.5);
return((i1&&i2)||(i3&&i4));
}
}
else {
if (angle<180) {
if ((other.j()<j())||(other.i()<i())) return false;
else {
bool i1 = ((other.j()-j()-0.5)/tan(3.14-(angle*3.14/180)))>(other.i()-i()-0.5);
bool i2 = ((other.j()-j()-0.5)/tan(3.14-(angle*3.14/180)))<(other.i()-i()+0.5);
bool i3 = ((other.i()-i()-0.5)*tan(3.14-(angle*3.14/180)))>(other.j()-j()-0.5);
bool i4 = ((other.i()-i()-0.5)*tan(3.14-(angle*3.14/180)))<(other.j()-j()+0.5);
return((i1&&i2)||(i3&&i4));
}
}
else {
if(angle<270) {
if ((other.j()>j())||(other.i()<i())) return false;
else {
bool i1 = ((j()-other.j()-0.5)/tan((angle*3.14/180)-3.14))>(other.i()-i()-0.5);
bool i2 = ((j()-other.j()-0.5)/tan((angle*3.14/180)-3.14))<(other.i()-i()+0.5);
bool i3 = ((other.i()-i()-0.5)*tan((angle*3.14/180)-3.14))>(j()-other.j()-0.5);
bool i4 = ((other.i()-i()-0.5)*tan((angle*3.14/180)-3.14))<(j()-other.j()+0.5);
return((i1&&i2)||(i3&&i4));
}
}
else{
if ((other.j()>j())||(other.i()>i())) return false;
else {
bool i1 = ((j()-other.j()-0.5)/tan(6.28-(angle*3.14/180)))>(i()-other.i()-0.5);
bool i2 = ((j()-other.j()-0.5)/tan(6.28-(angle*3.14/180)))<(i()-other.i()+0.5);
bool i3 = ((i()-other.i()-0.5)*tan(6.28-(angle*3.14/180)))>(j()-other.j()-0.5);
bool i4 = ((i()-other.i()-0.5)*tan(6.28-(angle*3.14/180)))<(j()-other.j()+0.5);
return((i1&&i2)||(i3&&i4));
}
}
}
}
}
};
class Planner {
std::vector<std::vector<Grid> > map;
int grid_i; int grid_j; int t_grid_i; int t_grid_j;
float total_weight(float angle,int start_i,int start_j){
std::vector<Grid> temp;
temp.push_back(map[start_i][start_j]);
int point=0;
float total = 0;
int now_i; int now_j;
bool keep_run = true;
int mypush = 1;
if(angle<180) {
if(angle<90) {
for(;keep_run;) {
int size = temp.size();
point = size-mypush;
mypush = 0;
for(int k = point; k<size; k++) {
total = total+temp[k].w()/temp[0].dis(temp[k]);
now_i = temp[k].i(); now_j = temp[k].j();
std::cout<<"now_i: "<<now_i<<",now_j: "<<now_j<<", weight: "<<temp[k].w()<<std::endl;
if ((now_j+1)<size_of_field && (now_i-1>=0)) {
if (temp[0].inside(map[now_i-1][now_j],angle)) {
//std::cout<<"inside?"<<std::endl;
if (!map[now_i-1][now_j].Passible()) keep_run = false;
else {
bool already_in = false;
for(int v = point;v<temp.size();v++) {
if(temp[v].equalTo(now_i-1,now_j)) already_in = true;
}
if (!already_in) {
mypush++;
temp.push_back(map[now_i-1][now_j]);
}
}
}
if (temp[0].inside(map[now_i-1][now_j+1],angle)){
//std::cout<<"inside?"<<std::endl;
if (!map[now_i-1][now_j+1].Passible()) keep_run = false;
else {
bool already_in = false;
for(int v = point;v<temp.size();v++) {
if(temp[v].equalTo(now_i-1,now_j+1)) already_in = true;
}
if (!already_in) {
mypush++;
temp.push_back(map[now_i-1][now_j+1]);
}
}
}
if (temp[0].inside(map[now_i][now_j+1],angle)) {
//std::cout<<"inside?"<<std::endl;
if (!map[now_i][now_j+1].Passible()) keep_run = false;
else {
bool already_in = false;
for(int v = point;v<temp.size();v++) {
if(temp[v].equalTo(now_i,now_j+1)) already_in = true;
}
if (!already_in) {
mypush++;
temp.push_back(map[now_i][now_j+1]);
}
}
}
}
else keep_run = false;
}
}
}
else{
for(;keep_run;) {
int size = temp.size();
point = size-mypush;
mypush = 0;
for(int k = point; k<size; k++) {
total = total+temp[k].w()/temp[0].dis(temp[k]);
now_i = temp[k].i(); now_j = temp[k].j();
std::cout<<"now_i: "<<now_i<<",now_j: "<<now_j<<", weight: "<<temp[k].w()<<std::endl;
if ((now_j+1)<size_of_field && (now_i+1<size_of_field)) {
if (temp[0].inside(map[now_i+1][now_j],angle)) {
if (!map[now_i+1][now_j].Passible()) keep_run = false;
else {
bool already_in = false;
for(int v = point;v<temp.size();v++) {
if(temp[v].equalTo(now_i+1,now_j)) already_in = true;
}
if (!already_in) {
mypush++;
temp.push_back(map[now_i+1][now_j]);
}
}
}
if (temp[0].inside(map[now_i+1][now_j+1],angle)){
if (!map[now_i+1][now_j+1].Passible()) keep_run = false;
else {
bool already_in = false;
for(int v = point;v<temp.size();v++) {
if(temp[v].equalTo(now_i+1,now_j+1)) already_in = true;
}
if (!already_in) {
mypush++;
temp.push_back(map[now_i+1][now_j+1]);
}
}
}
if (temp[0].inside(map[now_i][now_j+1],angle)) {
if (!map[now_i][now_j+1].Passible()) keep_run = false;
else {
bool already_in = false;
for(int v = point;v<temp.size();v++) {
if(temp[v].equalTo(now_i,now_j+1)) already_in = true;
}
if (!already_in) {
mypush++;
temp.push_back(map[now_i][now_j+1]);
}
}
}
}
else keep_run = false;
}
}
}
}
else{
if(angle<270) {
for(;keep_run;) {
int size = temp.size();
point = size-mypush;
mypush = 0;
for(int k = point; k<size; k++) {
total = total+temp[k].w()/temp[0].dis(temp[k]);
now_i = temp[k].i(); now_j = temp[k].j();
std::cout<<"now_i: "<<now_i<<",now_j: "<<now_j<<", weight: "<<temp[k].w()<<std::endl;
if ((now_j-1)>=0 && (now_i+1<size_of_field)) {
if (temp[0].inside(map[now_i+1][now_j],angle)) {
if (!map[now_i+1][now_j].Passible()) keep_run = false;
else {
bool already_in = false;
for(int v = point;v<temp.size();v++) {
if(temp[v].equalTo(now_i+1,now_j)) already_in = true;
}
if (!already_in) {
mypush++;
temp.push_back(map[now_i+1][now_j]);
}
}
}
if (temp[0].inside(map[now_i+1][now_j-1],angle)){
if (!map[now_i+1][now_j-1].Passible()) keep_run = false;
else {
bool already_in = false;
for(int v = point;v<temp.size();v++) {
if(temp[v].equalTo(now_i+1,now_j-1)) already_in = true;
}
if (!already_in) {
mypush++;
temp.push_back(map[now_i+1][now_j-1]);
}
}
}
if (temp[0].inside(map[now_i][now_j-1],angle)) {
if (!map[now_i][now_j-1].Passible()) keep_run = false;
else {
bool already_in = false;
for(int v = point;v<temp.size();v++) {
if(temp[v].equalTo(now_i,now_j-1)) already_in = true;
}
if (!already_in) {
mypush++;
temp.push_back(map[now_i][now_j-1]);
}
}
}
}
else keep_run = false;
}
}
}
else{
for(;keep_run;) {
int size = temp.size();
point = size-mypush;
mypush = 0;
for(int k = point; k<size; k++) {
total = total+temp[k].w()/temp[0].dis(temp[k]);
now_i = temp[k].i(); now_j = temp[k].j();
std::cout<<"now_i: "<<now_i<<",now_j: "<<now_j<<", weight: "<<temp[k].w()<<std::endl;
if ((now_j-1)>=0 && (now_i-1>=0)) {
if (temp[0].inside(map[now_i-1][now_j],angle)) {
if (!map[now_i-1][now_j].Passible()) keep_run = false;
else {
bool already_in = false;
for(int v = point;v<temp.size();v++) {
if(temp[v].equalTo(now_i-1,now_j)) already_in = true;
}
if (!already_in) {
mypush++;
temp.push_back(map[now_i-1][now_j]);
}
}
}
if (temp[0].inside(map[now_i-1][now_j-1],angle)){
if (!map[now_i-1][now_j-1].Passible()) keep_run = false;
else {
bool already_in = false;
for(int v = point;v<temp.size();v++) {
if(temp[v].equalTo(now_i-1,now_j-1)) already_in = true;
}
if (!already_in) {
mypush++;
temp.push_back(map[now_i-1][now_j-1]);
}
}
}
if (temp[0].inside(map[now_i][now_j-1],angle)) {
if (!map[now_i][now_j-1].Passible()) keep_run = false;
else {
bool already_in = false;
for(int v = point;v<temp.size();v++) {
if(temp[v].equalTo(now_i,now_j-1)) already_in = true;
}
if (!already_in) {
mypush++;
temp.push_back(map[now_i][now_j-1]);
}
}
}
}
else keep_run = false;
}
}
}
}
std::cout<<"did I return?"<<std::endl;
return total;
}
public:
Planner() {
for (int i=0; i<size_of_field;i++) {
std::vector<Grid> vm;
for (int j=0; j<size_of_field; j++) {
Grid g((j-middle_of_field)*grid_size,(middle_of_field-i)*grid_size,i,j);
vm.push_back(g); //i is row, j is column
}
map.push_back(vm);
}
grid_i = -1;
grid_j = -1;
t_grid_i = -1;
t_grid_j = -1;
}
float plan(Location* location) { //return the angle that robot should turn
std::cout<<"planning"<<std::endl;
std::cout<<"planning"<<std::endl;
std::cout<<"planning"<<std::endl;
std::cout<<"planning"<<std::endl;
float x = location->x();
float y = location->y();
int this_i; int this_j;
if (x>0) this_j = ((int) ((x/grid_size)+0.5))+middle_of_field;
else this_j = ((int) ((x/grid_size)-0.5))+middle_of_field;
if (y>0) this_i = middle_of_field-(int)((y/grid_size)+0.5);
else this_i = middle_of_field-(int)((y/grid_size)-0.5);
std::vector<float> v;
for(int i=0; i<12;i++) {
float ttw = total_weight(i*30,this_i,this_j);
std::cout<<"degree: "<<i*30<<" ,total weight: "<< ttw<<std::endl;
v.push_back(ttw);
}
float largest = v[0];
int largest_pin = 0;
for(int i=1;i<12;i++) {
if(v[i]>largest) {
largest = v[i];
largest_pin = i;
}
}
std::cout<<" I plan to go in: "<<largest*30<<std::endl;
float real_angle = location->theta() - (int)(location->theta()/6.28);
return ((3.14*largest_pin/6)-real_angle);
}
void whole_update() {
for (int i=0; i<size_of_field;i++) {
for (int j=0; j<size_of_field; j++) {
map[i][j].more_passible();
}
}
}
void is_wall(Location* location,float dis, float angle) { //this location is a wall block
std::cout<<"run through is_wall"<<std::endl;
int this_i;
int this_j;
float x = location->x();
float y = location->y();
if (x>0) this_j = ((int) ((x/grid_size)+0.5))+middle_of_field;
else this_j = ((int) ((x/grid_size)-0.5))+middle_of_field;
if (y>0) this_i = middle_of_field-(int)((y/grid_size)+0.5);
else this_i = middle_of_field-(int)((y/grid_size)-0.5);
Location* update = location->move(dis,angle);
int update_i;
int update_j;
float _x = update->x();
float _y = update->y();
if (_x>0) update_j = ((int) ((_x/grid_size)+0.5))+middle_of_field;
else update_j = ((int) ((_x/grid_size)-0.5))+middle_of_field;
if (_y>0) update_i = middle_of_field-(int)((_y/grid_size)+0.5);
else update_i = middle_of_field-(int)((_y/grid_size)-0.5);
int return_i;
int return_j;
if ((update_i == this_i)&&(update_j == this_j)) {
float final_angle = location->theta()+angle;
float test_angle = final_angle-6.28*floor(final_angle/6.28);
if (test_angle<0.78||test_angle>=5.5) {return_i = this_i-1; return_j = this_j;}
if ((test_angle>=0.78)&&(test_angle<2.35)) {return_i = this_i; return_j = this_j+1;}
if ((test_angle>=2.35)&&(test_angle<3.92)) {return_i = this_i+1; return_j = this_j+1;}
if ((test_angle>=3.92)&&(test_angle<5.5)) {return_i = this_i; return_j = this_j-1;}
}
else {
return_i = update_i; return_j = update_j;
}
std::cout<<"walli: "<<return_i<<", wallj: "<<return_j<<std::endl;
map[return_i][return_j].is_not_passible();
}
void update_grid(Location* location) {
int this_i;
int this_j;
float _x = location->x();
float _y = location->y();
if (_x>0) this_j = ((int) ((_x/grid_size)+0.5))+middle_of_field;
else this_j = ((int) ((_x/grid_size)-0.5))+middle_of_field;
if (_y>0) this_i = middle_of_field-(int)((_y/grid_size)+0.5);
else this_i = middle_of_field-(int)((_y/grid_size)-0.5);
if ((this_i != t_grid_i)||(this_j != t_grid_j)) {
map[this_i][this_j].is_passible();
t_grid_i = this_i;
std::cout<<"I am at: "<<this_i<<" "<<this_j<<std::endl;
t_grid_j = this_j;
}
Location* update = location->move_forward(camera_center);
int update_i;
int update_j;
float x = update->x();
float y = update->y();
if (x>0) update_j = ((int) ((x/grid_size)+0.5))+middle_of_field;
else update_j = ((int) ((x/grid_size)-0.5))+middle_of_field;
if (y>0) update_i = middle_of_field-(int)((y/grid_size)+0.5);
else update_i = middle_of_field-(int)((y/grid_size)-0.5);
if ((update_i != grid_i)||(update_j != grid_j)) {
map[update_i][update_j].update();
std::cout<<"I update: "<<update_i<<" "<<update_j<<std::endl;
grid_i = update_i; grid_j = update_j;
}
}
};
class Planningwalk {
Motor* left;
Motor* right;
IR* irf;
IR* irlf;
IR* irlb;
IR* irr;
Odometry* odo;
Motion* motion;
mraa::Gpio* irb;
Location* start;
Location* current;
Planner* map;
struct timeval stktv;
float check_stuck_base_time;
bool initialized;
bool r_init; bool l_init; int f_cnt; Location* l_start; Location* r_start; int wall_side; //wallside: 0:left; 1:right; 2:front
bool end_turn;
public:
Planningwalk (Motor* _left,Motor* _right,IR* _irf,IR* _irlf,IR* _irlb,IR* _irr,mraa::Gpio* _irb, Location* _start) {
left = _left; right = _right;
irf = _irf; irlf = _irlf; irlb = _irlb; irr = _irr; irb = _irb;
start = _start; current = _start;
odo = new Odometry(_left, _right, current);
motion = new Motion(_left,_right,odo,_start);
initialized = false;
map = new Planner();
}
int run(int channel){
if (channel == 0) { //problem dealer, when you are stuck in a bad thing
std::cout<<"channel 0: I meat a problem "<<std::endl;
std::cout<<"channel 0: I meat a problem "<<std::endl;
std::cout<<"channel 0: I meat a problem "<<std::endl;
if (!initialized) {
left->backward();
right->backward();
left->setSpeed(0.7);
right->setSpeed(0.7);
gettimeofday(&stktv, NULL);
check_stuck_base_time = (unsigned long long)(stktv.tv_sec)*1000 + (unsigned long long)(stktv.tv_usec) / 1000;
initialized = true;
return 0;
}
else {
gettimeofday(&stktv,NULL);
if(((unsigned long long)(stktv.tv_sec)*1000 + (unsigned long long)(stktv.tv_usec) / 1000)-check_stuck_base_time<500) {
left->run();
right->run();
odo->run();
return 0;
}
else {
channel_stop();
return 2;
}
}
}
if (channel == 1) {
if (!initialized) {
forward_setup();
return 1;
}
else{
gettimeofday(&stktv,NULL);
if(((unsigned long long)(stktv.tv_sec)*1000 + (unsigned long long)(stktv.tv_usec) / 1000)-check_stuck_base_time>stuck_threshold*1000) {
initialized = false;
return 0;
}
if(!forward_next()){
forward_run();
return 1;
}
else {
channel_stop();
wall_dealer();
return 2;
}
}
}
if (channel == 2) {
if (!initialized) {
turn_setup();
return 2;
}
else {
if(!turn_next()){
turn_run();
return 2;
}
else {
channel_stop();
return 1;
}
}
}
}
void channel_stop() {
left->stop(); right->stop();
initialized = false;
sleep (slp);
}
void forward_setup() {
gettimeofday(&stktv,NULL);
check_stuck_base_time = (unsigned long long)(stktv.tv_sec)*1000 + (unsigned long long)(stktv.tv_usec) / 1000;
left->forward();
right->forward();
left->setSpeed(forward_speed);
right->setSpeed(forward_speed);
r_init = false; l_init = false; f_cnt = 0;
initialized = true;
}
void forward_run() {
left->run();
right->run();
odo->run();
map->update_grid(current);
std::cout<<"x position: "<<current->x()<<" y position: "<<current->y()<<" theta: "<<current->theta()<<std::endl;
}
void wall_dealer() {
map->whole_update();
odo->run();
float dis;
if (wall_side==0) {
dis = irlf->getDistance();
std::cout<<"wall in left: "<<dis<<std::endl;
map->is_wall(current,dis,-1.57);
}
else{
if (wall_side==1) {
dis = irr->getDistance();
std::cout<<"wall in right: "<<dis<<std::endl;
map->is_wall(current,dis,1.57);
}
else{
if (wall_side==2) {
dis = irf->getDistance();
std::cout<<"wall in front: "<<dis<<std::endl;
map->is_wall(current,dis,0);
std::cout<<"I updated is wall"<<std::endl;
}
}
}
}
void turn_setup() {
float angle = map->plan(current);
motion->rotate(angle);
initialized = true;
end_turn = false;
}
void turn_run() {
end_turn = motion->run();
}
bool turn_next() {
return end_turn;
}
bool forward_next () {
float dlf = irlf->getDistance();
float dr = irr->getDistance();
float df = irf->getDistance();
std::cout<<"dlf: "<< dlf<<" dr: "<<dr<<" df: "<<df<<std::endl;
if (!((dlf>forward_side_dis_threshold) && (dr>forward_side_dis_threshold) && (df>forward_front_dis_threshold) && (!irb->read()))) {
if (df<=forward_front_dis_threshold) { //front wall dealer
if (f_cnt<0) f_cnt++;
else {
wall_side = 2;
return true;
}
}
else f_cnt = 0;
if (dlf<=forward_side_dis_threshold) { //left wall dealer
if (!l_init) {
l_start = current;
l_init = true;
}
else {
if ((current->distance(l_start))>block_size) {
wall_side = 0;
return true;
}
}
}
else l_init = false;
if (dr<=forward_side_dis_threshold) {
if(!r_init) {
r_start = current;
r_init = true;
}
else {
if ((current->distance(r_start))>block_size) {
wall_side = 1;
return true;
}
}
}
else r_init = false;
}
else {
r_init = false;
l_init = false;
f_cnt = 0;
}
return false;
}
};