Follow me bot application!
Dependencies: Rectangle Servo TextLCD mbed
iRobot.cpp
- Committer:
- dhamilton31
- Date:
- 2013-11-11
- Revision:
- 0:3ed56271dd2d
File content as of revision 0:3ed56271dd2d:
#include "mbed.h" #include "iRobot.h" // Definitions of iRobot Create OpenInterface Command Numbers // See the Create OpenInterface manual for a complete list iRobot::iRobot(PinName tx, PinName rx) : device(tx, rx){ speed_left = 200; speed_right = 200; } // Start - send start and safe mode, start streaming sensor data void iRobot::start() { // device.printf("%c%c", Start, SafeMode); device.putc(Start); device.putc(SafeMode); wait(.5); // device.printf("%c%c%c", SensorStream, char(1), BumpsandDrops); device.putc(SensorStream); device.putc(1); device.putc(BumpsandDrops); wait(.5); } // Stop - turn off drive motors void iRobot::stop() { device.printf("%c%c%c%c%c", DriveDirect, char(0), char(0), char(0), char(0)); } // Forward - turn on drive motors void iRobot::forward() { device.printf("%c%c%c%c%c", DriveDirect, char((speed_right>>8)&0xFF), char(speed_right&0xFF), char((speed_left>>8)&0xFF), char(speed_left&0xFF)); } // Reverse - reverse drive motors void iRobot::reverse() { device.printf("%c%c%c%c%c", DriveDirect, char(((-speed_right)>>8)&0xFF), char((-speed_right)&0xFF), char(((-speed_left)>>8)&0xFF), char((-speed_left)&0xFF)); } // Left - drive motors set to rotate to left void iRobot::left() { device.printf("%c%c%c%c%c", DriveDirect, char((speed_right>>8)&0xFF), char(speed_right&0xFF), char(((-speed_left)>>8)&0xFF), char((-speed_left)&0xFF)); } // Right - drive motors set to rotate to right void iRobot::right() { device.printf("%c%c%c%c%c", DriveDirect, char(((-speed_right)>>8)&0xFF), char((-speed_right)&0xFF), char((speed_left>>8)&0xFF), char(speed_left&0xFF)); } // Charger - search and return to charger using IR beacons (if found) void iRobot::charger() { device.printf("%c%c", Demo, char(1)); } // Play Song - define and play a song void iRobot::playsong() { // Send out notes & duration to define song and then play song 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(0), char(16), char(91), char(24), char(89), char(12), char(87), char(36), char(87), char(24), char(89), char(12), char(91), char(24), char(91), char(12), char(91), char(12), char(89), char(12),char(87), char(12), char(89), char(12), char(91), char(12), char(89), char(12), char(87), char(24), char(86), char(12), char(87), char(48)); wait(.2); device.printf("%c%c", PlaySong, char(0)); }