EE149
/
FinalProject
Final Project files for mBed development.
Diff: main.c
- Revision:
- 29:459ff10d2a07
- Parent:
- 28:9976a94efa83
- Child:
- 30:3211e2962441
--- a/main.c Mon Dec 08 10:52:42 2014 +0000 +++ b/main.c Mon Dec 08 22:43:09 2014 +0000 @@ -1,72 +1,48 @@ /** * @file driver.c - * @brief Basic driver program for our robot's controller logic. + * @brief Primary control logic for robot. * - * Maybe add lots of stuff here or maybe split it off into - * multiple subfiles? - * - * @author John Wilkey - aw hells no! you ain't takin' credit for all this! + * @author John Wilkey + * @author Alec Guertin + * @author Chester Chu */ #include "main.h" -#include "control.h" -/* These are global data Used externally in all other files */ -m3pi pi; -Timer timer; - -/* Digital inputs to the mBed */ -DigitalIn start_button(p21); +m3pi pi; /**< m3pi Object for all control operations. */ +Timer timer; /**< Timer used to wait in timerWait. */ +DigitalIn start_button(p21); /**< Pi start button input on mBed pin 32 */ +int draw; /**< Boolean for drawing/moving. */ -/* - * 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); -DigitalOut pin16(p16); -DigitalOut pin17(p17); -DigitalOut pin18(p18); -DigitalOut pin19(p19); -DigitalOut pin20(p20); +/* 4 mBed onboard LEDs */ +DigitalOut oled_1(LED1), oled_2(LED2), oled_3(LED3), oled_4(LED4); -/* mBed onboard LEDs */ -DigitalOut oled_1(LED1); -DigitalOut oled_2(LED2); -DigitalOut oled_3(LED3); -DigitalOut oled_4(LED4); +/* 8 LEDs driven from mBed digital outs. */ +DigitalOut pin13(p13), pin14(p14), pin15(p15), pin16(p16), + pin17(p17), pin18(p18), pin19(p19), pin20(p20); /* Local File System */ LocalFileSystem local("local"); -/* Boolean for drawing/moving. */ -int draw; - -/** - * @brief Entry point. Main loop. - */ +/** @brief Entry point. Main loop. */ int main() { - FILE *ps_file; - int instbuflen = 250; - char instbuf[instbuflen]; - - // Basic setup information + FILE *ps_file; + float cal_time; + float pos = 0; + float over_thresh = 0.05; + float correction = 0.2*DRIVE_SPEED; + int instbuflen = 250; + char instbuf[instbuflen]; + start_button.mode(PullUp); - pi.cls(); pi.locate(0,0); - pi.printf("PiCO"); + pi.printf("Ready"); pi.locate(0,1); pi.printf("%f mV", pi.battery()); wait(.5); - - // Drawing environment calibration. pi.sensor_auto_calibrate(); - float pos = 0; - float over_thresh = 0.05; - float correction = 0.2*DRIVE_SPEED; - float cal_time; + wait(1); do { @@ -256,9 +232,8 @@ } pi.cls(); pi.locate(0,0); - pi.printf("done"); + pi.printf("Done"); while (1); - return 0; } int retrieve_inst(char *buf, int *x, int *y, int *draw) @@ -289,7 +264,7 @@ return 1; } -int forward(int amt) +void forward(int amt) { Timer t; pi.locate(0,0); @@ -302,10 +277,9 @@ pi.right_motor(.7*DRIVE_SPEED); t.stop(); pi.stop(); - return EXIT_SUCCESS; } -int backward(int amt) +void backward(int amt) { Timer t; t.start(); @@ -315,10 +289,9 @@ while(t.read_ms() < amt); t.stop(); pi.stop(); - return EXIT_SUCCESS; } -int right(float deg) +void right(float deg) { if(deg < 0) { return left(-1*deg); @@ -329,7 +302,6 @@ while(t.read_ms() < ((float)(deg/360)*TIME_FACT)); t.stop(); pi.stop(); - return EXIT_SUCCESS; } void timerWait(float seconds) @@ -340,7 +312,7 @@ t.stop(); } -int left(float deg) +void left(float deg) { if(deg < 0) { return right(-1*deg); @@ -351,7 +323,6 @@ while(t.read_ms() < ((float)(deg/360)*TIME_FACT)); t.stop(); pi.stop(); - return EXIT_SUCCESS; } void pen_down()