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:39:06 2016 +0000
Parent:
1:5235d57bb8d3
Commit message:
Xbee robot with telemetry, robot code

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 5235d57bb8d3 -r c7c1c5e42767 main.cpp
--- a/main.cpp	Fri Apr 29 19:09:58 2016 +0000
+++ b/main.cpp	Fri Apr 29 19:39:06 2016 +0000
@@ -6,100 +6,29 @@
 #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);
 
-//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);
 
-DigitalOut led4(LED4);
 AnalogIn battery(p20);
 AnalogIn sensor(p18);
 
-
-
-/*int a;
-void forward_pushed (void)
-{
-    a = 11;
-    xbee1.putc(a);
-    pc.putc(a);
-}
-void left_pushed (void)
-{
-    a = 12;
-    xbee1.putc(a);
-    pc.putc(a);
-}
-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);
-}
+float s=0.8 ;//speed of forward and backward, set to 0.8 for a medium speed
 
-/* 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;
+    rst2 = 0; //reset Xbee to initialize
     wait_ms(100);
     rst2 = 1;
-    while (1) {
-        float xx= (battery);
-        float sense=sensor;
-
+    while (1) 
+    {
         int b;
         b = xbee2.getc();
         if (b==11) {   //move forward
@@ -120,24 +49,18 @@
             B.speed(s+0.2);
         } else if (b==15) {
 
-            pc.printf("%i\n",int(float(232)*xx));
-            xbee2.putc(int(float(232)*xx));
+            xbee2.putc(int(float(232)*battery));
         } else if (b==16) {
-            pc.printf("%i\n",int(float(232)*sense));
-            xbee2.putc(int(float(232)*sense));
+            xbee2.putc(int(float(232)*sensor));
 
         } else if (b==0){
-            
+            // stops the motor if no command
             A.speed(0);
             B.speed(0);
-            
         }
 
         wait(0.01);
-        led1=led2=led3=led4=0;
-        
+        led1=led2=led3=led4=0; //reset leds    
     }
-    
 
-    //}
 }
\ No newline at end of file