Code with mutex and threads

Dependencies:   C12832 Servo mbed-rtos-edited mbed

Fork of NervousPuppySprintOne by Sprint One

Files at this revision

API Documentation at this revision

Comitter:
SeanDoyle
Date:
Wed Jan 14 16:57:41 2015 +0000
Parent:
2:8415bea33a95
Child:
4:2b47356f4b7d
Commit message:
Tidied code, fixed issue for no optimal angle

Changed in this revision

nervousPuppy.cpp Show annotated file Show diff for this revision Revisions of this file
nervousPuppy.h Show annotated file Show diff for this revision Revisions of this file
--- a/nervousPuppy.cpp	Tue Jan 13 16:08:22 2015 +0000
+++ b/nervousPuppy.cpp	Wed Jan 14 16:57:41 2015 +0000
@@ -12,35 +12,25 @@
             scared = true;
             playerError = playerDistance - SCARED;
             
-            if(calculateVerticalAdjustment() != 0)changePosition("tilt",calculateVerticalAdjustment());
-            else changePosition("rotate",calculateHorizontalAdjustment());
+            if(calculateAngle("Vertical") != 0)changePosition("tilt",calculateAngle("Vertical"));
+            else if(calculateAngle("Horizontal") != 0)changePosition("rotate",calculateAngle("Horizontal"));
+            else isRunning = false;
+            
             scared = false;
         } else if(isLonely()){// MoveForward
             lonely = true;
             playerError = playerDistance - LONELY;
             
-            if(calculateVerticalAdjustment() !=0)changePosition("tilt",calculateVerticalAdjustment());
-            else changePosition("rotate",calculateHorizontalAdjustment());
+            if(calculateAngle("Vertical") !=0)changePosition("tilt",calculateAngle("Vertical"));
+            else if(calculateAngle("Horizontal") != 0)changePosition("rotate",calculateAngle("Horizontal"));
+            else isRunning = false;
+            
             lonely = false;
         }
     }
 }
 
 /**
- * Returns the vertical adjustment
- */
-float nervousPuppy::calculateVerticalAdjustment(){
-    return calculateAngle("Vertical");
-}
-
-/**
- * Returns the horizontal adjustment
- */
-float nervousPuppy::calculateHorizontalAdjustment(){
-    return calculateAngle("Horizontal");
-}
-
-/**
  * Calculates the angle required to bring the 'puppy' to a 'safe distance'
  * Returns 0 if it cannot find a 'safe distance'
  */
--- a/nervousPuppy.h	Tue Jan 13 16:08:22 2015 +0000
+++ b/nervousPuppy.h	Wed Jan 14 16:57:41 2015 +0000
@@ -20,8 +20,6 @@
         float getPlayerDistance();
         void setPlayerDistance(float dist);
         
-        float calculateVerticalAdjustment();
-        float calculateHorizontalAdjustment();
         float calculateAngle(string axis);
         void changePosition(string servo,float angle);