Executes commands received via xbee.

Dependencies:   m3pi mbed

Committer:
bc6599
Date:
Sun Apr 19 16:01:27 2015 +0000
Revision:
0:98be52da5242
Child:
1:8b83b8a03351
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bc6599 0:98be52da5242 1 #include "mbed.h"
bc6599 0:98be52da5242 2 #include "m3pi.h"
bc6599 0:98be52da5242 3
bc6599 0:98be52da5242 4 Serial xbee(p28, p27);
bc6599 0:98be52da5242 5 m3pi m3pi;
bc6599 0:98be52da5242 6
bc6599 0:98be52da5242 7 void execute();
bc6599 0:98be52da5242 8 void set_command();
bc6599 0:98be52da5242 9
bc6599 0:98be52da5242 10 const char LEFT = 'A';
bc6599 0:98be52da5242 11 const char RIGHT = 'B';
bc6599 0:98be52da5242 12 const char STOP = 'D';
bc6599 0:98be52da5242 13 const char FORWARD = 'E';
bc6599 0:98be52da5242 14 const char BACKWARD = 'F';
bc6599 0:98be52da5242 15
bc6599 0:98be52da5242 16 char command;
bc6599 0:98be52da5242 17 float speed;
bc6599 0:98be52da5242 18
bc6599 0:98be52da5242 19 int main() {
bc6599 0:98be52da5242 20
bc6599 0:98be52da5242 21 command = STOP;
bc6599 0:98be52da5242 22 speed = 0.3;
bc6599 0:98be52da5242 23 m3pi.locate(0,1);
bc6599 0:98be52da5242 24 m3pi.printf("Hola");
bc6599 0:98be52da5242 25
bc6599 0:98be52da5242 26 while (1) {
bc6599 0:98be52da5242 27 set_command();
bc6599 0:98be52da5242 28 m3pi.locate(0,1);
bc6599 0:98be52da5242 29 m3pi.printf("%c",command);
bc6599 0:98be52da5242 30 execute();
bc6599 0:98be52da5242 31 //wait(1);
bc6599 0:98be52da5242 32 }
bc6599 0:98be52da5242 33 }
bc6599 0:98be52da5242 34
bc6599 0:98be52da5242 35 void execute() {
bc6599 0:98be52da5242 36 switch (command) {
bc6599 0:98be52da5242 37 case LEFT:
bc6599 0:98be52da5242 38 m3pi.left(speed); break;
bc6599 0:98be52da5242 39 case RIGHT:
bc6599 0:98be52da5242 40 m3pi.right(speed); break;
bc6599 0:98be52da5242 41 case STOP:
bc6599 0:98be52da5242 42 m3pi.stop(); break;
bc6599 0:98be52da5242 43 case FORWARD:
bc6599 0:98be52da5242 44 m3pi.forward(speed); break;
bc6599 0:98be52da5242 45 case BACKWARD:
bc6599 0:98be52da5242 46 m3pi.backward(speed); break;
bc6599 0:98be52da5242 47 }
bc6599 0:98be52da5242 48 }
bc6599 0:98be52da5242 49
bc6599 0:98be52da5242 50 void set_command() {
bc6599 0:98be52da5242 51 if (xbee.readable()) {
bc6599 0:98be52da5242 52 command = xbee.getc();
bc6599 0:98be52da5242 53 wait(1);
bc6599 0:98be52da5242 54 }
bc6599 0:98be52da5242 55 }