Helvijs Kiselis
/
Micromouse
Algorithmus
Diff: main.cpp
- Revision:
- 32:e984b7959cb0
- Parent:
- 31:2c54f8304ef5
- Child:
- 33:836ab2089565
--- a/main.cpp Tue May 22 23:35:53 2018 +0000 +++ b/main.cpp Wed May 23 01:34:36 2018 +0000 @@ -54,7 +54,7 @@ volatile int start = 0; - const int debuging = 1; + const int debuging = 0; const int MOVE = 1; const int LEFT = 2; @@ -163,6 +163,8 @@ junction[j] = 0; printf("Kreuzung %d Schritt %d geloscht\n", j, r); j -= 1; + + bool looping = false; while (junction[j] <= r ) { @@ -172,8 +174,10 @@ switch (route[r]) { case MOVE: + if (looping == false) { motion.runTask(route, r, true, junction[j]); if (debuging == 1) printf("-Schritt: %d, Befehl: %d\n", r, route[r]); + } r--; break; case LEFT: @@ -197,6 +201,15 @@ }else if (route[r] == RIGHT) { route[r] = LEFT; + + }else if (junction[j] == r-1 && route[r] == MOVE) { + + looping = true; + + }else if (junction[j] == r-2 && route[r] == MOVE && route[junction[j]] != MOVE) { + + route[r] = 0; + r--; } motion.runTask(route, r, true, junction[j]); @@ -247,6 +260,7 @@ junction[j] = 0; if (debuging == 1) printf("Kreuzung %d Schritt %d geloscht\n", j, r); j -= 1; + bool looping = false; while (junction[j] <= r ) { @@ -256,8 +270,10 @@ switch (route[r]) { case MOVE: + if (looping == false) { motion.runTask(route, r, true, junction[j]); if (debuging == 1) printf("-Schritt: %d, Befehl: %d\n", r, route[r]); + } r--; break; case LEFT: @@ -281,6 +297,15 @@ }else if (route[r] == RIGHT) { route[r] = LEFT; + + }else if (junction[j] == r-1 && route[r] == MOVE) { + + looping = true; + + }else if (junction[j] == r-2 && route[r] == MOVE && route[junction[j]] != MOVE) { + + route[r] = 0; + r--; } motion.runTask(route, r, true, junction[j]);