kao yi
/
BX-car
running car
Fork of Boboobooo by
main.cpp
- Committer:
- backman
- Date:
- 2014-06-11
- Revision:
- 6:5a39bde2e016
- Parent:
- 3:c5f2281b3ed2
- Child:
- 7:fd976e1ced33
File content as of revision 6:5a39bde2e016:
#include "mbed.h" #include "servo_api.h" #include "camera_api.h" #include "motor_api.h" #define Debug_cam_uart #define R_eye //#define motor_on #define Pcontroller //#define servo_center Serial pc(USBTX, USBRX); BX_servo servo; BX_camera cam; BX_motor MotorA('A'); BX_motor MotorB('B'); int main() { /* int black_va; int white_va; */ #ifdef servo_center while(1) servo.set_angle(0); #endif pc.baud(115200); #ifdef Pcontroller int car_center=30; double Kp= 90.0/64.0; #ifdef motor_on double motor=0.3; MotorA.rotate(motor); MotorB.rotate(motor); #endif int error=0; while(1){ cam.read(); // #ifdef Debug_cam_uart #ifdef L_eye for(int i=0;i<128;i++){ if(i==64) pc.printf("X"); else pc.printf("%c", cam.sign_line_imageL[i]); } pc.printf(" || "); #endif // #ifdef R_eye for(int i=0;i<128;i++){ if(i==64) pc.printf("X"); else pc.printf("%c", cam.sign_line_imageR[i]); } pc.printf("\r\n"); // #endif // #endif error=car_center-cam.black_centerR(); servo.set_angle((int)Kp*error); 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); } #endif return 0; }