Friday, March 21, 2008

Let's Play with iRobot Create (2)

iRobot Create Open Interface (OI) has many functions, such as controlling LEDs, playing songs and investigating sensors. However, for iRobot Create + Sun SPOT demo, what you need is only
  • Start command
  • Mode command
  • Drive command
"Start" command is a trigger to start OI. iRobot Create has 4 operating modes (Off, Passive, Safe and Full) depending on its control level. In iRobot Create + Sun SPOT demo, you can always use "Full" mode in which you can perfectly contorl iRobot Create, but here I use "Safe" mode which is nearly the same as "Full" mode except having cliff, wheel-drop and internal charger safety features (for detail, see iRobot Create spec).

"Drive" command is used to drive iRobot Create's wheels, which is the main command for this demo. Let's try it with a serial connection + Realterm as previous.

Drive command syntax (in serial sequence) is

[137] [Velocity high byte] [Velocity low byte] [Radius high byte] [Radius low byte]

The range of velocity is -500 to 500 mm/s and that of radius is -2000 to 2000 mm. There are 3 special cases for this radius value as follows:
  • 0x8000 or 0x7FFF: Straight (+ Velocity moves forward and - Velocity moves backward)
  • 0xFFFF: Turn in place clockwise
  • 0x0001: Turn in place counter-clockwise
So, if you want your iRobot Create to perform as the following video,

video

you need to send the following commands:
  • 128 131 (Start OI and puts the OI into Safe mode)
  • 137 0 100 128 0 (move forward at 100 mm/s)
  • 156 1 44 (until traveling 300 mm (3 s))
  • 137 0 0 128 0 (stop)
  • 155 20 (wait for 20 * 1/10 = 2 s)
  • 137 255 156 128 0 (move backward at -100 mm/s)
  • 156 254 212 (until traveling -300 mm (3 s))
  • 137 0 0 128 0 (stop)
  • 155 20 (wait for 20 * 1/10 = 2 s)
  • 137 0 100 0 1 (move counter-clockwise at 100 mm/s)
  • 157 1 105 (until rotating 360 degrees)
  • 137 0 0 128 0 (stop)
  • 155 20 (wait for 20 * 1/10 = 2 s)
  • 137 0 100 255 255 (move clockwise at 100 mm/s)
  • 157 254 152 (until rotating -360 degrees)
  • 137 0 0 128 0 (stop)
I haven't mentioned the "Wait" command above yet, so let me explain it here. iRobot Create OI has a few "Wait" commands that literally wait a next command until some events occur. "Wait Distance (Opcode: 156)" waits until iRobot Create has traveled the specified distance in mm. So the above "156 1 44" waits 3 seconds when it moves at 100 mm/s. In turn, "Wait Angle (Opcode: 157)" waits until it has rotated through specified agnle in degrees. "Wait Time (Opcode 155)" waits for the specified time.

Apart from that, you may as well have a tool converting a decimal integer to a hex. In Ruby, you can use the following script to investigate the value -100, -300 and -360 we used above.

$ cat conv.rb
#!/usr/bin/env ruby

ARGV.each {|n|
s = sprintf("%.4x", n)
puts "#{n} => #{s} (#{s[0,2].hex} #{s[2,4].hex})"
}
$ ./conv.rb -100 -300 -360
-100 => ff9c (255 156)
-300 => fed4 (254 212)
-360 => fe98 (254 152)


To execute the above command with Realterm, power on iRobot Create, send "128 131" first and the rest command at once:

137 0 100 128 0 156 1 44 137 0 0 128 0 155 20 137 255 156 128 0 156 254 212 137 0 0 128 0 155 20 137 0 100 0 1 157 1 105 137 0 0 128 0 155 20 137 0 100 255 255 157 254 152 137 0 0 128 0

Until now, we use serial connection with Realterm to test and understand iRobot Create behavior, but it's much interesting to program iRobot Create? OK, let's delve into it from next time.

6 comments:

Nico said...

Nice explanation! :)

VincentLo said...

how to measure the time in rotation
for example speed at 100mm/s radius =1
and wait for 90 degree

Asad said...

i am using RS232 library for sending commands to roomba.
i have made functions for cw/ccw and forward/reverse motion of the roomba, along with distance and angle functions, which i have checked and are working fine.
The problem i am facing is that my code doesn't allow roomba to do multiple tasks in one single go,
like if i want it to rotate 79 degree in ccw direction and then move 500 mm straight with 500mm/s velocity.
with a stop and 2 sec delay between rotation and straight motion i will send the commands like this.
CCW();
THEETA(79);
STOP();
WAIT(20);
FORWARD();
DISTANCE(500);
these values are then gathered in an array and are sent to roomba through RS232_SendBuf() command, but the roomba stops after rotation only and doesn't move forward.
can you please specify me, where i am doing wrong.

ramya mp said...

i am doing project by using irobot create,can u please send me the code for create has to move in zig zac manner and random manner ,programming through real teerminal please help me out

ramya mp said...

<>can u please send me some more code for create,programming through real terminal

Kimsa2211 said...

Hello, iRobot team of dust-busting Roomba and its grime-fighting partner Scooba will effortlessly rid your home of filth. For detail information visit:
http://kidbuxblog.com/irobot-helps-you-clean-your-house-easily/