Xbee robot with telemetry, robot code

Dependencies:   4DGL-uLCD-SE DebounceIn Motor mbed

Fork of LED_RTOS by jim hamblen

Files at this revision

API Documentation at this revision

Comitter:
yhbyhb4433
Date:
Fri Apr 29 19:09:58 2016 +0000
Parent:
0:9439ccb44422
Child:
2:c7c1c5e42767
Commit message:
Xbee robot with telemetry, robot code

Changed in this revision

4DGL-uLCD-SE.lib Show annotated file Show diff for this revision Revisions of this file
DebounceIn.lib Show annotated file Show diff for this revision Revisions of this file
Motor.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
mbed-rtos.lib Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/4DGL-uLCD-SE.lib	Fri Apr 29 19:09:58 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DebounceIn.lib	Fri Apr 29 19:09:58 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/DebounceIn/#31ae5cfb44a4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.lib	Fri Apr 29 19:09:58 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/Motor/#f265e441bcd9
--- a/main.cpp	Fri Nov 28 18:00:06 2014 +0000
+++ b/main.cpp	Fri Apr 29 19:09:58 2016 +0000
@@ -1,75 +1,143 @@
+// basic xbee example
+// - take chars from the terminal, push them out xbee1
+// - listen on xbee2, and print value + 1 to terminal
+
 #include "mbed.h"
-#include "rtos.h"
-DigitalOut myled(LED1);
-PwmOut myled2(LED2);
-PwmOut myled3(LED3);
-PwmOut myled4(LED4);
+#include "Motor.h"
+Motor B(p21,p22,p23);//wd, rev, can brake right motor
+Motor A(p26,p24,p25);//wm, fwd, rev, can brake  left motir
+//#include "DebounceIn.h"
+
+Serial xbee1(p9, p10);
+
+//DigitalOut rst1(p11);
+//InterruptIn forward(p16);
+//InterruptIn left(p17);
+//InterruptIn reverse(p18);
+//InterruptIn right(p24);
+//forward   16
+//left      17
+//reverse   18
+//right     19
+Serial xbee2(p9, p10);
+DigitalOut rst2(p11);
 
-inline float random_number(){
-    return (rand()/(float(RAND_MAX)));
+//AnalogOut battery(p18);
+//battery=2;
+
+
+Serial pc(USBTX, USBRX);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+float s=0.8 ;//speed of forward and backward
+
+DigitalOut led4(LED4);
+AnalogIn battery(p20);
+AnalogIn sensor(p18);
+
+
+
+/*int a;
+void forward_pushed (void)
+{
+    a = 11;
+    xbee1.putc(a);
+    pc.putc(a);
 }
- 
-void beacon(void const *args){
-    while(1) {
-        //LED warm up effect using PWM
-        for(int i=0; i<50; i++) {
-            myled2 = i/50.0;
-            Thread::wait(1000.0*0.02);
-        }
-        //LED at full brightness level
-        myled2 = 1.0;
-        Thread::wait(1000.0*0.25);
-        //LED cool down effect using PWM
-        for(int i=49; i>0; i--) {
-            myled2 = i/50.0;
-            Thread::wait(1000.0*0.02);
-        }
-        //LED off
-        myled2 = 0.0;
-        Thread::wait(1000.0*1.5);
-    }
+void left_pushed (void)
+{
+    a = 12;
+    xbee1.putc(a);
+    pc.putc(a);
 }
-void welding(void const *args) {
-    float x = 0.0;
-    while(1) {
-        //get a new random number for PWM
-        x = random_number();
-        //add some exponential brightness scaling
-        //for more of a fast flash effect
-        myled3 = x*x*x;
-        //fast update rate for welding flashes
-        Thread::wait(1000.0*0.02);
-        //add a random pause between welds
-        if (random_number()>0.9925) {
-            myled3 = 0.0;
-            Thread::wait(1000.0*4.0*random_number());
-        }
-    }
+void reverse_pushed (void)
+{
+    a = 13;
+    xbee1.putc(a);
+    pc.putc(a);
+}
+void right_pushed (void)
+{
+    a = 14;
+    xbee1.putc(a);
+    pc.printf("%i\n",a);
 }
 
-void lighthouse(void const *args){
-    float y=0.0;
-    while(1) {
-        for(double x=0.0; x <= 3.14159; x = x + 0.0314159) {
-            y = sin(x); //nice periodic function 0..1..0
-            myled4 = y*y*y;//exponential effect - needs a sharp peak
-            Thread::wait(1000.0*.025);
+/* int main()
+{
+    forward.mode(PullUp);
+    reverse.mode(PullUp);
+    left.mode(PullUp);
+    right.mode(PullUp);
+
+    // reset the xbees (at least 200ns)
+//    rst1 = 0;
+    rst2 = 0;
+//    wait_ms(100);
+//    rst1 = 1;
+//    rst2 = 1;
+//    wait_ms(100);
+
+    wait(.01);
+    // Attach the address of the interrupt handler routine for pushbutton
+//    forward.fall(&forward_pushed);
+//    left.fall(&left_pushed);
+//    reverse.fall(&reverse_pushed);
+//    right.fall(&right_pushed);
+//    wait(0.05);
+//    //xbee1.putc(pc.getc());
+*/
+
+//led1=1;
+//}
+int main()
+{
+    rst2 = 0;
+    wait_ms(100);
+    rst2 = 1;
+    while (1) {
+        float xx= (battery);
+        float sense=sensor;
+
+        int b;
+        b = xbee2.getc();
+        if (b==11) {   //move forward
+            led1 = 1;
+            A.speed(s);
+            B.speed(s);
+        } else if (b==12) {   // move backward
+            led2 = 1;
+            A.speed(-s);
+            B.speed(-s);
+        } else if (b==13) {       // move left
+            led3 = 1;
+            A.speed(s+0.2);
+            B.speed(s-0.2);
+        } else if (b==14) {      // move right
+            led4 = 1;
+            A.speed(s-0.2);
+            B.speed(s+0.2);
+        } else if (b==15) {
+
+            pc.printf("%i\n",int(float(232)*xx));
+            xbee2.putc(int(float(232)*xx));
+        } else if (b==16) {
+            pc.printf("%i\n",int(float(232)*sense));
+            xbee2.putc(int(float(232)*sense));
+
+        } else if (b==0){
+            
+            A.speed(0);
+            B.speed(0);
+            
         }
-        myled4 = 0.0;
-        //most lighthouses have a 5 second delay - so add another 2.5
-        Thread::wait(1000.0*2.5);
+
+        wait(0.01);
+        led1=led2=led3=led4=0;
+        
     }
-}
+    
 
-int main() {
-    Thread thread2(beacon);
-    Thread thread3(welding);
-    Thread thread4(lighthouse);
-    //main runs standard LED blink demo
-    while(1) {
-        myled = 1;
-        Thread::wait(1000.0*0.2);
-        myled = 0;
-        Thread::wait(1000.0*0.2);
-    }
-}
+    //}
+}
\ No newline at end of file
--- a/mbed-rtos.lib	Fri Nov 28 18:00:06 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#02f5cf381388