Zachary Sunberg / Mbed 2 deprecated SAILORSbot

Dependencies:   mbed

Revision:
23:55f8b1abbf99
Parent:
22:dae192ffca90
Child:
24:62cad0ea47da
diff -r dae192ffca90 -r 55f8b1abbf99 main.cpp
--- a/main.cpp	Sun Aug 02 22:22:29 2015 +0000
+++ b/main.cpp	Wed Aug 05 05:21:41 2015 +0000
@@ -1,10 +1,9 @@
 #include "robot.h"
+#include "my_functions.h"
 
 /*
- * This function will be called at approximately <SPEED> when the control mode is LINE_FOLLOW_MODE
+ * This function will be called at approximately 50 hz when the control mode is LINE_FOLLOW_MODE
  */
- 
- ///////////////////////////////////////////add line following code
 void line_follow_loop(){
     led4 = 1;
     
@@ -86,14 +85,19 @@
 // s:<int>,<int>,<int>,<int>,<int>
 //              light sensor values
 // m:<int>      mode
+// a:<message>  acknowledge
 void communicate()
 {
     led1 = 1;
     pi.sensor_reading(sensors);
     int* s = sensors; // just to make the next line more compact
+    __disable_irq();
     xbee.printf("s:%i,%i,%i,%i,%i\n", s[0], s[1], s[2], s[3], s[4]);
+    __enable_irq();
+    __disable_irq();
     xbee.printf("p:%f\n", pi.line_position());
     xbee.printf("m:%d\n", mode);
+    __enable_irq();
     led1 = 0;
 }
 
@@ -113,7 +117,9 @@
         // mode
         }else if(cmd[0]=='c'){
             mode = atoi(&cmd[2]);
-            communicate(); // make sure we get a confirmation of the mode
+            __disable_irq();
+            xbee.printf("a:c:%d\n", mode);// acknowledge the mode change
+            __enable_irq();
             // xbee.printf("mode set to %d\n", mode);
         // gains
         }else if(cmd[0]=='g'){
@@ -124,15 +130,24 @@
             }else if(cmd[2]=='d'){
                 k_d = atof(&cmd[4]);
             }
+            __disable_irq();
             xbee.printf("gains p:%f, i:%f, d:%f\n", k_p, k_i, k_d);
+            __enable_irq();
+  
         // battery
         }else if(cmd[0]=='b'){
+            __disable_irq();
             xbee.printf("battery voltage: %f\n", pi.battery());
+            __enable_irq();
         }else{
-            xbee.printf("%s\n",cmd); 
+            __disable_irq();
+            xbee.printf("%s\n",cmd);
+            __enable_irq();
         }
     }else{
+        __disable_irq();
         xbee.printf("%s\n",cmd);
+        __enable_irq();
     }
     return 0;
 }