Do NOT modify!

Dependencies:   mbed Servo ServoArm

Fork of PES_Yanick by zhaw_st16b_pes2_10

Revision:
5:1aaf5de776ff
Parent:
4:67d7177c213f
Child:
6:ba26dd3251b3
diff -r 67d7177c213f -r 1aaf5de776ff Sources/Robot.cpp
--- a/Sources/Robot.cpp	Wed Apr 19 12:23:52 2017 +0000
+++ b/Sources/Robot.cpp	Wed Apr 26 08:05:25 2017 +0000
@@ -148,25 +148,25 @@
 }
 
 
-void Robot::legoFront(int* counter, int* timer, int* lastAct, int* legoFound){
+void Robot::legoFront(int* counter, int* timer, int* lastAct, int* legoFound, int* found){
     //*counter += 1;
     *legoFound = 0;
     
-    if (*lastAct != 4){               //If this wasn't the last called action, reset the timer.
+    if (*lastAct != 4){                 //If this wasn't the last called action, reset the timer.
         *timer = 0;
         *lastAct = 4;
     }
     
-    if (this->sensors[FWD] < NEAR){
+    if (this->sensors[FWD] < NEAR){     //If Sam sees a wall turn around
         *legoFound = -1;
+        *counter = MAX;                 //setting counter to MAX will couse sam to turnAround
     }
     
-    else if (this->sensors[FWD_L] > 0.15f){
+    if (this->sensors[FWD_L] > 0.16f){
         this->drive();
     }
     else{
-        this->stop();
-        *legoFound = 3;
+        *found = 1;
     }
 }
 
@@ -179,12 +179,12 @@
         *lastAct = 5;
     }
     
-    if (this->sensors[FWD_L] > NEAR){
+    if (this->sensors[FWD_L] > 0.22f){
         this->turnRight();
     }
     else{
         this->stop();
-        *legoFound = 3;
+        *legoFound = -1;
     }
 }
 
@@ -197,12 +197,12 @@
         *lastAct = 6;
     }
     
-    if (this->sensors[FWD_L] > NEAR){
+    if (this->sensors[FWD_L] > 0.22f){
         this->turnLeft();
     }
     else{
         this->stop();
-        *legoFound = 3;
+        *legoFound = -1;
     }
 }
 
@@ -232,15 +232,15 @@
     *timer += 1;                    //timer holds the time in 0.1s
     
     
-    if (*counter >= MAX/* && legoFound == -1*/) {                   //Robot is stuck turning left & right
+    if (*counter >= MAX) {          //Robot is stuck turning left & right
         counterMax(counter, timer, &lastAct, &rando);
     }
     
-    //Wall actions:
+    /*//Wall actions:
     else if (this->sensors[RIGHT] < NEAR && legoFound == -1){   //Robot has spotted an obstacle on the right.
         wallRight(counter, timer, &lastAct);
     }
-    
+    */
     else if (this->sensors[LEFT] < NEAR && legoFound == -1) {   //Robot has spotted an obstacle on the left.
         wallLeft(counter, timer, &lastAct);
     }
@@ -251,7 +251,7 @@
     
     //Lego actions:
     else if (this->sensors[FWD_L] < NEAR_LEGO && legoFound == -1 || legoFound == 0){    //There's a Lego in front.
-        legoFront(counter, timer, &lastAct, &legoFound);
+        legoFront(counter, timer, &lastAct, &legoFound, found);
     }
 
     else if (this->sensors[RIGHT_L] < NEAR_LEGO && legoFound == -1 || legoFound == 1){  //There's a Lego on the right.