good

Dependencies:   mbed

Fork of BX-car by Clark Lin

Committer:
backman
Date:
Wed Jun 11 14:41:52 2014 +0000
Revision:
6:5a39bde2e016
Parent:
3:c5f2281b3ed2
Child:
7:fd976e1ced33
three;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
backman 0:68c173249c01 1 #include "mbed.h"
backman 1:82bc25a7b68b 2 #include "servo_api.h"
backman 1:82bc25a7b68b 3 #include "camera_api.h"
backman 6:5a39bde2e016 4 #include "motor_api.h"
backman 3:c5f2281b3ed2 5
backman 3:c5f2281b3ed2 6 #define Debug_cam_uart
backman 6:5a39bde2e016 7 #define R_eye
backman 6:5a39bde2e016 8 //#define motor_on
backman 6:5a39bde2e016 9 #define Pcontroller
backman 6:5a39bde2e016 10 //#define servo_center
backman 6:5a39bde2e016 11 Serial pc(USBTX, USBRX);
backman 0:68c173249c01 12
backman 0:68c173249c01 13
backman 1:82bc25a7b68b 14 BX_servo servo;
backman 6:5a39bde2e016 15
backman 6:5a39bde2e016 16 BX_camera cam;
backman 0:68c173249c01 17
backman 6:5a39bde2e016 18 BX_motor MotorA('A');
backman 6:5a39bde2e016 19 BX_motor MotorB('B');
backman 3:c5f2281b3ed2 20
backman 3:c5f2281b3ed2 21
backman 0:68c173249c01 22 int main() {
backman 0:68c173249c01 23
backman 1:82bc25a7b68b 24 /*
backman 1:82bc25a7b68b 25 int black_va;
backman 1:82bc25a7b68b 26 int white_va;
backman 1:82bc25a7b68b 27 */
backman 6:5a39bde2e016 28
backman 6:5a39bde2e016 29 #ifdef servo_center
backman 6:5a39bde2e016 30
backman 1:82bc25a7b68b 31
backman 6:5a39bde2e016 32 while(1)
backman 6:5a39bde2e016 33 servo.set_angle(0);
backman 6:5a39bde2e016 34 #endif
backman 6:5a39bde2e016 35
backman 6:5a39bde2e016 36 pc.baud(115200);
backman 6:5a39bde2e016 37
backman 6:5a39bde2e016 38 #ifdef Pcontroller
backman 1:82bc25a7b68b 39
backman 1:82bc25a7b68b 40
backman 6:5a39bde2e016 41 int car_center=30;
backman 6:5a39bde2e016 42
backman 6:5a39bde2e016 43 double Kp= 90.0/64.0;
backman 1:82bc25a7b68b 44
backman 6:5a39bde2e016 45 #ifdef motor_on
backman 6:5a39bde2e016 46 double motor=0.3;
backman 6:5a39bde2e016 47
backman 6:5a39bde2e016 48
backman 6:5a39bde2e016 49
backman 6:5a39bde2e016 50 MotorA.rotate(motor);
backman 6:5a39bde2e016 51 MotorB.rotate(motor);
backman 6:5a39bde2e016 52 #endif
backman 6:5a39bde2e016 53 int error=0;
backman 6:5a39bde2e016 54
backman 6:5a39bde2e016 55
backman 6:5a39bde2e016 56 while(1){
backman 1:82bc25a7b68b 57
backman 6:5a39bde2e016 58 cam.read();
backman 6:5a39bde2e016 59
backman 6:5a39bde2e016 60 // #ifdef Debug_cam_uart
backman 6:5a39bde2e016 61
backman 6:5a39bde2e016 62 #ifdef L_eye
backman 1:82bc25a7b68b 63 for(int i=0;i<128;i++){
backman 1:82bc25a7b68b 64 if(i==64)
backman 1:82bc25a7b68b 65 pc.printf("X");
backman 1:82bc25a7b68b 66 else
backman 2:c51647d3c14d 67 pc.printf("%c", cam.sign_line_imageL[i]);
backman 2:c51647d3c14d 68 }
backman 2:c51647d3c14d 69 pc.printf(" || ");
backman 6:5a39bde2e016 70 #endif
backman 6:5a39bde2e016 71 // #ifdef R_eye
backman 2:c51647d3c14d 72 for(int i=0;i<128;i++){
backman 2:c51647d3c14d 73 if(i==64)
backman 2:c51647d3c14d 74 pc.printf("X");
backman 2:c51647d3c14d 75 else
backman 2:c51647d3c14d 76 pc.printf("%c", cam.sign_line_imageR[i]);
backman 1:82bc25a7b68b 77 }
backman 1:82bc25a7b68b 78 pc.printf("\r\n");
backman 6:5a39bde2e016 79 // #endif
backman 6:5a39bde2e016 80
backman 6:5a39bde2e016 81
backman 6:5a39bde2e016 82
backman 3:c5f2281b3ed2 83
backman 3:c5f2281b3ed2 84
backman 3:c5f2281b3ed2 85
backman 3:c5f2281b3ed2 86
backman 6:5a39bde2e016 87
backman 3:c5f2281b3ed2 88
backman 6:5a39bde2e016 89
backman 2:c51647d3c14d 90
backman 6:5a39bde2e016 91 // #endif
backman 1:82bc25a7b68b 92
backman 1:82bc25a7b68b 93
backman 1:82bc25a7b68b 94
backman 1:82bc25a7b68b 95
backman 1:82bc25a7b68b 96
backman 1:82bc25a7b68b 97
backman 1:82bc25a7b68b 98
backman 1:82bc25a7b68b 99
backman 1:82bc25a7b68b 100
backman 1:82bc25a7b68b 101
backman 1:82bc25a7b68b 102
backman 6:5a39bde2e016 103
backman 6:5a39bde2e016 104
backman 6:5a39bde2e016 105 error=car_center-cam.black_centerR();
backman 6:5a39bde2e016 106
backman 6:5a39bde2e016 107
backman 6:5a39bde2e016 108
backman 6:5a39bde2e016 109
backman 6:5a39bde2e016 110 servo.set_angle((int)Kp*error);
backman 1:82bc25a7b68b 111
backman 6:5a39bde2e016 112 pc.printf("b1s: %d b1e:%d b_center %d error :%d angle %d\r\n",cam.debugV,cam.debugV2,cam.black_centerR(),error,(int)Kp*error);
backman 6:5a39bde2e016 113
backman 6:5a39bde2e016 114
backman 6:5a39bde2e016 115 }
backman 6:5a39bde2e016 116 #endif
backman 6:5a39bde2e016 117
backman 6:5a39bde2e016 118
backman 0:68c173249c01 119
backman 0:68c173249c01 120
backman 0:68c173249c01 121
backman 1:82bc25a7b68b 122 return 0;
backman 0:68c173249c01 123
backman 0:68c173249c01 124
backman 0:68c173249c01 125 }