EE149
/
FinalProject
Final Project files for mBed development.
Revision 32:8b589710632b, committed 2014-12-09
- Comitter:
- lsaristo
- Date:
- Tue Dec 09 22:56:54 2014 +0000
- Parent:
- 31:1e950ee04481
- Child:
- 33:8e2e8b664938
- Commit message:
- Added pi.stop()s back in. Removed unneeded stuff.
Changed in this revision
--- a/main.c Tue Dec 09 21:18:07 2014 +0000 +++ b/main.c Tue Dec 09 22:56:54 2014 +0000 @@ -34,15 +34,12 @@ int instbuflen = 250; char instbuf[instbuflen]; - start_button.mode(PullUp); + // --------------------------------------------------------- + // First calibrate robot and figure out space dimensions. pi.cls(); - pi.locate(0,0); - pi.printf("Ready"); pi.locate(0,1); pi.printf("%f mV", pi.battery()); pi.sensor_auto_calibrate(); - - wait(1); do { pos = pi.line_position(); @@ -67,7 +64,6 @@ return 1; } left(180); - Timer caltimer; caltimer.start(); do { @@ -95,7 +91,8 @@ return 1; } right(180); - timerWait(.5); + timerWait(.2); + while(fabs(pos = pi.line_position()) > CLOSE_ENOUGH) { pi.right((pos < 0 ? -.6*CAL_SPEED : .6*CAL_SPEED)); pi.cls(); @@ -103,23 +100,12 @@ pi.printf("O: %f", pos); } pi.stop(); - timerWait(0.5); + timerWait(0.2); backward(500); - - /* Maybe uncomment this depending on the surface. - timerWait(.5); - while(fabs(pos = pi.line_position()) > CLOSE_ENOUGH) { - pi.right((pos < 0 ? -.6*CAL_SPEED : .6*CAL_SPEED)); - pi.cls(); - pi.locate(0,0); - pi.printf("O: %f", pos); - } - pi.stop(); - */ - - timerWait(.6); - // Main program loop. + // --------------------------------------------------------- + // DONE calibrating. Begin reading in coordinate + // file and run robot. size_t bytes_read = 0; int err, x, y, last_x, last_y, delta_x, delta_y; float delta_a; @@ -154,8 +140,12 @@ cur++; offset = instbuf+instbuflen-cur-1; memcpy(instbuf, cur, offset); + + + // --------------------------------------------------------- + // File open and buffer setup. Begin reading instructions and + // moving robot. Refill buffer after each instruction. while (1) { - timerWait(.18); memset(instbuf+offset, 0, instbuflen-offset); bytes_read = fread(instbuf+offset, sizeof(char), instbuflen-1-offset, ps_file); @@ -168,12 +158,14 @@ cur = instbuf; err = retrieve_inst(instbuf, &x, &y, &draw); + if (err == 0) { pi.cls(); pi.locate(0,0); pi.printf("noinst"); return 1; } + delta_x = x-last_x; delta_y = y-last_y; @@ -184,13 +176,14 @@ theta += 180; } delta_a = theta-angle; + if (delta_x < 0 && delta_y < 0) { delta_a += 180; } + if (delta_a > 180) { delta_a -= 360; - } - if (delta_a < -180) { + } else if (delta_a < -180) { delta_a = 360 + delta_a; } angle += delta_a; @@ -200,7 +193,6 @@ pi.cls(); pi.locate(0,0); pi.printf("a:%f", delta_a); - timerWait(1.5); left(delta_a); /* Put pen into position. */ @@ -218,7 +210,6 @@ pi.cls(); pi.locate(0,0); pi.printf("d:%f", 0.4*cal_time*(dist/(double)dim_x)); - timerWait(1.5); forward(0.4*cal_time*(dist/(double)dim_x)); last_x = x; @@ -237,6 +228,7 @@ pi.cls(); pi.locate(0,0); pi.printf("Done"); + pi.stop(); // Just in case. Prevent runaway polio. That's all bad! while (1); } @@ -277,7 +269,6 @@ pi.left_motor(DRIVE_SPEED+.0023); pi.right_motor(DRIVE_SPEED); while(t.read_ms() < amt); - t.stop(); pi.stop(); } @@ -286,10 +277,7 @@ Timer t; t.start(); pi.backward(.5*DRIVE_SPEED); - while(t.read_ms() < (amt-500)); - pi.backward(.5*DRIVE_SPEED); while(t.read_ms() < amt); - t.stop(); pi.stop(); } @@ -303,7 +291,6 @@ t.start(); pi.right(TURN_SPEED); while(t.read_ms() < amt); - t.stop(); pi.stop(); } @@ -312,7 +299,6 @@ Timer t; t.start(); while(t.read_us() < 1000000*seconds); - t.stop(); } void left(float deg) @@ -324,16 +310,5 @@ pi.left(TURN_SPEED); t.start(); while(t.read_ms() < ((float)(deg/360)*TIME_FACT)); - t.stop(); pi.stop(); -} - -void pen_down() -{ - oled_1 = 1; -} - -void pen_up() -{ - oled_1 = 0; } \ No newline at end of file
--- a/main.h Tue Dec 09 21:18:07 2014 +0000 +++ b/main.h Tue Dec 09 22:56:54 2014 +0000 @@ -25,7 +25,6 @@ #define CAL_SPEED .1 #define CLOSE_ENOUGH .0008 - /** @brief Move the robot from its current position to (x,y) */ void move(int x, int y, int draw);
--- a/user-gui.py Tue Dec 09 21:18:07 2014 +0000 +++ b/user-gui.py Tue Dec 09 22:56:54 2014 +0000 @@ -1,5 +1,5 @@ #!/usr/bin/python -""""Paint program by Dave Michell. +"""" NOTE: A substantial portion of this code was taken from Dave Michell's example illustrating how to draw on a Python-generated canvas. All credit @@ -8,6 +8,8 @@ # Start origin header ######################## +Paint program by Dave Michell. + Subject: tkinter "paint" example From: Dave Mitchell <davem@magnet.com> To: python-list@cwi.nl @@ -219,12 +221,37 @@ prev_x = prev_s[0] if prev: output_list.append(prev) - for move in output_list: - x_coord = move.split()[0] - y_coord = move.split()[1] - cmd = move.split()[2] + x0 = 0 + y0 = 0 + f_output_list = list() + i = 0 + while i < len(output_list)-1: + line1 = output_list[i].split(' ') + line2 = output_list[i+1].split(' ') + x1 = int(line1[0]) + x2 = int(line2[0]) + y1 = int(line1[1]) + y2 = int(line2[1]) + if line1[2] == line2[2] and dist(x0,y0,x1,y1) <= 10\ + and dist(x1,y1,x2,y2) <= 10: + x0 = x2 + y0 = y2 + i += 2 + f_output_list.append("%d %d %s" % (x2,y2,line1[2])); + else: + x0 = x1 + y0 = y1 + f_output_list.append(output_list[i]) + i += 1 + f_output_list.append(output_list[len(output_list)-1]) + print output_list + print "--------------------------------------------" + print f_output_list - return output_list + return f_output_list + +def dist(x1,y1,x2,y2): + return ((x2-x1)**2 + (y2-y1)**2)**.5 def b1down(event): global b1