EE149
/
FinalProject
Final Project files for mBed development.
Diff: main.c
- Revision:
- 26:a74edc4c6acb
- Parent:
- 25:2c7717684d09
- Child:
- 27:44a4a0abc8ee
--- a/main.c Mon Dec 08 04:21:55 2014 +0000 +++ b/main.c Mon Dec 08 04:27:33 2014 +0000 @@ -10,19 +10,17 @@ #include "main.h" #include "control.h" -/** - * These are global data Used externally in all other files - */ +/* These are global data Used externally in all other files */ m3pi pi; Timer timer; -// -// Digital inputs to the mBed +/* Digital inputs to the mBed */ DigitalIn start_button(p21); -// -// Digital outputs from the mBed. Note that by default these are -// used to drive the 8 LED's on the top board. +/* + * Digital outputs from the mBed. Note that by default these are + * used to drive the 8 LED's on the top board. + */ DigitalOut pin13(p13); DigitalOut pin14(p14); DigitalOut pin15(p15); @@ -32,8 +30,7 @@ DigitalOut pin19(p19); DigitalOut pin20(p20); -// -// mBed onboard LEDs +/* mBed onboard LEDs */ DigitalOut oled_1(LED1); DigitalOut oled_2(LED2); DigitalOut oled_3(LED3); @@ -54,7 +51,6 @@ int instbuflen = 250; char instbuf[instbuflen]; - // // Basic setup information start_button.mode(PullUp); @@ -64,72 +60,15 @@ pi.locate(0,1); pi.printf("%f mV", pi.battery()); wait(.5); - /* while(start_button) { - oled_2 = 1; - wait(.5); - pi.locate(0,0); - pi.printf("Ready"); - oled_2 = 0; - } */ - pi.cls(); - pi.locate(0,0); - // pi.printf("GO!"); - wait(.5); - - /* - while(1) { - if(!start_button) { - pi.stop(); - goto start; - } else { - goto calibrate; - } - } - */ - // // Drawing environment calibration. pi.sensor_auto_calibrate(); - //pi.backward(DRIVE_SPEED); float pos = 0; float over_thresh = 0.05; float correction = 0.2*DRIVE_SPEED; float cal_time; wait(1); - /* - do { - pos = pi.line_position(); - if(pos > over_thresh) { - pi.left_motor(-CAL_SPEED); - pi.right_motor(-CAL_SPEED+correction); - } else if(pos < -over_thresh) { - pi.right_motor(-CAL_SPEED); - pi.left_motor(-CAL_SPEED+correction); - } else { - pi.backward(CAL_SPEED); - } - pi.cls(); - pi.locate(0,0); - pi.printf("P: %f", pos); - } while (pos != -1 && pos <= 0.3); - pi.stop(); - wait(1); - - if (pos != -1) { - timer.start(); - pi.forward(CAL_SPEED); - } else { - pi.cls(); - pi.locate(0,0); - pi.printf("LP: %f",pos); - forward(1000); - goto calibrate; - return 1; - } - */ - - // wait(1); - + do { pos = pi.line_position(); if(pos > over_thresh) { @@ -189,16 +128,7 @@ } pi.stop(); timerWait(2); - /* - pos = pi.line_position(); - do { - pi.backward(CAL_SPEED); - pi.cls(); - pi.locate(0,0); - pi.printf("p:%f", pos); - pos = pi.line_position(); - } while (pos != -1 && pos >= -0.25); - */ + backward(500); timerWait(.5); while(fabs(pos = pi.line_position()) > CLOSE_ENOUGH) { @@ -209,96 +139,10 @@ } pi.stop(); timerWait(2); - /* - pos = pi.line_position(); - do { - pi.forward(CAL_SPEED); - pi.cls(); - pi.locate(0,0); - pi.printf("p:%f", pos); - pos = pi.line_position(); - } while (pos <= -0.07); - timerWait(0.25); - pi.stop(); - pos = pi.line_position(); - while(fabs(pos) > CLOSE_ENOUGH) { - pi.right((pos < 0 ? -CAL_SPEED : CAL_SPEED)); - timerWait(.08); - pi.cls(); - pi.locate(0,0); - pi.printf("O: %f", pos); - pi.stop(); - pos = pi.line_position(); - timerWait(.2); - } - */ + timerWait(1); - // - // Pivot 180 degrees to go to the starting position. - /* - do { - pos = pi.line_position(); - if(pos > over_thresh) { - pi.right_motor(-DRIVE_SPEED); - pi.left_motor(-DRIVE_SPEED+correction); - } else if(pos < -over_thresh) { - pi.left_motor(-DRIVE_SPEED); - pi.right_motor(-DRIVE_SPEED+correction); - } else { - pi.backward(DRIVE_SPEED); - } - pi.cls(); - pi.locate(0,0); - pi.printf("P: %f", pos); - } while (pos != -1 && pos > -0.3); - pi.stop(); - if(pos != -1) { - oled_1 = 1; - timer.stop(); - cal_time = timer.read(); - pi.cls(); - pi.locate(0,0); - pi.printf("T: %d", timer.read_ms()); - } else { - pi.cls(); - pi.locate(0,0); - pi.printf("lP:%f", pos); - return 1; - } - */ - /* - while(pi.line_position() == 1); - do { - pos = pi.line_position(); - if(pos > over_thresh) { - pi.right_motor(DRIVE_SPEED); - pi.left_motor(DRIVE_SPEED - correction); - } else if(pos < -over_thresh) { - pi.left_motor(DRIVE_SPEED); - pi.right_motor(DRIVE_SPEED - correction); - } else { - pi.forward(DRIVE_SPEED); - } - pi.cls(); - pi.locate(0,0); - pi.printf("Pos: %f", pos); - } while(pos != -1 && pos != 1); - if(pos == 1) { - oled_1 = 1; - timer.stop(); - pi.stop(); - } else { - pi.stop(); - pi.cls(); - pi.locate(0,0); - pi.printf("LP:%f", pos); - while(1); - } - */ - // // Main program loop. - // robot_loop(); size_t bytes_read = 0; int err, x, y, last_x, last_y, delta_x, delta_y; float delta_a; @@ -352,10 +196,6 @@ theta *= 57.29; delta_a = theta-angle; if (delta_x < 0 && delta_y < 0) { - //pi.cls(); - //pi.locate(0,0); - //pi.printf("pland"); - //timerWait(2); delta_a += 180; } angle += delta_a; @@ -395,10 +235,6 @@ cur = next+1; offset = instbuf+instbuflen-cur-1; memcpy(instbuf, cur, offset); - //pi.cls(); - //pi.locate(0,0); - //pi.printf("%.08s", instbuf); - //timerWait(2); } pi.cls(); pi.locate(0,0);