-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexam_cv.cpp
1968 lines (1758 loc) · 62.7 KB
/
exam_cv.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
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <iostream>
#include <stdio.h>
//#include <sys/time.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
//#include <opencv2/gpu/device/utility.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include "car_lib.h"
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <termio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <fstream>
#include <math.h>
#include <queue>
#define PI 3.1415926
#define LOCALHOST "10.10.70.1"
#define PORT 7200
#define FRAME_WIDTH 320
#define FRAME_HEIGHT 180
#define RACING_MODE true
#define MODE_STOP 0
#define MODE_LANE_TRACING 1
#define MODE_INTERSECTION_WAITING 2
#define MODE_INTERSECTION_RUN 3
#define MODE_TRAFFIC_LIGHT_WAITING 4
#define MODE_LEFT_LANE_TRACING 5
#define MODE_RIGHT_LANE_TRACING 6
#define MODE_EMERGENCY_STOP 7
#define MODE_PARKING_1 8
#define MODE_PARKING_2 9
#define MODE_OVERKATE 10
#define MODE_FINISH_LINE 11
#define MODE_INTERSECTION_STOP 12
#define MODE_TRAFFIC_LIGHT_LEFT 13
#define MODE_TRAFFIC_LIGHT_RIGHT 14
#define MODE_GO_STRAIGHT 15
#define MODE_FINDING_YELLO_LINE 16
#define MODE_END 17
#define MODE_LEFT_TURN 18
#define NO_LANE_TURN_ANGLE 50
#define NO_LANE_TURN_ANGLE_AFTER 100
#define SPEED_SLOW 150
#define SPEED_FAST 150
using namespace std;
using namespace cv;
extern "C" {
void error(const char *msg)
{
perror(msg);
exit(0);
}
bool isIntersectionMissionEnd = false;
int sockfd, portno, n, imgSize, IM_HEIGHT, IM_WIDTH;
struct sockaddr_in serv_addr;
struct hostent *server;
char buffer[256];
Mat cameraFeed;
int wheelAngle;
bool leftLaneExist;
bool rightLaneExist;
float leftLaneAngle;
float rightLaneAngle;
int runningSpeed = SPEED_FAST;
void openStreaming()
{
cout << "socket init" << endl;
portno = PORT;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
error("ERROR opening socket");
server = gethostbyname(LOCALHOST);
if (server == NULL)
{
fprintf(stderr, "ERROR, no such host\n");
exit(0);
}
bzero((char *)&serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
serv_addr.sin_port = htons(portno);
if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
error("ERROR connecting");
cout << "socket init end" << endl;
}
// 소캣 닫기
void closeStreaming(){
close(sockfd);
}
// 이미지 전송
void streamingClient(Mat *cameraFeed)
{
static int c = 1;
if (c == 1)
openStreaming();
c++;
static int count = 0;
count++;
if (count % 3 != 0)
return;
imgSize = (*cameraFeed).total() * (*cameraFeed).elemSize();
n = send(sockfd, (*cameraFeed).data, imgSize, 0);
if (n < 0)
error("ERROR writing to socket");
}
class LightControll{
private:
bool front_on;
bool back_on;
int num;
void turn(){
if (back_on && front_on){
CarLight_Write(3);
}
else if(!back_on && front_on){
CarLight_Write(1);
}
else if(back_on && !front_on){
CarLight_Write(2);
}
else{
CarLight_Write(0);
}
}
public:
void frontToggle(){
front_on = !front_on;
this->turn();
}
void frontOn(){
front_on = true;
this->turn();
}
void frontOff(){
}
void backToggle(){
back_on = !back_on;
this->turn();
}
};
LightControll lightControll;
void CarStop(){
DesireSpeed_Write(0); // -500 ~ 500
SteeringServoControl_Write(1500); //1000~2000
}
void CarRun(int angle){
DesireSpeed_Write(runningSpeed); // -500 ~ 500
SteeringServoControl_Write(angle); //1000~2000
}
int getch(void)
{
int ch;
struct termios buf;
struct termios save;
tcgetattr(0, &save);
buf = save;
buf.c_lflag &= ~(ICANON|ECHO);
buf.c_cc[VMIN] = 1;
buf.c_cc[VTIME] = 0;
tcsetattr(0, TCSAFLUSH, &buf);
ch = getchar();
tcsetattr(0, TCSAFLUSH, &save);
return ch;
}
string getkey(void){
int temp = getch();
// direction key
if(temp == 27){
getch();
temp = getch();
if (temp == 65) return "^";
else if (temp == 66) return "v";
else if(temp == 67) return ">";
else return "<";
}
else if(temp == 127) return "back";
else if(temp == 10) return "enter";
else if(temp == 32) return "space";
else {
string out;
out += (char)temp;
return out;
}
}
typedef struct Mode{
int run; // 0 : 정지, 1 : 0 차선주행, 2 : logicalMove, 3 : 외쪽차선 주행, 4 : 오른쪽 차선 주행, 5 : 터널 주행
int view;
int cameraAngle;
int minPixelCount;
int maxVariance;
}Mode;
struct Points{
public:
int row;
int col;
Points(){}
Points (int row, int col){
this->row = row;
this->col = col;
}
};
struct Hsv {
public:
int H_max;
int H_min;
int S_max;
int S_min;
int V_max;
int V_min;
};
struct Homography {
public:
Points upperPoint;
Points lowerPoint;
};
struct LineDetection {
public:
Homography homography;
Hsv binarization;
};
struct TrafficLight {
public:
Hsv red;
Hsv green;
Hsv orange;
Hsv arrow;
int sizeMax;
int sizeMin;
float circleConvexityMin;
float arrowConvexityMax;
float circleCircularityMin;
float arrowCircularityMax;
};
struct StopSign {
public:
Hsv red;
int sizeMax;
int sizeMin;
float convexityMax;
float convexityMin;
float circularityMax;
float circularityMin;
};
struct Params {
public:
LineDetection lineDetection;
TrafficLight trafficLight;
StopSign stopsign;
Mode mode;
int streaming; // -1 : 닫기 수행(close), 0 : 닫혀있는 상황, 1 : 열기 수행(open, streamingClient), 2 : 열려있는 상황(streamingClient)
};
Params * p = new Params();
void moveCamera(){ // 카메라 움직이기
CameraYServoControl_Write(p->mode.cameraAngle);
}
// 주차장, 추월차로
class logicalMove{
//SpeedControlOnOff_Write(1);
//PositionControlOnOff_Write(UNCONTROL);
//SteeringServoControl_Write() 1000~ 2000
//DesireEncoderCount_Read
//DesireEncoderCount_Write
private:
class logic{
private:
int angle;
int distance;
int state;
int wall_distance;
bool detectWall;
bool buzzer;
public:
logic(){}
logic(int angle, int distance, bool detectWall, bool buzzer){
this->angle = angle;
this->distance = distance;
this->state = 0; // 0 : ready, 1 : setAngle, 2 : move
this->detectWall = detectWall;
this->buzzer = buzzer;
}
void move(){
if(this->state == 0){
this->state = 1;
}
else if(this->state == 1){
DesireSpeed_Write(0);
SteeringServoControl_Write(this->angle);
if(SteeringServoControl_Read() == this->angle){
state = 2;
DesireEncoderCount_Write(this->distance);
//cout << "set : " << DesireEncoderCount_Read() << endl;
//cout << "dist" << this->distance << endl;
}
}
else if(this->state == 2){
if(this->distance > 0) DesireSpeed_Write(100);
else DesireSpeed_Write(-100);
//cout << "DesireEncoderCount_Read() : " << DesireEncoderCount_Read() << endl;
if(abs(DesireEncoderCount_Read()) < 120 || (this->detectWall && LineSensor_Read() == 0)){
//cout << " end " << endl;
if(buzzer){
Alarm_Write(255);
sleep(1);
Alarm_Write(0);
}
DesireSpeed_Write(0);
state = 0;
}
}
}
bool isReady(){
if(this->state == 0) return true;
else return false;
}
};
int logic_count;
logic logic_arr[20];
int state;
int logic_now;
public:
logicalMove(){
logic_count = 0;
state = 0;
logic_now = 0;
}
logicalMove * addLogic(int angle, int distance, bool detectWall, bool buzzer){
logic_arr[logic_count] = logic(angle, distance, detectWall, buzzer);
logic_count++;
return this;
}
void run(){
//cout << "logic now" << this->logic_now << "DesireEncoderCount_Read() : " << DesireEncoderCount_Read() << endl;
if(this->state == 0){
SpeedControlOnOff_Write(1);
PositionControlOnOff_Write(1);
this->state = 1;
}
if(this->state == 1){
logic_arr[logic_now].move();
if(logic_arr[logic_now].isReady()){
this->logic_now++;
}
if(this->logic_now == this->logic_count){
SpeedControlOnOff_Write(0);
PositionControlOnOff_Write(0);
this->logic_now = 0;
this->state = 2;
if(p->mode.run == MODE_OVERKATE){
p->mode.run = MODE_TRAFFIC_LIGHT_WAITING;
CameraYServoControl_Write(1600);
CarStop();
}
else if(p->mode.run == MODE_TRAFFIC_LIGHT_LEFT || p->mode.run == MODE_TRAFFIC_LIGHT_RIGHT){
cout << "racing end" << endl;
p->mode.run = MODE_END;
CarStop();
}
else if(p->mode.run == MODE_LEFT_TURN){
p->mode.run = MODE_TRAFFIC_LIGHT_WAITING;
CameraYServoControl_Write(1600);
lightControll.frontOff();
CarStop();
}
else{
p->mode.run = MODE_LEFT_LANE_TRACING;
runningSpeed = SPEED_FAST;
}
}
}
}
};
logicalMove parking1;
logicalMove parking2;
logicalMove overtake;
logicalMove trafficLightLeft;
logicalMove trafficLightRight;
logicalMove leftTurn;
void initParams(){
// 불 켜기
lightControll.frontOn();
// 파일 스트림 열기
ifstream ifs("params.txt", ios::binary);
// 읽어오기
ifs.read((char *)p, sizeof(*p));
ifs.close();
// 초기 셋팅 설정
p->mode.run = 0; // 시작과 동시에 출발하려면 1로 변경
p->streaming = 0;
p->mode.view = 1;
p->mode.cameraAngle = 1710;
// p->lineDetection.homography.upperPoint.row = 18;
// p->lineDetection.homography.upperPoint.col = 102;
// p->lineDetection.binarization.H_max = 103;
// p->lineDetection.binarization.H_min = 60;
// p->lineDetection.binarization.S_max = 139;
// p->lineDetection.binarization.S_min = 68;
// p->lineDetection.binarization.V_max = 255;
// p->lineDetection.binarization.V_min = 208;
parking2.addLogic(1500, 700, false, false)
->addLogic(1000, -1400, false, false)
->addLogic(1500, -500, false, true) // 주차
->addLogic(1500, 500, false, false)
->addLogic(1000, 1400, false, false);// 복귀
// parking1.addLogic(1500, 500, false, false)
// ->addLogic(1000, -1400, false, false)
// ->addLogic(1500, -300, true, false)
// ->addLogic(1000, 800, false, false)
// ->addLogic(2000, -900, false, true) // 추차
// ->addLogic(2000, 900, false, false)
// ->addLogic(1000, -800, false, false)
// ->addLogic(1500, 300, false, false)
// ->addLogic(1000, 1400, false, false);// 복귀
parking1.addLogic(1500, 650, false, false)
->addLogic(1000, - 900, false, false)
->addLogic(1400, -300, false, false)
->addLogic(2000, -800, false, true)
->addLogic(2000, 800, false, false)
->addLogic(1400, 300, false, false)
->addLogic(1000, 800, false, false);
//->addLogic(1500, 400, false, false);
trafficLightLeft.addLogic(1500, 800, false, false)
->addLogic(2000, 1250, false, false)
->addLogic(1500, 800, false, false);
trafficLightRight.addLogic(1500,800, false, false)
->addLogic(1000, 1250, false, false)
->addLogic(1500, 800, false, false);
overtake.addLogic(1500, 1000, true, false)
->addLogic(1500, -700, false, false)
->addLogic(2000, 350, false, false)
->addLogic(1000, 350, false, false)
->addLogic(1500, 500, true, true);
leftTurn.addLogic(1500, 500, false, false)
->addLogic(1900, 1800, false, false) //좌회전
->addLogic(1500, 200, false, false) // 직진
->addLogic(1000, 1000, false, false) // 오른쪽 차선으로 바꾸기
->addLogic(2000, 1000, false, false)
->addLogic(1500, 500, false, false) //직진
->addLogic(2000, 1000, false, false) // 왼쪽 차선으로 바꾸기
->addLogic(1000, 1000, false, false)
->addLogic(1500, 200, false, true); //직진
moveCamera();
}
void saveParams(){
// output 파일 스트림을 열고
ofstream ofs("params.txt", ios::binary);
// 그 스트림에 Student 객체를 밀어 넣는다.
ofs.write((char *)p, sizeof(*p));
cout << "params saved" << endl;
ofs.close();
}
class Controller {
private:
public:
Controller * child[10];
int childCnt;
string menuName;
string paramName;
string paramType; // Hsv, Point
int * intParam;
Hsv * hsvParam;
Points * pointParam;
float * floatParam;
bool isMenu;
bool isMain;
int selectedMenu;
// 생성자
Controller() {
}
Controller(string name, bool isMenu) {
childCnt = 0;
this->menuName = menuName;
if (isMenu) {
this->menuName = name;
}
else {
this->paramName = name;
}
this->isMenu = isMenu;
this->isMain = false;
}
void setParam(Points * pointParam) {
this->pointParam = pointParam;
this->paramType = "Point";
}
void setParam(Hsv * hsvParam) {
this->hsvParam = hsvParam;
this->paramType = "Hsv";
}
void setParam(int * intParam) {
this->intParam = intParam;
this->paramType = "int";
}
void setParam(float * floatParam) {
this->floatParam = floatParam;
this->paramType = "float";
}
void changeParam(string key) {
if (this->paramType == "Point") {
changeParamPoint(this->pointParam, key);
}
else if(this->paramType == "Hsv"){
changeParamHsv(this->hsvParam, key);
}
else if(this->paramType == "int"){
changeParamint(this->intParam, key);
}
else if(this->paramType == "float"){
changeParamfloat(this->floatParam, key);
}
}
void changeParamPoint(Points * p, string key) {
if (key == "<") {
p->col--;
}
else if (key == ">") {
p->col++;
}
else if (key == "^") {
p->row--;
}
else if (key == "v") {
p->row++;
}
}
void changeParamHsv(Hsv * h, string key){
if (key == "q"){
this->hsvParam->H_max += 2;
}
else if(key == "a"){
this->hsvParam->H_max -= 2;
}
else if(key == "w"){
this->hsvParam->H_min += 2;
}
else if(key == "s"){
this->hsvParam->H_min -= 2;
}
else if(key == "e"){
this->hsvParam->S_max += 2;
}
else if(key == "d"){
this->hsvParam->S_max -= 2;
}
else if(key == "r"){
this->hsvParam->S_min += 2;
}
else if(key == "f"){
this->hsvParam->S_min -= 2;
}
else if(key == "t"){
this->hsvParam->V_max += 2;
}
else if(key == "g"){
this->hsvParam->V_max -= 2;
}
else if(key == "y"){
this->hsvParam->V_min += 2;
}
else if(key == "h"){
this->hsvParam->V_min -= 2;
}
}
void changeParamint(int * i, string key){
if(key == "^"){
(*i) += 5;
}
else if(key == "v"){
(*i) -= 5;
}
if(this->paramName == "Camera Angle") moveCamera();
}
void changeParamfloat(float * f, string key){
if(key == "^"){
(*f) += 0.01;
}
else if(key == "v"){
(*f) -= 0.01;
}
}
void setIsMain() {
this->isMain = true;
}
void setMenuName(string name) {
this->menuName = name;
}
void printMenu() {
cout << "*** " << menuName << " ***" << endl << endl;
for (int i = 0; i < childCnt; i++) {
if(this->child[i]->isMenu) {
cout << child[i]->menuName;
if(this->selectedMenu == i){
cout << " O" << endl;
}
else cout << endl;
}
else {
cout << child[i]->paramName;
if(this->selectedMenu == i){
cout << " O" << endl;
}
else cout << endl;
}
}
}
void printParam() {
cout << "*********** change param ***********" << endl;
cout << "*** " << this->paramName << " ***" << endl << endl;
if(this->paramType == "Point"){
cout << "row : " << this->pointParam->row << endl;
cout << "col : " << this->pointParam->col << endl;
}
else if(this->paramType == "Hsv"){
cout << "H Max : " << this->hsvParam->H_max << endl;
cout << "H min : " << this->hsvParam->H_min << endl;
cout << "S Max : " << this->hsvParam->S_max << endl;
cout << "S min : " << this->hsvParam->S_min << endl;
cout << "V Max : " << this->hsvParam->V_max << endl;
cout << "V min : " << this->hsvParam->V_min << endl;
}
else if(this->paramType == "int"){
cout << "value : " << *this->intParam << endl;
}
else if(this->paramType == "float"){
cout << "value : " << *this->floatParam << endl;
}
}
Controller * addChild(Controller * child) {
this->child[childCnt] = child;
childCnt++;
return this;
}
void start() {
string key;
selectedMenu = 0;
while (1) {
system("clear");
if(isMenu) printMenu();
if (!isMenu) printParam();
// 키 입력
key = getkey();
// 메뉴일 때
if (this->isMenu) {
if (key == "^" && selectedMenu > 0) {
selectedMenu--;
}
else if (key == "v" && selectedMenu < childCnt - 1) {
selectedMenu++;
}
// 엔터 눌렀을 때
else if (key == "enter") {
child[selectedMenu]->start();
}
// 뒤로가기 눌렀을 때
else if (key == "back" && !this->isMain) {
break;
}
else if(key == "1"){
p->mode.view = 1;
}
else if(key == "2"){
p->mode.view = 2;
}
else if(key == "3"){
p->mode.view = 3;
}
else if(key == "4"){
p->mode.view = 4;
}
else if(key == "5"){
p->mode.view = 5;
}
else if(key == "6"){
p->mode.view = 6;
}
else if(key == "7"){
p->mode.view = 7;
}
else if(key == "8"){
p->mode.view = 8;
}
else if(key == "9"){
p->mode.view = 9;
}
else if(key == "m"){
if(p->streaming == 0) p->streaming = 1;
else if(p->streaming == 2) p->streaming = -1;
}
else if(key == "space"){
if(p->mode.run == 0) p->mode.run = MODE_LEFT_LANE_TRACING;
else p->mode.run = 0;
}
else if(key == "s"){ // 파라미터 저장
saveParams();
}
else if(key == "l"){ // 파라미터 불러오기
lightControll.frontToggle();
}
else if(key == "z"){ // 주차장 1번
p->mode.run = MODE_PARKING_1;
}
else if(key == "x"){ // 주차장 2번
p->mode.run = MODE_PARKING_2;
}
else if(key == "c"){ // 추월 미션 테스트
isIntersectionMissionEnd = true;
p->mode.run = MODE_RIGHT_LANE_TRACING;
}
else if(key == "b"){ // 신호등 오른쪽
p->mode.run = MODE_TRAFFIC_LIGHT_RIGHT;
}
else if(key == "n"){ // 신호등 테스트
p->mode.run = MODE_TRAFFIC_LIGHT_WAITING;
CameraYServoControl_Write(1500);
}
}
// 파라미터일때
else {
// 엔터 눌렀을 때
if (key == "enter") {
break;
}
// 뒤로가기 눌렀을 때
else if (key == "back") {
break;
}
else if(key == "1"){ // 기본
p->mode.view = 1;
}
else if(key == "2"){ // homography 상단 점
p->mode.view = 2;
}
else if(key == "3"){ // homography rgb
p->mode.view = 3;
}
else if(key == "4"){ // homography 이진화
p->mode.view = 4;
}
else if(key == "5"){ // 돌발표지
p->mode.view = 5;
}
else if(key == "6"){ // 신호등 빨간색
p->mode.view = 6;
}
else if(key == "7"){ // 신호등 주황색
p->mode.view = 7;
}
else if(key == "8"){ // 신호등 초록색
p->mode.view = 8;
}
else if(key == "9"){ // 신호등 화살표
p->mode.view = 9;
}
else if(key == "m"){
if(p->streaming == 0) p->streaming = 1;
else if(p->streaming == 2) p->streaming = -1;
}
else if(key == "space"){
if(p->mode.run == 0) p->mode.run = MODE_LEFT_LANE_TRACING;
else p->mode.run = 0;
}
else if(key == "l"){ // 파라미터 불러오기
lightControll.frontToggle();
}
else {
changeParam(key);
}
}
}
}
};
void keyboardController(Params* params) {
p = params;
//main
Controller * main = new Controller("Main", true);
// mian -> line detection
Controller * lineDetection = new Controller("Line Detection", true);
// mian -> line detection -> homography
Controller * homography = new Controller("Homography", true);
Controller * upperPoint = new Controller("Upper Point", false);// 파라미터
upperPoint->setParam(¶ms->lineDetection.homography.upperPoint);
// mian -> line detection -> binarization
Controller * binarization = new Controller("Binarization", false);
binarization->setParam(¶ms->lineDetection.binarization);
// main -> traffic light
Controller * trafficLight = new Controller("Traffic Light", true);
//main -> traffic light -> traffic light red
Controller * trafficLightRed = new Controller("traffic Light Red", false);
trafficLightRed->setParam(¶ms->trafficLight.red);
Controller * trafficLightGreen = new Controller("traffic Light Green", false);
trafficLightGreen->setParam(¶ms->trafficLight.green);
Controller * trafficLightorange = new Controller("traffic Light Orange", false);
trafficLightorange->setParam(¶ms->trafficLight.orange);
Controller * trafficLightArrow = new Controller("traffic Light Arrow", false);
trafficLightArrow->setParam(¶ms->trafficLight.arrow);
Controller * trafficLightMaxSize = new Controller("traffic Light Max Size", false);
trafficLightMaxSize->setParam(¶ms->trafficLight.sizeMax);
Controller * trafficLightMinSize = new Controller("traffic Light Min Size", false);
trafficLightMinSize->setParam(¶ms->trafficLight.sizeMin);
Controller * trafficLightCircleConvexityMin = new Controller("traffic Light Circle Convexity Min", false);
trafficLightCircleConvexityMin->setParam(¶ms->trafficLight.circleConvexityMin);
Controller * trafficLightArrowConvexityMax = new Controller("traffic Light Arrow Convexity Max", false);
trafficLightArrowConvexityMax->setParam(¶ms->trafficLight.arrowConvexityMax);
Controller * trafficLightCircleCircularityMin = new Controller("traffic Light Circle Circularity Min", false);
trafficLightCircleCircularityMin->setParam(¶ms->trafficLight.circleCircularityMin);
Controller * trafficLightArrowCircularityMax = new Controller("traffic Light arrow Circularity Max", false);
trafficLightArrowCircularityMax->setParam(¶ms->trafficLight.arrowCircularityMax);
// main -> stop sign
Controller * stopSign = new Controller("StopSign", true);
// main -> stop sign -> Hsv
Controller * stopSignHsv = new Controller("Stop Sign Hsv", false);
stopSignHsv->setParam(¶ms->stopsign.red);
Controller * stopSignMaxSize = new Controller("Stop Sign Size Max", false);
stopSignMaxSize->setParam(¶ms->stopsign.sizeMax);
Controller * stopSignMinSize = new Controller("Stop Sign Size Min", false);
stopSignMinSize->setParam(¶ms->stopsign.sizeMin);
Controller * stopSignMaxConvexity = new Controller("Stop Sign Max Convexity", false);
stopSignMaxConvexity->setParam(¶ms->stopsign.convexityMax);
Controller * stopSignMinConvexity = new Controller("Stop Sign Min Convexity", false);
stopSignMinConvexity->setParam(¶ms->stopsign.convexityMin);
Controller * stopSignMaxCircularity = new Controller("Stop Sign Max Circularity", false);
stopSignMaxCircularity->setParam(¶ms->stopsign.circularityMax);
Controller * stopSignMinCircularity = new Controller("Stop Sign Min Circularity", false);
stopSignMinCircularity->setParam(¶ms->stopsign.circularityMin);
// main-> mode
Controller * mode = new Controller("Mode", true);
//main -> mode -> cameraAngle
Controller * cameraAngle = new Controller("Camera Angle", false);
cameraAngle->setParam(¶ms->mode.cameraAngle);
Controller * minPixelCount = new Controller("Min Pixel Count", false);
minPixelCount->setParam(¶ms->mode.minPixelCount);
Controller * maxPixelVariance = new Controller("Max Pixel Variance", false);
maxPixelVariance->setParam(¶ms->mode.maxVariance);
main->addChild(lineDetection)
->addChild(trafficLight)
->addChild(stopSign)
->addChild(mode)
->setIsMain();
lineDetection->addChild(homography)
->addChild(binarization);
homography->addChild(upperPoint);
trafficLight->addChild(trafficLightRed)
->addChild(trafficLightGreen)
->addChild(trafficLightorange)
->addChild(trafficLightArrow)
->addChild(trafficLightMaxSize)
->addChild(trafficLightMinSize)
->addChild(trafficLightCircleCircularityMin)
->addChild(trafficLightArrowCircularityMax)
->addChild(trafficLightCircleConvexityMin)
->addChild(trafficLightArrowConvexityMax);
stopSign->addChild(stopSignHsv)
->addChild(stopSignMaxSize)
->addChild(stopSignMinSize)
->addChild(stopSignMaxConvexity)
->addChild(stopSignMinConvexity)
->addChild(stopSignMaxCircularity)
->addChild(stopSignMinCircularity);
mode->addChild(cameraAngle)
->addChild(minPixelCount)
->addChild(maxPixelVariance);
main->start();
}
class point{
public:
int x;
int y;
};
#define SCENARIO_STRAIGHT_LANE_1 0
#define SCENARIO_PARKINT_1 1
#define SCENARIO_STRAIGHT_LANE_2 2
#define SCENARIO_CURVE_1_RIGHT 3
#define SCENARIO_STRAIGHT_LANE_3 4
#define SCENARIO_PARKINT_2 5
#define SCENARIO_STRAIGHT_LANE_4 6
#define SCENARIO_CURVE_2_RIGHT 7
#define SCENARIO_INTERSECTION 8
#define SCENARIO_STRAIGHT_LANE_5 9
#define SCENARIO_CURVE_3_LEFT 10
#define SCENARIO_HILL 11
#define SCENARIO_CURVE_4_LEFT 12
#define SCENARIO_STRAIGHT_LANE_6 13
#define SCENARIO_TUNNEL 14
#define SCENARIO_STRAIGHT_LANE_7 15
#define SCENARIO_CURVE_5_LEFT 16
#define SCENARIO_STRAIGHT_LANE_8 17
#define SCENARIO_CHANGE_LANE 18
#define SCENARIO_GO_TO_TRAFFIC_LIGHT 19