00001 // Roomba.h 00002 // 00003 /// 00004 /// \mainpage Roomba library for Arduino 00005 /// 00006 /// This is the Arduino Roomba library. 00007 /// It provides an object-oriented interface for talking to iRobot Roomba and Create robots 00008 /// via a serial port. 00009 /// The Roomba is the original device from iRobot. It has a serial port DIN socket on the side. 00010 /// The Create is a more full-featured robot platform for hobbyists. It has both the DIN socket and a DB25 00011 /// connector called the CArgo Bay Connector 00012 /// 00013 /// The Create understands a superset of the Roomba commands. This library supports both devices. Where 00014 /// comands are only available on one or the other platform it is noted. 00015 /// 00016 /// The version of the package that this documentation refers to can be downloaded 00017 /// from http://www.open.com.au/mikem/arduino/Roomba/Roomba-1.2.zip 00018 /// You can find the latest version at http://www.open.com.au/mikem/arduino/Roomba 00019 /// 00020 /// Tested on Arduino Duemilanove, Diecimila and Mega with arduino-0018 on OpenSuSE 11.1 and avr-libc-1.6.1-1.15, 00021 /// cross-avr-binutils-2.19-9.1, cross-avr-gcc-4.1.3_20080612-26.5. 00022 /// 00023 /// A number of example programs are included that work with the iRobot Create: 00024 /// \li TestSuite Runs on a Mega and exercises a number of the functions, checking for correct operation 00025 /// \li RoombaTest1 Runs in any Arduino, checks that sensors can be read from Create using the stream() command 00026 /// \li RoombaRCRx Demo program that shows how to control a Create using the RCRx Arduino library, 00027 /// an Arduino WiFi shield such as BlackWidow and the RCTx 00028 /// iPhone app. Control a Create from your iPhone! 00029 /// 00030 /// A video domonstating this library (along with the http://www.open.com.au/mikem/arduino/RCKit library) 00031 /// being used to control a Create from an iPhone or iPad can be found at http://www.youtube.com/watch?v=Qv-5ZOb5WW4 00032 /// 00033 /// \par Installation 00034 /// Install in the usual way: unzip the distribution zip file to the libraries 00035 /// sub-folder of your sketchbook. 00036 /// 00037 /// This software is Copyright (C) 2010 Mike McCauley. Use is subject to license 00038 /// conditions. The main licensing options available are GPL V2 or Commercial: 00039 /// 00040 /// \par Open Source Licensing GPL V2 00041 /// This is the appropriate option if you want to share the source code of your 00042 /// application with everyone you distribute it to, and you also want to give them 00043 /// the right to share who uses it. If you wish to use this software under Open 00044 /// Source Licensing, you must contribute all your source code to the open source 00045 /// community in accordance with the GPL Version 2 when your application is 00046 /// distributed. See http://www.gnu.org/copyleft/gpl.html 00047 /// 00048 /// \par Commercial Licensing 00049 /// This is the appropriate option if you are creating proprietary applications 00050 /// and you are not prepared to distribute and share the source code of your 00051 /// application. Contact info@open.com.au for details. 00052 /// 00053 /// \par Revision History 00054 /// \version 1.0 Initial release 00055 /// \version 1.1 Updated docs, added Youtube video 00056 /// \version 1.2 Compiles under Arduino 1.0 00057 /// 00058 /// \author Mike McCauley (mikem@open.com.au) 00059 // Copyright (C) 2010 Mike McCauley 00060 // $Id: Roomba.h,v 1.1 2010/09/27 21:58:32 mikem Exp mikem $ 00061 00062 #ifndef Roomba_h 00063 #define Roomba_h 00064 00065 #if (ARDUINO < 100) 00066 #include "WProgram.h" 00067 #else 00068 #include <Arduino.h> 00069 #endif 00070 00071 /// Masks for LEDs in leds() 00072 #define ROOMBA_MASK_LED_NONE 0 00073 #define ROOMBA_MASK_LED_PLAY 0x2 00074 #define ROOMBA_MASK_LED_ADVANCE 0x8 00075 00076 /// Masks for digitalOut() 00077 #define ROOMBA_MASK_DIGITAL_OUT_0 0x1 00078 #define ROOMBA_MASK_DIGITAL_OUT_1 0x2 00079 #define ROOMBA_MASK_DIGITAL_OUT_2 0x4 00080 00081 /// Masks for drivers() 00082 #define ROOMBA_MASK_DRIVER_0 0x1 00083 #define ROOMBA_MASK_DRIVER_1 0x2 00084 #define ROOMBA_MASK_DRIVER_2 0x4 00085 /// Roomba only: 00086 #define ROOMBA_MASK_SIDE_BRUSH 0x1 00087 #define ROOMBA_MASK_VACUUM 0x2 00088 #define ROOMBA_MASK_MAIN_BRUSH 0x4 00089 00090 /// Masks for bumps and wheedrops sensor packet id 7 00091 #define ROOMBA_MASK_BUMP_RIGHT 0x1 00092 #define ROOMBA_MASK_BUMP_LEFT 0x2 00093 #define ROOMBA_MASK_WHEELDROP_RIGHT 0x4 00094 #define ROOMBA_MASK_WHEELDROP_LEFT 0x8 00095 #define ROOMBA_MASK_WHEELDROP_CASTER 0x10 00096 00097 /// Masks for driver overcurrents Packet ID 13 00098 #define ROOMBA_MASK_LD1 0x1 00099 #define ROOMBA_MASK_LD0 0x2 00100 #define ROOMBA_MASK_LD2 0x4 00101 #define ROOMBA_MASK_RIGHT_WHEEL 0x8 00102 #define ROOMBA_MASK_LEFT_WHEEL 0x10 00103 // Roomba, use ROOMBA_MASK_SIDE_BRUSH, ROOMBA_MASK_VACUUM, ROOMBA_MASK_MAIN_BRUSH 00104 00105 /// Masks for buttons sensor packet ID 18 00106 /// Create 00107 #define ROOMBA_MASK_BUTTON_PLAY 0x1 00108 #define ROOMBA_MASK_BUTTON_ADVANCE 0x4 00109 /// Roomba 00110 #define ROOMBA_MASK_BUTTON_MAX 0x1 00111 #define ROOMBA_MASK_BUTTON_CLEAN 0x2 00112 #define ROOMBA_MASK_BUTTON_SPOT 0x4 00113 #define ROOMBA_MASK_BUTTON_POWER 0x8 00114 00115 /// Masks for digital inputs sensor packet ID 32 00116 #define ROOMBA_MASK_DIGITAL_IN_0 0x1 00117 #define ROOMBA_MASK_DIGITAL_IN_1 0x2 00118 #define ROOMBA_MASK_DIGITAL_IN_2 0x4 00119 #define ROOMBA_MASK_DIGITAL_IN_3 0x8 00120 #define ROOMBA_MASK_DIGITAL_IN_DEVICE_DETECT 0x10 00121 00122 /// Masks for charging sources sensor packet ID 34 00123 #define ROOMBA_MASK_INTERNAL_CHARGER 0x1 00124 #define ROOMBA_MASK_HOME_BASE 0x2 00125 00126 /// \def ROOMBA_READ_TIMEOUT 00127 /// Read timeout in milliseconds. 00128 /// If we have to wait more than this to read a char when we are expecting one, then something is wrong. 00129 #define ROOMBA_READ_TIMEOUT 200 00130 00131 // You may be able to set this so you can use Roomba with NewSoftSerial 00132 // instead of HardwareSerial 00133 //#define HardwareSerial NewSoftSerial 00134 00135 ///////////////////////////////////////////////////////////////////// 00136 /// \class Roomba Roomba.h <Roomba.h> 00137 /// \brief Support for iRobot Roomba and Create platforms via serial port using the iRobot Open Interface (OI) 00138 /// protocol. 00139 /// 00140 /// The iRobot Roomba and Create platforms support a serial port through which you can control and 00141 /// interrogate the device. The protocol implemented here conforms to the Open Interface protocol described in the 00142 /// iRobot Open Interface Command Reference. Not all commands are supported on both platforms. Differences are 00143 /// noted in the API 00144 /// 00145 /// The Roomba and Create is equipped with a min-din serial port socket, while the Create 00146 /// is also equipped with a 25-pin D connector called the Cargo Bay Connector. The 00147 /// pins on the Cargo Bay Connector include the serial port, battery, digital inputs and 00148 /// outputs, and an analog input. 00149 /// 00150 /// In order to communicate with a Roomba, you must create an instance of the Roomba class and then call its 00151 /// instance methods to send commmands and receive sensor messages. You can also request continuous 00152 /// streams of sensor data to be sent by the Roomba. The Roomba also emits messages on its 00153 /// serial port from time to time as described below. 00154 /// 00155 /// \par Electrical Considerations 00156 /// 00157 /// The serial port output TXD from the Roomba/Create is too weak to drive the RX serial port input 00158 /// of an Arduino properly. 00159 /// This is because of the USB-Serial converter on the Arduino: it also tries to drive the RX serial port input 00160 /// via a pullup resistor, 00161 /// but the Roomba does not have enough drive to pull the RX down below about 2.5 volts, which is insufficient 00162 /// to be reliably detected as a TTL serial input of 0. 00163 /// 00164 /// \note Note that this problem does not affect the Serial1 Serial2 or Serial3 ports on the Mega: these ports do not 00165 /// have other circuitry connected to them and the Roomba can drive the serial port inputs of these ports 00166 /// without a problem. Its only the RX Serial port (ie the first Serial port) that is affected by this problem. 00167 /// 00168 /// What this means is that if you intend to connect a Roomba to the standard (first) RX/TX serial port on an Arduino 00169 /// you \a MUST have additional circuitry to help drive RX on the Arduino low enough. 00170 /// We use a simple PNP emitter follower. Almost any small signal low power PNP will do. 00171 /// See the <a href="Create-Arduino.pdf">example circuit diagram</a>. This will ensure the RX serial 00172 /// port input on the Arduino is pulled down to about 0.6V for reliable comms. 00173 /// 00174 /// \par Other Roomba messages 00175 /// 00176 /// When iRobot Create powers up and after a reset, it sends a message like this on its serial port: 00177 /// \code 00178 /// bl-start 00179 /// 2006-09-12-1137-L 00180 /// RDK by iRobot! 00181 /// MC9S12E128 00182 /// 2006-11-20-1731-L 00183 /// battery-current-quiescent-raw 524 battery-current-zero 510 00184 /// 00185 /// 2006-11-20-1731-L 00186 /// \endcode 00187 /// 00188 /// While charging it will send a message like this each second: 00189 /// \code 00190 /// bat: min 3 sec 21 mV 15558 mA 1491 deg-C 24 00191 /// \endcode 00192 /// 00193 /// To enter the factory test menu for the IRobot Create, hold down the (>) and (>>|) 00194 /// buttons then press and hold the Power button until the assending and descending tones play and then stop. 00195 /// You wil see some messages emitted on teh serial port. 00196 /// Press the right-right arrow button to cycle through the tests. 00197 /// 00198 class Roomba 00199 { 00200 public: 00201 /// \enum Baud 00202 /// Demo types to pass to Roomba::baud() 00203 typedef enum 00204 { 00205 Baud300 = 0, 00206 Baud600 = 1, 00207 Baud1200 = 2, 00208 Baud2400 = 3, 00209 Baud4800 = 4, 00210 Baud9600 = 5, 00211 Baud14400 = 6, 00212 Baud19200 = 7, 00213 Baud28800 = 8, 00214 Baud38400 = 9, 00215 Baud57600 = 10, 00216 Baud115200 = 11, 00217 } Baud; 00218 00219 /// \enum Demo 00220 /// Demo types to pass to Roomba::demo() 00221 typedef enum 00222 { 00223 DemoAbort = -1, 00224 DemoCover = 0, 00225 DemoCoverAndDock = 1, 00226 DemoSpotCover = 2, 00227 DemoMouse = 3, 00228 DemoDriveFigureEight = 4, 00229 DemoWimp = 5, 00230 DemoHome = 6, 00231 DemoTag = 7, 00232 DemoPachelbel = 8, 00233 DemoBanjo = 9, 00234 } Demo; 00235 00236 /// \enum Drive 00237 /// Special values for radius in Roomba::drive() 00238 typedef enum 00239 { 00240 DriveStraight = 0x8000, 00241 DriveInPlaceClockwise = 0xFFFF, 00242 DriveInPlaceCounterClockwise = 0x0001, 00243 } Drive; 00244 00245 /// \enum StreamCommand 00246 /// Values to pass to Roomba::streamCommand() 00247 typedef enum 00248 { 00249 StreamCommandPause = 0, 00250 StreamCommandResume = 1, 00251 } StreamCommand; 00252 00253 /// \enum EventType 00254 /// Values to pass to Roomba::waitEvent() 00255 typedef enum 00256 { 00257 EventTypeWheelDrop = 1, 00258 EventTypeFronWheelDrop = 2, 00259 EventTypeLeftWheelDrop = 3, 00260 EventTypeRightWheelDrop = 4, 00261 EventTypeBump = 5, 00262 EventTypeLeftBump = 6, 00263 EventTypeRightBump = 7, 00264 EventTypeVirtualWall = 8, 00265 EventTypeWall = 9, 00266 EventTypeCliff = 10, 00267 EventTypeLeftCliff = 11, 00268 EventTypeFrontLeftCliff = 12, 00269 EventTypeFrontRightCliff = 13, 00270 EventTypeRightCliff = 14, 00271 EventTypeHomeBase = 15, 00272 EventTypeAdvanceButton = 16, 00273 EventTypePlayButton = 17, 00274 EventTypeDigitalInput0 = 18, 00275 EventTypeDigitalInput1 = 19, 00276 EventTypeDigitalInput2 = 20, 00277 EventTypeDigitalInput3 = 21, 00278 EventTypeModePassive = 22, 00279 } EventType; 00280 00281 /// \enum IRCommand 00282 /// Values for sensor packet ID 27 00283 typedef enum 00284 { 00285 // Remote control: 00286 IRCommandLeft = 129, 00287 IRCommandForward = 130, 00288 IRCommandRight = 131, 00289 IRCommandSpot = 132, 00290 IRCommandMax = 133, 00291 IRCommandSmall = 134, 00292 IRCommandMedium = 135, 00293 IRCommandLargeClean = 136, 00294 IRCommandPause = 137, 00295 IRCommandPower = 138, 00296 IRCommandArcForwardLeft = 139, 00297 IRCommandArcForwardRight = 140, 00298 IRCommandDriveStop = 141, 00299 // Scheduling Remote: 00300 IRCommandSendAll = 142, 00301 IRCommandSeekDock = 143, 00302 // Home Base: 00303 IRCommandReserved1 = 240, 00304 IRCommandRedBuoy = 248, 00305 IRCommandGreenBuoy = 244, 00306 IRCommandForceField = 242, 00307 IRCommandRedGreenBuoy = 252, 00308 IRCommandRedBuoyForceField = 250, 00309 IRCommandGreenBuoyForceField = 246, 00310 IRCommandRedGreenBuoyForceField = 254, 00311 } IRCommand; 00312 00313 /// \enum ChargeState 00314 /// Values for sensor packet ID 21 00315 typedef enum 00316 { 00317 ChargeStateNotCharging = 0, 00318 ChargeStateReconditioningCharging = 1, 00319 ChargeStateFullChanrging = 2, 00320 ChargeStateTrickleCharging = 3, 00321 ChargeStateWaiting = 4, 00322 ChargeStateFault = 5, 00323 } ChargeState; 00324 00325 /// \enum Mode 00326 /// Values for sensor packet ID 35 00327 typedef enum 00328 { 00329 ModeOff = 0, 00330 ModePassive = 1, 00331 ModeSafe = 2, 00332 ModeFull = 3, 00333 } Mode; 00334 00335 /// \enum Sensor 00336 /// Values for sensor packet IDs to pass to getSensors() and getSensorsList() 00337 typedef enum 00338 { 00339 Sensors7to26 = 0, 00340 Sensors7to16 = 1, 00341 Sensors17to20 = 2, 00342 Sensors21to26 = 3, 00343 Sensors27to34 = 4, 00344 Sensors35to42 = 5, 00345 Sensors7to42 = 6, 00346 SensorBumpsAndWheelDrops = 7, 00347 SensorWall = 8, 00348 SensorCliffLeft = 9, 00349 SensorCliffFrontLeft = 10, 00350 SensorCliffFrontRight = 11, 00351 SensorCliffRight = 12, 00352 SensorVirtualWall = 13, 00353 SensorOvercurrents = 14, 00354 // SensorUnused1 = 15, 00355 // SensorUnused2 = 16, 00356 SensorIRByte = 17, 00357 SensorButtons = 18, 00358 SensorDistance = 19, 00359 SensorAngle = 20, 00360 SensorChargingState = 21, 00361 SensorVoltage = 22, 00362 SensorCurrent = 23, 00363 SensorBatteryTemperature = 24, 00364 SensorBatteryCharge = 25, 00365 SensorBatteryCapacity = 26, 00366 SensorWallSignal = 27, 00367 SensoCliffLeftSignal = 28, 00368 SensoCliffFrontLeftSignal = 29, 00369 SensoCliffFrontRightSignal = 30, 00370 SensoCliffRightSignal = 31, 00371 SensorUserDigitalInputs = 32, 00372 SensorUserAnalogInput = 33, 00373 SensorChargingSourcesAvailable = 34, 00374 SensorOIMode = 35, 00375 SensorSongNumber = 36, 00376 SensorSongPlaying = 37, 00377 SensorNumberOfStreamPackets = 38, 00378 SensorVelocity = 39, 00379 SensorRadius = 40, 00380 SensorRightVelocity = 41, 00381 SensorLeftVelocity = 42, 00382 } Sensor; 00383 00384 /// Constructor. You can have multiple simultaneous Roomba if that makes sense. 00385 /// \param[in] serial POinter to the HardwareSerial port to use to communicate with the Roomba. 00386 /// Defaults to &Serial 00387 /// \param[in] baud the baud rate to use on the serial port. Defaults to 57600, the default for the Roomba. 00388 Roomba(HardwareSerial* serial = &Serial, Baud baud = Baud57600); 00389 00390 /// Resets the Roomba. 00391 /// It will emit its startup message 00392 /// Caution, this may take several seconds to complete 00393 void reset(); 00394 00395 /// Starts the Open Interface and sets the mode to Passive. 00396 /// You must send this before sending any other commands. 00397 /// Initialises the serial port to the baud rate given in the constructor 00398 void start(); 00399 00400 /// Converts the specified baud code into a baud rate in bits per second 00401 /// \param[in] baud Baud code, one of Roomba::Baud 00402 /// \return baud rate in bits per second 00403 uint32_t baudCodeToBaudRate(Baud baud); 00404 00405 /// Changes the baud rate 00406 /// Baud is on of the Roomba::Baud enums 00407 void baud(Baud baud); 00408 00409 /// Sets the OI to Safe mode. 00410 /// In Safe mode, the cliff and wheel drop detectors work to prevent Roomba driving off a cliff 00411 void safeMode(); 00412 00413 /// Sets the OI to Full mode. 00414 /// In Full mode, the cliff and wheel drop detectors do not stop the motors: you are responsible 00415 // for full control of the Roomba 00416 void fullMode(); 00417 00418 /// Puts a Roomba in sleep mode. 00419 /// Roomba only, no equivalent for Create. 00420 void power(); 00421 00422 /// Causes roomba to immediately 00423 /// seek the docking station. 00424 /// No equivalent for Create. 00425 void dock(); 00426 00427 /// Starts the requirested built-in demo 00428 /// \param[in] demo The demo number. One of Roomba::Demo 00429 void demo(Demo demo); 00430 00431 /// Starts the Cover demo 00432 /// Changes mode to Passive 00433 void cover(); 00434 00435 /// Starts the Cover and Dock demo 00436 /// Changes mode to Passive 00437 void coverAndDock(); 00438 00439 /// Starts the Spot Cover demo 00440 /// Changes mode to Passive 00441 void spot(); 00442 00443 /// Starts the Roomba driving with a specified wheel velocity and radius of turn 00444 /// \param[in] velocity Speed in mm/s (-500 to 500 mm/s) 00445 /// \param[in] radius Radius of the turn in mm. (-2000 to 2000 mm). 00446 /// Any of the special values in enum Roomba::Drive may be used instead of a radius value 00447 void drive(int16_t velocity, int16_t radius); 00448 00449 /// Starts the Roomba driving with a specified velocity for each wheel 00450 /// Create only. No equivalent on Roomba. 00451 /// \param[in] leftVelocity Left wheel velocity in mm/s (-500 to 500 mm/s) 00452 /// \param[in] rightVelocity Right wheel velocity in mm/s (-500 to 500 mm/s) 00453 void driveDirect(int16_t leftVelocity, int16_t rightVelocity); 00454 00455 /// Controls the LEDs on the Create 00456 /// \param[in] leds Bitmask specifying which LEDs to activate. ORed combination of ROOMBA_MASK_LED_* 00457 /// \param[in] powerColour The colour of the Power LED. 0 to 255. 0 = green, 255 = red, 00458 /// intermediate values are intermediate colours 00459 /// \param[in] powerIntensity Power LED intensity. 0 to 255. 0 = off, 255 = full intensity 00460 void leds(uint8_t leds, uint8_t powerColour, uint8_t powerIntensity); 00461 00462 /// Sets the digital output pins on the Cargo Bay Connector of the Create 00463 /// Create only. No equivalent on Roomba. 00464 /// \param[in] out Mask specifiying which outputs to enable. ORed value ROOMBA_MASK_DIGITAL_OUT_* 00465 void digitalOut(uint8_t out); 00466 00467 /// Sets the duty cycle for PWM outputs on the low side drivers. These can be use for PWM driving of 00468 /// motors, lights etc. 00469 /// Create only. No equivalent on Roomba. 00470 /// \param[in] dutyCycle0 Duty cycle for low side driver 0. 0 to 128. 00471 /// \param[in] dutyCycle1 Duty cycle for low side driver 1. 0 to 128. 00472 /// \param[in] dutyCycle2 Duty cycle for low side driver 2. 0 to 128. 00473 void pwmDrivers(uint8_t dutyCycle0, uint8_t dutyCycle1, uint8_t dutyCycle2); 00474 00475 /// Sets the low side drivers on or off. On the Romba, these control the 3 motors. 00476 /// \param[in] out Bitmask of putputs to enable. ORed value ROOMBA_MASK_DRIVER_* 00477 void drivers(uint8_t out); 00478 00479 /// Sends the requested byte out of the low side driver 1 (pin 23 on the Cargo Bay Connector). 00480 /// low side driver 1 can be used to drive an IR transmitter to send commands to other Roombas and Creates. 00481 /// Create only. No equivalent on Roomba. 00482 /// \param[in] data Data byte to transmit 00483 void sendIR(uint8_t data); 00484 00485 /// Defines a song which can later be played with playSong() 00486 /// \param[in] songNumber Song number for this song. 0 to 15 00487 /// \param[in] notes Array of note/duration pairs. See Open Interface manual for details. 2 bytes per note, 00488 /// first byte is the note and the second is the duration 00489 /// \param[in] len Length of notes array in bytes, so this will be twice the number of notes in the song 00490 void song(uint8_t songNumber, const uint8_t* notes, int len); 00491 00492 /// Plays a song that has previously been defined by song() 00493 /// \param[in] songNumber The song number to play. 0 to 15 00494 void playSong(uint8_t songNumber); 00495 00496 /// Requests that a stream of sensor data packets be sent by the Roomba. 00497 /// See the Open Interface manual for details on the resutting data. 00498 /// The packets will be sent every 15ms. 00499 /// You can use pollSensors() to receive sensor data streams. 00500 /// Create only. No equivalent on Roomba. 00501 /// See the Open Interface maual for more details and limitations. 00502 /// \param[in] packetIDs Array specifying sensor packet IDs from Roomba::Sensor to be sent. 00503 /// \param[in] len Number of IDs in packetIDs 00504 void stream(const uint8_t* packetIDs, int len); 00505 00506 /// Pause or resume a stream of sensor data packets previously requested by stream() 00507 /// Create only. No equivalent on Roomba. 00508 /// \param[in] command One of Roomba::StreamCommand 00509 void streamCommand(StreamCommand command); 00510 00511 /// Defines a command script which can later be executed with playScript(). You can clear the script by calling 00512 /// script(NULL, 0); 00513 /// Create only. No equivalent on Roomba. 00514 /// \param[in] script Array containing a sequence of Roomba OI commands. 00515 /// \param[in] len Length of the script in bytes. 00516 void script(const uint8_t* script, uint8_t len); 00517 00518 /// Executes a previously defined script, 00519 /// the last one specified by script() 00520 /// Create only. No equivalent on Roomba. 00521 void playScript(); 00522 00523 /// Tells the Roomba to wait for a specified time. 00524 /// This command is intended for use in scripting only. 00525 /// Create only. No equivalent on Roomba. 00526 /// \param[in] ticks The number of ticks to wait. Each tick is 15ms 00527 void wait(uint8_t ticks); 00528 00529 /// Causes Roomba to wait until it has travelled the distance specified. 00530 /// Roomba will not react to any inputs until the wait has completed. 00531 /// Note that this does not cause the host arduino to wait, it only sends the wait comman to the Roomba 00532 /// This command is intended for use in scripting only. 00533 /// Create only. No equivalent on Roomba. 00534 /// \param[in] mm Distance to wait for in mm 00535 void waitDistance(int16_t mm); 00536 00537 /// Causes Roomba to wait until it has rotated through the specified angle. 00538 /// Roomba will not react to any inputs until the wait has completed. 00539 /// Note that this does not cause the host arduino to wait, it only sends the wait comman to the Roomba 00540 /// This command is intended for use in scripting only. 00541 /// Create only. No equivalent on Roomba. 00542 /// \param[in] degrees Angle to wait for in degrees 00543 void waitAngle(int16_t degrees); 00544 00545 /// Cause the Create to wait for a specified event. 00546 /// Roomba will not react to any inputs until the wait has completed. 00547 /// Note that this does not cause the host arduino to wait, it only sends the wait comman to the Roomba 00548 /// Create only. No equivalent on Roomba. 00549 /// \param[in] type Event type to wait for. One of Roomba::EventType 00550 void waitEvent(EventType type); 00551 00552 /// Low level funciton to read len bytes of data from the Roomba 00553 /// Blocks untill all len bytes are read or a read timeout occurs. 00554 /// \param[out] dest Destination where the read data is stored. Must have at least len bytes available. 00555 /// \param[in] len Number of bytes to read 00556 /// \return true if all len bytes were successfully read. Returns false in the case of a timeout 00557 /// on reading any byte. 00558 bool getData(uint8_t* dest, uint8_t len); 00559 00560 /// Reads the sensor data for the specified sensor packet ID. Note that different sensor packets have 00561 /// different lengths, and it is the callers responsibilty to make sure len agrees with the expected 00562 /// length of the sensor data. See the Open Interface manual for details on sensor packet lengths. 00563 /// Roomba.h defines various enums and defines for decoding sensor data. 00564 /// Blocks untill all len bytes are read or a read timeout occurs. 00565 /// \param[in] packetID The ID of the sensor packet to read from Roomba::Sensor 00566 /// \param[out] dest Destination where the read data is stored. Must have at least len bytes available. 00567 /// \param[in] len Number of sensor data bytes to read 00568 /// \return true if all len bytes were successfully read. Returns false in the case of a timeout 00569 /// on reading any byte. 00570 bool getSensors(uint8_t packetID, uint8_t* dest, uint8_t len); 00571 00572 /// Reads the sensor data for the specified set of sensor packet IDs. Note that different sensor packets have 00573 /// different lengths, and it is the callers responsibilty to make sure len agrees with the expected 00574 /// length of the sensor data. See the Open Interface manual for details on sensor packet lengths. 00575 /// Blocks until all len bytes are read or a read timeout occurs. 00576 /// Create only. No equivalent on Roomba. 00577 /// \param[in] packetIDs Array of IDs from Roomba::Sensor of the sensor packets to read 00578 /// \param[in] numPacketIDs number of IDs in the packetIDs array 00579 /// \param[out] dest Destination where the read data is stored. Must have at least len bytes available. 00580 /// \param[in] len Number of sensor data bytes to read and store to dest. 00581 /// \return true if all len bytes were successfully read. Returns false in the case of a timeout 00582 /// on reading any byte. 00583 bool getSensorsList(uint8_t* packetIDs, uint8_t numPacketIDs, uint8_t* dest, uint8_t len); 00584 00585 /// Polls the serial input for data belonging to a sensor data stream previously requested with stream(). 00586 /// As sensor data is read it is appended to dest until at most len bytes are stored there. 00587 /// When a complete sensor stream has been read with a correct checksum, returns true. 00588 /// See the Open Interface manual for details on how the sensor data will be encoded in dest. 00589 /// Discards characters that are not part of a stream, such as the messages the Roomba 00590 /// sends at startup and while charging. 00591 /// Create only. No equivalent on Roomba. 00592 /// \param[out] dest Destination where the read data is stored. Must have at least len bytes available. 00593 /// \param[in] len Max number of sensor data bytes to store to dest 00594 /// \return true when a complete stream has been read, and the checksum is correct. The sensor data 00595 /// (at most len bytes) will have been stored into dest, ready for the caller to decode. 00596 bool pollSensors(uint8_t* dest, uint8_t len); 00597 00598 /// Reads a the contents of the script most recently specified by a call to script(). 00599 /// Create only. No equivalent on Roomba. 00600 /// \param[out] dest Destination where the read data is stored. Must have at least len bytes available. 00601 /// \param[in] len The maximum number of bytes to place in dest. If the script is actually longer than len 00602 /// only len bytes will be written 00603 /// \return The actual number of bytes in the script, even if this is more than len. By calling 00604 /// getScript(NULL, 0), you can determine how many bytes would be required to store the script. 00605 uint8_t getScript(uint8_t* dest, uint8_t len); 00606 00607 private: 00608 /// \enum PollState 00609 /// Values for _pollState 00610 typedef enum 00611 { 00612 PollStateIdle = 0, 00613 PollStateWaitCount = 1, 00614 PollStateWaitBytes = 2, 00615 PollStateWaitChecksum = 3, 00616 } PollState; 00617 00618 /// The baud rate to use for the serial port 00619 uint32_t _baud; 00620 00621 /// The serial port to use to talk to the Roomba 00622 HardwareSerial* _serial; 00623 00624 /// Variables for keeping track of polling of data streams 00625 uint8_t _pollState; /// Current state of polling, one of Roomba::PollState 00626 uint8_t _pollSize; /// Expected size of the data stream in bytes 00627 uint8_t _pollCount; /// Num of bytes read so far 00628 uint8_t _pollChecksum; /// Running checksum counter of data bytes + count 00629 00630 }; 00631 00632 #endif