James Allen
/
MyMazeSolver
working modified m3pimazesolver
Diff: main.cpp
- Revision:
- 1:f4db9b0bb5e2
- Parent:
- 0:05dee1d3d857
- Child:
- 2:73f7cc4c30c7
diff -r 05dee1d3d857 -r f4db9b0bb5e2 main.cpp --- a/main.cpp Thu Apr 04 03:44:59 2013 +0000 +++ b/main.cpp Fri Apr 05 18:46:50 2013 +0000 @@ -6,6 +6,7 @@ char path[1000] = ""; unsigned char path_length = 0; // the length of the path so far int sensors[5]; +DigitalIn pb(p21); // Minimum and maximum motor speeds #define MAX 0.25 @@ -188,6 +189,44 @@ // The path is now two steps shorter. path_length -= 2; } +/*============================================================================================================== + PRESSED +================================================================================================================*/ +void pressed() +{ + + // wait 15s to give time to turn off, or put the robot back to the start + wait(2); + // ideally we would use a button press here + // but I don't think it can easily be read + + // Re-run the maze. It's not necessary to identify the + // intersections, so this loop is really simple. + int i; + for(i=0;i<path_length;i++) + { + follow_line(); + + // Drive straight while slowing down + //m3pi.forward(0.5); + //wait(0.05); + m3pi.forward(0.2); + wait(0.2); + + // Make a turn according to the instruction stored in + // path[i]. + doturn(path[i]); + } + + // Follow the last segment up to the finish. + follow_line(); + m3pi.forward(0.2); + wait(0.6); + return; + + // Now we should be at the finish! Restart the loop. + +} /*======================================================================================================== MAZESOLVE @@ -195,6 +234,7 @@ // This function is called once, from main.c. void mazesolve() { + // These variables record whether the robot has seen a line to the // left, straight ahead, and right, while examining the current // intersection. @@ -239,6 +279,7 @@ //move upon the home pad to show off m3pi.forward(0.2); wait(0.4); + m3pi.printf("Finished"); break; } else found_left = 1; @@ -259,6 +300,7 @@ { m3pi.forward(0.2); wait(0.4); + m3pi.printf("Finished"); break; } //can we go forward @@ -307,41 +349,22 @@ // times as we want to. while(1) { - - m3pi.forward(0.0); - m3pi.printf("Finished"); - - // wait 15s to give time to turn off, or put the robot back to the start - wait(15); - // ideally we would use a button press here - // but I don't think it can easily be read - - // Re-run the maze. It's not necessary to identify the - // intersections, so this loop is really simple. - int i; - for(i=0;i<path_length;i++) + m3pi.forward(0.0); + pb.mode(PullUp); + + if(pb) { - follow_line(); - - // Drive straight while slowing down - //m3pi.forward(0.5); - //wait(0.05); - m3pi.forward(0.2); - wait(0.2); - - // Make a turn according to the instruction stored in - // path[i]. - doturn(path[i]); - } + do + { + + } + while(pb); + pressed(); + } - // Follow the last segment up to the finish. - follow_line(); - m3pi.forward(0.2); - wait(0.6); + } - // Now we should be at the finish! Restart the loop. - } } /*======================================================================================================== @@ -358,5 +381,4 @@ mazesolve(); m3pi.forward(0.0); - }