Racing Robots Session

Dependencies:   MbedJSONValue m3pi

This is the library for the Racing Robots session. It supports the M3PI robot of Polulu.

It is based on the "Arduino" principle of the init and loop function.

Just add a main.cpp file which contains:

Racing Robots main file

#include "robot_logic.h"

void init()
{
   //put your initialization logic here
}

void loop()
{
    //put your robot control logic here    
}

Features include:

  1. Controlling the LEDS
  2. Move forward and backward
  3. Turn
  4. Read the sensor values
  5. Use a PID controller
Revision:
8:597ce8a7d34b
Parent:
7:a72215b1910b
--- a/robot_logic.cpp	Wed Feb 25 15:56:14 2015 +0000
+++ b/robot_logic.cpp	Mon Jun 01 14:47:32 2015 +0000
@@ -1,4 +1,5 @@
 #include "robot_logic.h"
+#include "xbee.h"
 
 // Some defines
 #define MAX_SPEED 100
@@ -10,6 +11,10 @@
 // Static scope variables
 static m3pi m3pi;
 
+#ifdef XBEE
+Xbee xbee(p28, p27);
+#endif
+
 // Static scope variables for keeping internal state
 static int internal_speed = 0;          // [-100, +100]
 static int internal_turnspeed = 0;     // [-100, +100]
@@ -28,7 +33,7 @@
 
     internal_speed = speed;
 
-    if (speed == 0) {
+    if (speed == 0 || !canDrive()) {
         m3pi.stop();
     } else if (speed > 0) {
         m3pi.forward(MAX_REAL_SPEED*speed/MAX_SPEED);
@@ -60,6 +65,11 @@
         left = MIN;
     else if (left > MAX_SPEED)
         left = MAX_SPEED;
+
+    if(!canDrive()){
+        left = right = 0;
+    }
+
     m3pi.left_motor(MAX_REAL_SPEED*left/MAX_SPEED);
     m3pi.right_motor(MAX_REAL_SPEED*right/MAX_SPEED);
 }
@@ -160,4 +170,20 @@
         error("Illegal LED state");
     }
     m3pi.leds(internal_led_state);
+}
+
+int canDrive()
+{
+#ifdef XBEE
+    return !xbee.stopped();
+#endif
+    return true;  
+}
+
+
+void setCode(int code)
+{
+#ifdef XBEE
+    xbee.setCode(code);    
+#endif
 }
\ No newline at end of file