Algorithmus

Dependencies:   mbed

Revision:
21:41997651337a
Parent:
20:20573f55a5fd
Child:
23:accd07ca2da7
--- a/main.cpp	Fri May 11 13:12:28 2018 +0000
+++ b/main.cpp	Sat May 12 16:30:18 2018 +0000
@@ -1,15 +1,10 @@
  /** 
  *      Micromouse PES2
  *
- *      Suchfahrtalg. + Schnellfahrtalg.  
+ *      Suchfahrt + Speicherfahrtalg.  
  *
  */
  
- /* todo:
- 
-    - Abbiegen
-    
-*/
 #include <mbed.h>
 #include "EncoderCounter.h"
 #include "Controller.h"
@@ -94,18 +89,14 @@
     while(1) {
     
         button.fall(&press); //User button einlesen
-    
-        /** 
-         *    
-         *  Search run
-         *
-         */
+
+/*-----------------------------------------------------------------------------* 
+ *    
+ *                          Search run
+ *
+ *-----------------------------------------------------------------------------*/
    
         while(start == 1 && Ziel == 0) { 
-    
-            /**
-            *  Entscheidung und Bewegung
-            */
          
          
             float distanceL = irSensorL.readL();
@@ -165,7 +156,7 @@
 //                    printf("Kreuzung %d Schritt %d geloscht\n", j, r);
                     j -= 1;
                 
-                    do {
+                     while (junction[j] < r )  {
                     
                         //invert rotation
                         if (route[r] == LEFT) {
@@ -177,12 +168,12 @@
                             route[r] = LEFT;
                         }
                     
-                        motion.runTask(route,r,true,junction[j]);
+                        motion.runTask(route, r, true, junction[j]);
 //                        printf("Schritt: %d, Befehl: %d\n", r, route[r]);
                         route[r] = 0;
                         r--;
                         
-                    } while (junction[j] < r ) ;
+                    }
                     motion.stop();
 //                    printf("Loop stop\n");
 
@@ -220,7 +211,7 @@
 //                    printf("Kreuzung %d Schritt %d geloscht\n", j, r);
                     j -= 1;
                 
-                    do {
+                    while (junction[j] < r ) {
                     
                         //invert rotation
                         if (route[r] == LEFT) {
@@ -232,12 +223,12 @@
                             route[r] = LEFT;
                         }
                     
-                        motion.runTask(route,r,true,junction[j]);
+                        motion.runTask(route, r, true, junction[j]);
 //                        printf("Schritt: %d, Befehl: %d\n", r, route[r]);
                         route[r] = 0;
                         r--;
                         
-                    } while (junction[j] < r );
+                    }
                     motion.stop();
 //                    printf("Loop stop\n");
                 
@@ -280,7 +271,7 @@
                     
                         switch (route[r]) {
                             case MOVE: 
-                                motion.runTask(route,r,true, junction[j]);
+                                motion.runTask(route, r, true, junction[j]);
 //                                printf("Schritt: %d, Befehl: %d\n", r, route[r]);
                                 r--;
                                 break;
@@ -308,7 +299,7 @@
                             route[r] = LEFT;
                         }
                         //Run tasks in declining order
-                        motion.runTask(route,r,true, junction[j]);
+                        motion.runTask(route, r, true, junction[j]);
 //                        printf("Schritt: %d, Befehl: %d\n", r, route[r]);
                         route[r] = 0;
                         r--;
@@ -324,6 +315,7 @@
                 r = 0;  
                 start = 0;
                 controller.counterReset();
+                myled = 1;
             }else{
                 Ziel = 0;
             }
@@ -331,9 +323,11 @@
 
         }
     
-    /*
-     *  Speed run
-     */
+    /*-------------------------------------------------------------------------*
+     *
+     *                                Speed run
+     *
+     *-------------------------------------------------------------------------*/
      
         while ( start == 1 && Ziel == 1 ) {
         
@@ -343,7 +337,8 @@
             if (route[r] == 0) {
                 //Weg fertig
                 motion.stop();
-                start = 0;    
+                start = 0;  
+                myled = 0;  
             }    
         }