Helvijs Kiselis
/
Micromouse
Algorithmus
Diff: main.cpp
- Revision:
- 12:75d0291a9785
- Parent:
- 11:2960fc540616
- Child:
- 14:2926932e26df
--- a/main.cpp Mon Apr 30 18:27:23 2018 +0000 +++ b/main.cpp Wed May 02 14:58:48 2018 +0000 @@ -7,8 +7,8 @@ /* todo: - - Regler gerade Fahrt - - gespeicherten Weg fahren + - Beschleunigung: Wann & Wo? + - Zentrieren Optimieren: - Beschleunigung @@ -81,9 +81,9 @@ } //Return to last junction -void reverseToJunction(int junc[], int j, int r, int route[]) { +void reverseToJunction(int junc, int &r, int route[]) { - while (junc[j-1] < r ) { + do { //invert rotation if (route[r] == LEFT) { @@ -95,11 +95,11 @@ route[r] = LEFT; } - motion.runTask(route[r]); + motion.runTask(route,r,true); printf("Schritt: %d, Befehl: %d\n", r, route[r]); route[r] = 0; r--; - } + } while (junc < r ); } //------------------------------------------------------------------------------ @@ -107,8 +107,8 @@ int main() { //Init - volatile int route[200] = {0}; - volatile int r = 0; + int route[200] = {0}; + int r = 0; volatile int junction[20] = {0}; volatile int j = 0; @@ -119,16 +119,16 @@ short Ziel = 0; -//loop + //infinite loop while(1) { button.fall(&press); //User button einlesen - /** - * - * Search run - * - */ + /** + * + * Search run + * + */ while(start == 1 && Ziel == 0) { @@ -163,7 +163,7 @@ printf("Kreuzung: %d Schritt: %d\n", j, r); } - //No wall left + //No wall left if (lWall == 0) { if (route[r] == LEFT) { @@ -195,7 +195,7 @@ //if (j > 0) {j--;} printf("Kreuzung %d Schritt %d geloscht\n", j, r); j -= 1; - //reverseToJunction(junction, j, r, route); + //reverseToJunction(junction[j], r, route); /*for (int i = r; i > junction[j]; i--) { r = i; @@ -239,13 +239,14 @@ route[r] = LEFT; } - motion.runTask(route[r]); + motion.runTask(route,r,true); printf("Schritt: %d, Befehl: %d\n", r, route[r]); //At work!!!!! route[r] = 0; r--; } while (junction[j] < r ) ; motion.stop(); + printf("Loop stop\n"); }else{ @@ -325,13 +326,14 @@ route[r] = LEFT; } - motion.runTask(route[r]); + motion.runTask(route,r,true); printf("Schritt: %d, Befehl: %d\n", r, route[r]); route[r] = 0; r--; } while (junction[j] < r ); motion.stop(); + printf("Loop stop\n"); }else{ @@ -369,7 +371,7 @@ switch (route[r]) { case MOVE: - motion.runTask(route[r]); + motion.runTask(route,r,true); printf("Schritt: %d, Befehl: %d\n", r, route[r]); r--; break; @@ -392,7 +394,7 @@ route[r] = LEFT; } //Run tasks in declining order - motion.runTask(route[r]); + motion.runTask(route,r,true); printf("Schritt: %d, Befehl: %d\n", r, route[r]); route[r] = 0; r--; @@ -449,7 +451,7 @@ float distanceC = irSensorC.readC(); float distanceR = irSensorR.readR(); - motion.runTask(route[r]); + motion.runTask(route,r,false); r++; if (route[r] == 0) {