Robot App Store Developer Program

robots-app-store-developer-program

Knowledge Base

How to Program Roomba to Drive

  By Anna Sandler

Make sure you are familiar with basic Roomba programming as explained in the "Introduction to Roomba Programming" chapter, and that your Bluetooth device or serial cable's baud rate is configured correctly
as explained in the "Serial Port Baud Rate Configuration" chapter

Things you should know about Roomba driving

The command sequence for driving:
[137] [Velocity high byte] [Velocity low byte] [Radius high byte] [Radius low byte]

Let's drive this robotic vacuum cleaner!
However, first, some facts:
  • Roomba accepts driving command only while at "Full" or "Safe" (recommended) modes;
    If you are not familiar with Roomba modes, please refer to Roomba modes chapter.
    Make sure you use a "Safe" mode for the driving command or a "Full" mode with your own fail-safe implementation;
  • Velocity and Radius of the driving are sent to Roomba as high-low bytes. (The conversion from decimal to high-low bytes is explained below);
  • The Velocity of the driving wheels is specified in millimeters per second;
  • Velocity range is between -500 and 500 mm/s;
  • The higher Velocity value, the faster Roomba will drive;
  • As you can expect negative Velocity value will make Roomba drive backwards, positive values- forward;
  • To stop Roomba’s driving - send driving command with Velocity value zero [0];
  • The Radius is also specified in millimeters;
  • Radius range is between -2000 and 2000 mm and unique value 32768 for driving straight;
  • The higher radius value, the wider the turn angle;
  • Negative radius value will make Roomba to turn right (clockwise), positive- to the left (counterclockwise);
  • For straight driving, use the value 32768 as a radius (convert it to high-low bytes as discussed below);
  • For turning in place, use the value -1 for clockwise, and 1 for counter-clockwise as a radius' value;
  • In order to make Roomba drive for a certain period of time, you need to send a driving command, wait for the desired time period, and then send stop driving command;

How to convert decimal to high-low bytes

The algorithm is very simple: every decimal number can be represented as a hex number;
The first two digits of the hex number are converted back to the decimal that represents the high byte;
the last two digits are converted back to decimal and represent the low byte;

For example, let's take the decimal -200 that in hex is equal to FF38.
The first two digits of this number are FF that equals to 255 in decimal,
and the last two digits are 38 that equals to 56 in decimal.
The high byte that will be sent to Roomba is 255 and the low byte that will be sent to Roomba is 56.

That’s all :)

How to convert decimal to hexadecimal

Hex base is 16 meaning: 0 1 2 3 4 5 6 7 8 9 A B C D E F

How to convert a positive decimal to hexadecimal (the very long way):

The decimal number is divided by 16,
and the remainder is collected (converted to hex) until it can no longer be divided.
Then you simply collect those remainders from the last to the first
and here you've got the hex number!

For example,
Let's convert the decimal 200 to hexadecimal
200/16 = 12 (reminder 0.5 -> 0.5*16 = 8-> 8 decimal in hex is 8),
Remember the result 8.
Let's continue deviding:
12/16 = 0 (reminder 0.75 -> 0.75* 16 = 12 -> 12 decimal in hex is C).
Remember the result C.
As we reached the 0 number for the last devide operation, it can no longer be devided.
So what we've got?
200 decimal = C8 hex (results are collected from the last to the first) = 00C8 hex.

How to convert negative decimal to hexadecimal (the very long way):

The idea is to ignore the minus,
convert the positive decimal to hex,
then subtract each digit from F
and add 1 to the result.

For example,
[-200] is the number in decimal.
The positive decimal is 200.
As shown in the example above, 200 decimal = 00C8 hex.
Back to the negative number -200 decimal = -00C8 hex.
Subtract each digit from F.
-00C8:
F-0 = F,
F-0 = F,
F-C = 3,
F-8 = 7
so we've got FF37.
After adding 1 to the result, we get FF38!

How to convert decimal to hexadecimal (the short way):

Write a method that gets a [decimal number] and returns a high byte:
return (byte)([decimal number] >> 8);

Write a method that gets a [decimal number] and returns a low byte:
return (byte)([decimal number] & 255);

That’s all :)

How to drive straight backward at velocity 200 mm/s

Make sure Roomba is connected, fully charged and its serial port device (serial to USB cable or a Bluetooth device) is connected to your Roomba;

Send the following commands:
  • 128 131
  • 137 255 56 128 0
Explanation
  • 128 131 (Start the command stream and change Roomba mode to "Safe" mode);
  • 137 (Prepare to drive);
  • 255 56 (Velocity high byte and Velocity low byte. Drive 200 mm/s backwards. Negative velocity means to drive backward while positive velocity tells Roomba to drive forward. -200 decimal is converted to 255 high byte and 56 low byte as described above).
  • 128 0 (Radius high byte and Radius low byte. Drive straight, no turning radius. The value to drive straight is 32768 decimal that is 8000 in hex. 80 hex means 128 decimal high byte and 00 hex means 0 decimal low byte);

What's next?

Let's make Roomba sing like Beethoven!

click here cheaters why do wife cheat
signs of a cheater married men that cheat







Related Robot-Apps™

Comments