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

Files at this revision

API Documentation at this revision

Comitter:
pcordemans
Date:
Tue Feb 24 09:38:40 2015 +0000
Parent:
4:3743cbfe031b
Child:
6:0dc4e4225881
Commit message:
added led implementation; cleaned up error messages

Changed in this revision

robot_logic.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/robot_logic.cpp	Tue Feb 24 09:06:29 2015 +0000
+++ b/robot_logic.cpp	Tue Feb 24 09:38:40 2015 +0000
@@ -17,6 +17,7 @@
 static int internal_i = 0;
 static int internal_d = 0;
 static int internal_previous_pos_of_line = 0;
+static int internal_led_state = 0;
 
 /*
  * Drive the robot forward or backward.
@@ -50,7 +51,7 @@
  */
 void turn(int turnspeed) {
     if (turnspeed > MAX_SPEED || turnspeed < -MAX_SPEED) {
-        printf("[ERROR] Turn speed out of range");
+        error("Speed out of range");
         return;
     }
 
@@ -222,4 +223,21 @@
  */
 void await(int milliseconds) {
     wait_ms(milliseconds);
+}
+
+
+void led(LedIndex i, LedState state) {
+    if(state == LED_ON){
+        internal_led_state |= (1 << i);
+    }
+    else if(state == LED_OFF) {
+        internal_led_state &= ~(1 << i);
+    }
+    else if(state == LED_TOGGLE){
+        internal_led_state ^= (1 << i);
+    }
+    else{
+        error("Illegal LED state");
+    }
+    m3pi.leds(internal_led_state);
 }
\ No newline at end of file