P2

Dependencies:   Library mbed

Files at this revision

API Documentation at this revision

Comitter:
kueenste
Date:
Fri Mar 23 12:57:27 2018 +0000
Parent:
0:b15fac82ee4e
Commit message:
P2;

Changed in this revision

Library.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r b15fac82ee4e -r ca37d1831bd1 Library.lib
--- a/Library.lib	Fri Mar 09 15:30:02 2018 +0000
+++ b/Library.lib	Fri Mar 23 12:57:27 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/kueenste/code/Library/#bb408887ab78
+https://os.mbed.com/teams/TeamSurface/code/Library/#6dd39662e6e5
diff -r b15fac82ee4e -r ca37d1831bd1 main.cpp
--- a/main.cpp	Fri Mar 09 15:30:02 2018 +0000
+++ b/main.cpp	Fri Mar 23 12:57:27 2018 +0000
@@ -66,9 +66,9 @@
     wait(5);
     controller.setTranslationalVelocity(10); 
     */
-    
+    short lb = button.read();
     while(1) {
-        
+        short b = button.read();
         // Initial reads
         
         float distanceStraight = irSensor0.read(); // gibt die Distanz in [m] zurueck
@@ -80,8 +80,15 @@
         
         // FSM
         
+        if (distanceStraight < 0.2f) {
+            led3.write(true);
+        } else {
+            led3.write(false);
+        }
+        
+        
         switch(state) {
-        
+
         // Robot off
         case(robOff):
         
@@ -91,7 +98,7 @@
             enableMotorDriver = 0; // Schaltet den Leistungstreiber
         
             // button pressed
-            if (button.read()){
+            if (b && b != lb){
                 enableMotorDriver = 1; // Schaltet den Leistungstreiber ein
                 
                 state = robMove;
@@ -101,17 +108,18 @@
         // Move Forward
         case(robMove):
             
-            controller.setTranslationalVelocity(20.0f);
+            controller.setTranslationalVelocity(0.7f);
             controller.setRotationalVelocity(0.0f);
         
         
             // button pressed
-            if (button.read()){
+            if (b && b != lb){
                 state = robOff;
-            } else if(distanceStraight <= 0.4f) {
-                if(distanceLeft > 0.3f) {
+            } else if(distanceStraight <= 0.2f) {
+                
+                if(distanceLeft > 0.2f) {
                     state = robLeft;    
-                } else if(distanceRight > 0.3f) {
+                } else if(distanceRight > 0.2f) {
                     state = robRight;    
                 } else {
                     state = robSlowDown;    
@@ -134,13 +142,13 @@
         case(robLeft):
             
             controller.setTranslationalVelocity(0.0f);
-            controller.setRotationalVelocity(10.0f);
+            controller.setRotationalVelocity(5.0f);
         
         
             // button pressed
-            if (button.read()){
+            if (b && b != lb){
                 state = robSlowDown;
-            } else if(distanceStraight > 0.6f) {
+            } else if(distanceStraight > 0.2f) {
                 state = robMove;    
             }
         break;
@@ -148,22 +156,23 @@
         case(robRight):
         
             controller.setTranslationalVelocity(0.0f);
-            controller.setRotationalVelocity(-10.0f);
+            controller.setRotationalVelocity(-5.0f);
         
             // button pressed
-            if (button.read()){
+            if (b && b != lb){
                 state = robSlowDown;
-            } else if(distanceStraight > 0.6f) {
+            } else if(distanceStraight > 0.2f) {
                 state = robMove;    
             }
         break;
         default:
         // fuck off
-        
+                
+
         break;
-
         }    
 
-
+        lb = b;
+        
     }
 }