receiver code which helps the vehicle to move forward, backward, left and right
Dependencies: mbed Servo mbed-rtos XBeeTest Motor emic2 X_NUCLEO_53L0A1
Revision 1:95f5ac2f045d, committed 2018-12-05
- Comitter:
- CharlesXu
- Date:
- Wed Dec 05 22:46:10 2018 +0000
- Parent:
- 0:25aca1983704
- Child:
- 2:112ca6a4fc73
- Commit message:
- receiver end of the device
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Motor.lib Wed Dec 05 22:46:10 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/simon/code/Motor/#f265e441bcd9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Receiver.lib Wed Dec 05 22:46:10 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/vcazan/code/XBeeTest/#25aca1983704
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/X_NUCLEO_53L0A1.lib Wed Dec 05 22:46:10 2018 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/X_NUCLEO_53L0A1/#27d3d95c8593
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emic2.lib Wed Dec 05 22:46:10 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/4180_1/code/emic2/#b95ede38e19d
--- a/main.cpp Tue Sep 29 21:31:14 2009 +0000
+++ b/main.cpp Wed Dec 05 22:46:10 2018 +0000
@@ -1,36 +1,121 @@
-/**
- * XBee Example Test
- * A test application that demonstrates the ability
- * of transmitting serial data via an XBee module with
- * an mbed microprocesor.
- * By: Vlad Cazan
- * Date: Tuesday, September 29th 2009
- */
-
+// basic xbee example
+// - take chars from the terminal, push them out xbee1
+// - listen on xbee2, and print value + 1 to terminal
+#include "Motor.h"
#include "mbed.h"
+#include "emic2.h"
+#include "XNucleo53L0A1.h"
+#include <stdio.h>
+Serial pc(USBTX, USBRX);
+DigitalOut shdn(p26);
-Serial xbee1(p9, p10); //Creates a variable for serial comunication through pin 9 and 10
-
-DigitalOut rst1(p11); //Digital reset for the XBee, 200ns for reset
+//I2C sensor pins
+#define VL53L0_I2C_SDA p28
+#define VL53L0_I2C_SCL p27
-DigitalOut myled(LED3);//Create variable for Led 3 on the mbed
-DigitalOut myled2(LED4);//Create variable for Led 4 on the mbed
+static XNucleo53L0A1 *board=NULL;
+DigitalOut shdn(p26);
+emic2 myTTS(p13, p14);
+Serial xbee1(p9, p10);
+DigitalOut rst1(p11);
-Serial pc(USBTX, USBRX);//Opens up serial communication through the USB port via the computer
+Motor B(p23, p6, p5); // pwm, fwd, rev, can brake, right
+Motor A(p24, p7, p8); // left motor
+
+char input;
+int counter;
int main() {
- rst1 = 0; //Set reset pin to 0
- myled = 0;//Set LED3 to 0
- myled2= 0;//Set LED4 to 0
- wait_ms(1);//Wait at least one millisecond
- rst1 = 1;//Set reset pin to 1
- wait_ms(1);//Wait another millisecond
-
- while (1) {//Neverending Loop
- if (pc.readable()) {//Checking for serial comminication
- myled = 0; //Turn Led 3 Off
- xbee1.putc(pc.getc()); //XBee write whatever the PC is sending
- myled = 1; //Turn Led 3 on for succcessfull communication
+ //initialize distance sensor
+ int status;
+ uint32_t distance;
+ DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
+ /* creates the 53L0A1 expansion board singleton obj */
+ board = XNucleo53L0A1::instance(device_i2c, A2, D8, D2);
+ shdn = 0; //must reset sensor for an mbed reset to work
+ wait(0.1);
+ shdn = 1;
+ wait(0.1);
+ /* init the 53L0A1 board with default values */
+ status = board->init_board();
+ while (status) {
+ pc.printf("Failed to init board! \r\n");
+ status = board->init_board();
+ }
+ //loop taking and printing distance
+ while (1) {
+ status = board->sensor_centre->get_distance(&distance);
+ if (status == VL53L0X_ERROR_NONE) {
+ pc.printf("D=%ld mm\r\n", distance);
+ }
+ }
+
+
+
+ myTTS.volume(2);
+ myTTS.voice(3);
+ counter = 0;
+ // reset the xbees (at least 200ns)
+ rst1 = 0;
+ wait_ms(1);
+ rst1 = 1;
+ wait_ms(1);
+ input = 'I';
+ A.speed(0);
+ B.speed(0);
+ while(1) {
+ if(xbee1.readable()) {
+ input = xbee1.getc();
+ }
+ 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();
+ 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);
+ } else if (input == 'C')
+ {
+ myTTS.speakf("S");//Speak command starts with "S"
+ myTTS.speakf("left");
+ myTTS.speakf("\r"); //marks end of speak command
+ myTTS.ready();
+ A.speed(0.5);
+ B.speed(0.5);
+ wait(0.5);
+ } else if (input == 'D')
+ {
+ myTTS.speakf("S");//Speak command starts with "S"
+ myTTS.speakf("right");
+ myTTS.speakf("\r"); //marks end of speak command
+ myTTS.ready();
+ A.speed(-0.5);
+ B.speed(-0.5);
+ wait(0.5);
+ } else if (input == 'E')
+ {
+ myTTS.speakf("S");//Speak command starts with "S"
+ myTTS.speakf("stop, open vicinity warning system");
+ myTTS.speakf("\r"); //marks end of speak command
+ myTTS.ready();
+ A.speed(0);
+ B.speed(0);
+ wait(0.5);
+
}
}
}
\ No newline at end of file
--- a/mbed.bld Tue Sep 29 21:31:14 2009 +0000 +++ b/mbed.bld Wed Dec 05 22:46:10 2018 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/a0336ede94ce +https://mbed.org/users/mbed_official/code/mbed/builds/e2bfab296f20 \ No newline at end of file