Programming for Shadow Robot control for smart phone mapping application.

Dependencies:   Motor LSM9DS1_Library_cal mbed Servo

Revision:
0:616fbf21a20e
Child:
1:8638bdaf172b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 22 19:46:41 2016 +0000
@@ -0,0 +1,66 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "Motor.h"
+
+Motor rwheel(p26, p25, p24); // pwm, fwd, rev
+Motor lwheel(p21, p22, p23); // pwm, fwd, rev
+Timer timestamp;
+
+DigitalOut myled(LED1);
+
+/*  move(float, int)
+    Usage: Moves the robot forward in a straight line at a constant speed.
+    s is a float from -1 to 1 representing the speed to move. 
+    A negative speed is used for backwards movement.
+    t is the time in milliseconds to move.
+*/
+void move(float s, int t)
+{
+    Timer timer;
+    //Start the timer
+    timer.start();
+    //Set the robot in motion at speed s
+    rwheel.speed(s);
+    lwheel.speed(s);
+    //Give other threads priority until the elapsed time
+    while(timer.read_ms() < t); //Thread::yield();
+    //Stop the robot
+    rwheel.speed(0);
+    lwheel.speed(0);
+}
+
+/*  turn(float,int)
+    Usage: Turns the robot about its center at constant angular speed.
+    s is a float from -1 to 1 representing the speed to turn.
+    A positive s indicates a clockwise rotation.
+    A negative s indicates a counter-clockwise rotation. 
+*/
+void turn(float s, int t)
+{
+    Timer timer;
+    //Start the timer
+    timer.start();
+    //Set the robot in motion turning at speed s
+    rwheel.speed(-1*s);
+    lwheel.speed(s);
+    //Give other threads priority until the elapsed time
+    while(timer.read_ms() < t);// Thread::yield();
+    //Stop the robot
+    rwheel.speed(0);
+    lwheel.speed(0);
+}
+int main() 
+{
+    timestamp.start(); 
+    while(1) 
+    {
+        myled = 0;
+        move(.5,2000);
+        move(-1,2000);
+        move(1,2000);
+        turn(1,2000);
+        turn(-1,2000);
+        myled=1;  
+        wait(5);
+    }
+}