Project ROBot
Dependencies: C12832_lcd HCSR04 TB6612FNG WiflyInterface mbed USBDevice
Welcome to Project ROBot!
ROBot is a robot based on an mbed platform. It is remotely controlled from a PC via a WiFi connection. The vehicle is also equipped with an ultrasonic range finder to detect any obstacles in the direct path of the ROBot and stop any forward motion if a collision is deemed imminent.
Components
The major components of the ROBot are:
- mbed application board
- RN-XV WiFly wireless board (datasheet)
- Toshiba TB6612FNG motor driver (datasheet)
- HC-SR04 ultrasonic range finder (datasheet)
- Redbot kit (just the chassis, motors, and wheels)
- 5V power source
- 6V power source
Schematic
Here is a schematic of the ROBot: schematic
Software Block Diagram
A state machine processes all input and sets the output
Standard Operation
A wireless remote connection from a PC sends commands List of commands:
- 'e' - move forward
- 'c' - move backward
- 'f' - move right
- 's' - move left
- 'd' - stop
commands are case-sensitive
Collision Warning/Avoidance
The range finder ranges every 65 millisecs
When an obstacle is within 50cm, a warning is sent back to the remote host (PC)
When an obstacle is within 30cm, all forward motion ceases. The remote host operator must use other commands to move the ROBot away from the obstacle.
Video
- ROBot and its parts
- Using a terminal emulator (Tera Term) to connect to the ROBot via a USB connection for wireless configuration. Once connected, the ROBot's IP address is shown in the terminal and on the LCD screen.
- Creating a telnet session to remotely control the ROBot. Connect to the IP address given in the previous step.
- Remote host operation of the ROBot
- Collision Warning/Avoidance
Things To Do
I'm not sure when I'll get to these but here are some things I need/would like to do eventually:
- improve the logic for collision
- incorporate the accelerometer on the mbed application board
- develop an Android/iPhone app for remote operation
- add video for true remote operation
Acknowledgements
This project would not have been possible without the following people (in no particular order)... Andrew, Bob, Morgan, Avnish. Thank you for your support! <3
Diff: ROBot.cpp
- Revision:
- 3:6bf3b80a8cd9
- Parent:
- 2:d093f7687c85
- Child:
- 4:228fd78e44fd
--- a/ROBot.cpp Sun Nov 24 23:20:32 2013 +0000 +++ b/ROBot.cpp Fri Dec 06 08:08:32 2013 +0000 @@ -34,9 +34,14 @@ #include "mbed.h" #include "C12832_lcd.h" - +#include "WiflyInterface.h" +#include "HCSR04.h" +#include "TB6612FNG.h" +#include "USBSerial.h" + // uncomment to enable DEBUG // enabling DEBUG does the following: +// - various debug statements // - show status of various state machines //#define DEBUG @@ -45,10 +50,6 @@ #define ENABLE_RANGE_FINDER #define ENABLE_MOTOR_DRIVER -#include "WiflyInterface.h" -#include "HCSR04.h" -#include "TB6612FNG.h" - // WiFi related #define WIFLY_PIN_TX (p9) #define WIFLY_PIN_RX (p10) @@ -56,11 +57,9 @@ #define WIFLY_PIN_RESET (p30) #define WIFI_ECHO_SERVER_PORT (7) #define WIFI_BUFFER_SIZE (64) -//WiflyInterface wifly(WIFLY_PIN_TX, WIFLY_PIN_RX, WIFLY_PIN_RESET, WIFLY_PIN_STATUS, "purpleMonkey", NULL, NONE); -WiflyInterface wifly(WIFLY_PIN_TX, WIFLY_PIN_RX, WIFLY_PIN_RESET, WIFLY_PIN_STATUS, "FishNet", "ffeeddccbbaa99887766554433", WEP_128); -//WiflyInterface wifly(WIFLY_PIN_TX, WIFLY_PIN_RX, WIFLY_PIN_RESET, WIFLY_PIN_STATUS, "Student", NULL, NONE); -TCPSocketServer server; -TCPSocketConnection client; +WiflyInterface *wiFly = NULL; +TCPSocketServer *server = NULL; +TCPSocketConnection *client = NULL; char wiflyBuffer[WIFI_BUFFER_SIZE]; // Range Finder @@ -132,8 +131,12 @@ C12832_LCD lcdScreen; //status display +//Virtual serial port over USB +USBSerial console; +#define STR_BUFFER_SZ (64) + // forward declarations -void init(void); // intializie +void init(void); // intialize void ROBot_sm(void); // ROBot state machine /* Name: main() @@ -143,6 +146,53 @@ */ int main(void) { + char wifi_ssid[STR_BUFFER_SZ]; + char wifi_passwd[STR_BUFFER_SZ]; + Security wifi_security; + +#ifdef DEBUG + printf("starting ROBot\n\r"); +#endif /* DEBUG */ + + // establish console connection to get WiFi parameters + while (1) + { + console.printf("Press <ENTER> to initialize ROBot\n\r"); + wait(1); + if ( console.readable() ) + { + break; + } + } + console.printf("\n\rEnter SSID\n\r"); + console.scanf("%s", wifi_ssid); + console.printf("\n\rEnter password (enter 0 if no password is required)\n\r"); + console.scanf("%s", wifi_passwd); + console.printf("\n\rEnter security type (0=NONE,1=WEP_128,3=WPA)\n\r"); + console.scanf("%d", (Security *)&wifi_security); +#ifdef DEBUG + printf("SSID = %s\n\r", wifi_ssid); + printf("passwd = %s\n\r", wifi_passwd); + printf("security type = %d\n\r", wifi_security); +#endif /* DEBUG */ + wiFly = new WiflyInterface(WIFLY_PIN_TX, + WIFLY_PIN_RX, + WIFLY_PIN_RESET, + WIFLY_PIN_STATUS, + wifi_ssid, + ((wifi_passwd[0]=='0')&&(wifi_passwd[1]=='\0')) ? NULL : wifi_passwd, + wifi_security);; + server = new TCPSocketServer; + client = new TCPSocketConnection; + + while ( !wiFly || !server || !client ) + { +#ifdef DEBUG + printf("ERROR: unable to allocate memory\n\r"); +#endif /* DEBUG */ + } + + // initilize the app init(); while (1) @@ -166,27 +216,27 @@ #ifdef DEBUG printf("Connecting to WiFi..."); #endif /* DEBUG */ - wifly.init(); // use DHCP + wiFly->init(); // use DHCP #ifdef DEBUG printf("DONE\n\r"); #endif /* DEBUG */ - while (!wifly.connect()) // join the network + while (!wiFly->connect()) // join the network { printf("attempting to connect\n\r"); } #ifdef DEBUG - printf("IP Address is %s\n\r", wifly.getIPAddress()); + printf("IP Address is %s\n\r", wiFly->getIPAddress()); #endif /* DEBUG */ lcdScreen.locate(0,0); - lcdScreen.printf("IP: %s", wifly.getIPAddress()); - server.bind(WIFI_ECHO_SERVER_PORT); - server.listen(); + lcdScreen.printf("IP: %s", wiFly->getIPAddress()); + server->bind(WIFI_ECHO_SERVER_PORT); + server->listen(); #ifdef DEBUG printf("\n\rWait for remote connection...\n\r"); #endif /* DEBUG */ - server.accept(client); // wait until remote host connects - client.set_blocking(false); + server->accept(*client); // wait until remote host connects + client->set_blocking(false); #ifdef DEBUG printf("remote host connected!\n\r"); #endif /* DEBUG */ @@ -227,7 +277,7 @@ #endif /* DEBUG */ strcpy( wiflyBuffer, "ROBot awaiting commands\n\r"); - client.send_all(wiflyBuffer, strlen(wiflyBuffer)); + client->send_all(wiflyBuffer, strlen(wiflyBuffer)); } /* Name: ROBot_sm() @@ -248,7 +298,7 @@ if ( range < RANGE_COLLISION ) { strcpy( wiflyBuffer, "\n\r**** COLLISION AVOIDANCE ****\n\r"); - client.send_all(wiflyBuffer, strlen(wiflyBuffer)); + client->send_all(wiflyBuffer, strlen(wiflyBuffer)); if ( ROBot_STATUS != STATUS_NEAR_COLLISION ) { moveStop(); @@ -262,7 +312,7 @@ { strcpy( wiflyBuffer, "\n\r**** COLLISION WARNING ****"); sprintf(wiflyBuffer, "%s %0.3f\n\r", wiflyBuffer, range); - client.send_all(wiflyBuffer, strlen(wiflyBuffer)); + client->send_all(wiflyBuffer, strlen(wiflyBuffer)); #ifdef DEBUG printf("%s", wiflyBuffer); #endif /* DEBUG */ @@ -279,7 +329,7 @@ // receive input and process it memset(wiflyBuffer, 0, sizeof(wiflyBuffer)); - int numCmds = client.receive(wiflyBuffer, sizeof(wiflyBuffer)); + int numCmds = client->receive(wiflyBuffer, sizeof(wiflyBuffer)); etROBot_CMD *pCmd = (etROBot_CMD *) wiflyBuffer; while ( numCmds > 0 ) {