Code for RFID Robot
Dependencies: DebounceIn HTTPClient ID12RFID SDFileSystem TextLCD WiflyInterface iniparser mbed
robot.cpp
00001 #include "robot.h" 00002 00003 void initializeRobot() { 00004 printLCD("Initializing", NULL); 00005 // wait for Roomba to power up to accept serial commands 00006 wait(2); 00007 // set baud rate for Roomba factory default 00008 device.baud(57600); 00009 // Start command mode and select sensor data to send back 00010 start(); 00011 00012 //define songs 00013 //one beep 00014 device.printf("%c%c%c%c%c", Song, char(1), char(1), char(69), char(16)); 00015 wait(1); 00016 //georgia tech fight song, split into 3 songs because max song length is 16 00017 device.printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", Song, char(2), char(16), char(67), char(18), char(0), char(2), char(65), char(9), char(0), char(2), char(63), char(18), char(0), char(2), char(63), char(9), char(0), char(2), char(63), char(18), char(0), char(2), char(65), char(9), char(0), char(2), char(67), char(18), char(0), char(2), char(67), char(9), char(0), char(2)); 00018 device.printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", Song, char(14), char(16), char(67), char(9), char(0), char(2), char(65), char(9), char(0), char(2), char(63), char(9), char(0), char(2), char(65), char(9), char(0), char(2), char(65), char(9), char(0), char(2), char(65), char(9), char(0), char(2), char(63), char(18), char(0), char(2), char(62), char(9), char(63), char(54)); 00019 //a major arpeggio 00020 device.printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", Song, char(3), char(7), char(69), char(32), char(73), char(32), char(76), char(32), char(81), char(32), char(76), char(32), char(73), char(32), char(69), char(32)); 00021 clearLCD(); 00022 } 00023 00024 // Start - send start and safe mode, start streaming sensor data 00025 void start() { 00026 // device.printf("%c%c", Start, SafeMode); 00027 device.putc(Start); 00028 wait(.1); 00029 device.putc(Control); 00030 wait(.5); 00031 // device.printf("%c%c", SensorStream, char(1)); 00032 device.putc(Sensors); 00033 device.putc(BumpsandDrops); 00034 wait(.5); 00035 } 00036 // Stop - turn off drive motors 00037 void stop() { 00038 device.printf("%c%c%c%c%c", Drive, char(0), char(0), char(0), char(0)); 00039 } 00040 // Forward - turn on drive motors 00041 void forward() { 00042 device.printf("%c%c%c%c%c", Drive, char((speed>>8)&0xFF), char(speed&0xFF), 00043 char((radius>>8)&0xFF), char(radius&0xFF)); 00044 00045 } 00046 // Reverse - reverse drive motors 00047 void reverse() { 00048 device.printf("%c%c%c%c%c", Drive, char(((-speed)>>8)&0xFF), char((-speed)&0xFF), 00049 char(((radius)>>8)&0xFF), char((radius)&0xFF)); 00050 00051 } 00052 // Left - drive motors set to rotate to left 00053 void left() { 00054 device.printf("%c%c%c%c%c", Drive, char((speed>>8)&0xFF), char(speed&0xFF), 00055 char(((1)>>8)&0xFF), char((1)&0xFF)); 00056 } 00057 // Right - drive motors set to rotate to right 00058 void right() { 00059 device.printf("%c%c%c%c%c", Drive, char(((speed)>>8)&0xFF), char((speed)&0xFF), 00060 char((-1>>8)&0xFF), char(-1&0xFF)); 00061 00062 } 00063 // Charger - search and return to charger using IR beacons (if found) 00064 void charger() { 00065 device.printf("%c", Clean ); 00066 wait(.2); 00067 device.printf("%c", CoverandDock ); 00068 } 00069 // Play Song - play a song 00070 void playsong(int mag) { //Play song 00071 if(mag == 2) { //play rest of georgia tech fight song 00072 device.printf("%c%c%c%c%c%c%c%c", NewScript, char(6), PlaySong, char(2), WaitTime, char(20), PlaySong, char(14)); 00073 device.printf("%c", DoScript); 00074 } 00075 else { 00076 device.printf("%c%c", PlaySong, char(mag)); 00077 } 00078 }
Generated on Tue Jul 12 2022 18:24:35 by 1.7.2