receiver code which helps the vehicle to move forward, backward, left and right
Dependencies: mbed Servo mbed-rtos XBeeTest Motor emic2 X_NUCLEO_53L0A1
Diff: main.cpp
- Revision:
- 3:5d43739ec09f
- Parent:
- 2:112ca6a4fc73
- Child:
- 4:c15361d55018
diff -r 112ca6a4fc73 -r 5d43739ec09f main.cpp --- a/main.cpp Wed Dec 05 23:08:58 2018 +0000 +++ b/main.cpp Wed Dec 12 21:59:14 2018 +0000 @@ -6,13 +6,17 @@ #include "emic2.h" #include "XNucleo53L0A1.h" #include <stdio.h> +#include "rtos.h" + + Serial pc(USBTX, USBRX); DigitalOut shdn(p26); - +AnalogOut led(p18); //I2C sensor pins #define VL53L0_I2C_SDA p28 #define VL53L0_I2C_SCL p27 + static XNucleo53L0A1 *board=NULL; emic2 myTTS(p13, p14); Serial xbee1(p9, p10); @@ -23,7 +27,7 @@ char input; int counter; - +int direction; int main() { //initialize distance sensor int status; @@ -43,8 +47,7 @@ } - myTTS.volume(2); - myTTS.voice(3); + counter = 0; // reset the xbees (at least 200ns) rst1 = 0; @@ -52,37 +55,64 @@ rst1 = 1; wait_ms(1); input = 'I'; + A.speed(0); B.speed(0); + wait(2); + direction = 1; while(1) { if(xbee1.readable()) { input = xbee1.getc(); + wait(0.2); } - A.speed(0); - B.speed(0); + //A.speed(0); + //B.speed(0); status = board->sensor_centre->get_distance(&distance); if (status == VL53L0X_ERROR_NONE) { pc.printf("D=%ld mm\r\n", distance); + + } + + while (distance < 200) { + direction = rand()*100; + if (direction > 50) + { + A.speed(-0.5); + B.speed(-0.5); + led = 0; + wait(0.1); + } else + { + + A.speed(0.5); + B.speed(0.5); + led = 1; + wait(0.1); + } + status = board->sensor_centre->get_distance(&distance); + led = 0; + A.speed(0); + B.speed(0); } if (input == 'A') { - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("forward"); - myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); + //myTTS.speakf("S");//Speak command starts with "S" + //myTTS.speakf("forward"); + //myTTS.speakf("\r"); //marks end of speak command + //myTTS.ready(); + A.speed(-0.5); + B.speed(0.5); + wait(0.2); + } else if (input == 'B') + { + //myTTS.speakf("S");//Speak command starts with "S" + //myTTS.speakf("back"); + //myTTS.speakf("\r"); //marks end of speak command + //myTTS.ready(); A.speed(0.5); B.speed(-0.5); - wait(0.5); - } else if (input == 'B') - { - myTTS.speakf("S");//Speak command starts with "S" - myTTS.speakf("back"); - myTTS.speakf("\r"); //marks end of speak command - myTTS.ready(); - A.speed(-0.5); - B.speed(0.5); - wait(0.5); + wait(0.2); } else if (input == 'C') { myTTS.speakf("S");//Speak command starts with "S" @@ -91,7 +121,7 @@ myTTS.ready(); A.speed(0.5); B.speed(0.5); - wait(0.5); + wait(0.2); } else if (input == 'D') { myTTS.speakf("S");//Speak command starts with "S" @@ -100,7 +130,7 @@ myTTS.ready(); A.speed(-0.5); B.speed(-0.5); - wait(0.5); + wait(0.2); } else if (input == 'E') { myTTS.speakf("S");//Speak command starts with "S" @@ -109,8 +139,7 @@ myTTS.ready(); A.speed(0); B.speed(0); - wait(0.5); - + wait(0.2); } } } \ No newline at end of file