Control iRobot Create through Windows

526 views
Skip to first unread message

Roy

unread,
Feb 25, 2012, 12:15:23 AM2/25/12
to irobot-cr...@googlegroups.com
I'm normally a Linux C/C++ programmer so Windows programming is somewhat new to me.

I'm working on a group project that *has* to use Windows, and one part of it will be to send commands to the iRobot.
We'll be mounting a Windows laptop on the iRobot Create to control it. Commands will be decided on the fly, so they can't be pre-programmed into the Command Module.

If we were to type out the commands, the easiest way would be to use RealTerm and connect through the USB->serial cable.
However we need to create a class that our other part of the project will use to send the controls.

That being said, should we be going through the Command Module or straight into the OI like when using RealTerm?

It seems like the Command Module doesn't offer benefits as we're using the laptops CPU and don't need a microprocessor.

But getting up and running with a project to control the iRobot using C/C++/C# on Windows is quite the feat.

Is CreateOI sourceforge.net/projects/createoi/ the best solution for this?

I'm having trouble compiling it on Windows 7 (64-bit) with Visual Studio 2010. I can post my errors if anyone is willing to help (if indeed CreateOI is what I should work with).


Thanks for your help!
Roy

dnevill

unread,
Feb 25, 2012, 1:09:52 AM2/25/12
to irobot-cr...@googlegroups.com
I'd be happy to help: I programmed my 'bot entirely in C#. I played
around with that OI in the early days, but it's very incomplete and
very inefficient: you can't have very many sensor packets streaming or
it'll start to bottle up, and a large portion of sensor packet types
aren't defined anyways.

Since you're using visual studio, it's pretty easy to setup
communications. Create a new SerialPort object on whatever COM port
the 'bot is connected to, call that object's Open function and you're
good to go. You don't need to specify baud rate, parity bit, data
bits, etc. as the class already defaults to the settings the Create
uses. Then you can call it's Read (or ReadByte if you prefer) and
Write commands to communicate with it. Be sure to call its Close
function when you close your program or you may have trouble with that
port showing up as closed or otherwise inaccessible.

I just set up a namespace full of constants for all the open interface
OpCodes with <summary> tags on them, so it's quite easy to work with
in Visual Studio. You'll find an incomplete file that does something
similar among the thirty billion documents in that CreateOI C#
framework. I'd be happy to send it your way if you like. Add a
reference to that namespace and you can type out
"SerialPortName.Write(OpCodes." and get a nice drop down box of all
the OpCodes and what kind of data bytes they expect.

(If you think you'll be using the Create's music player, I have the A0
through D5 notes defined as well in another file.)

Sincerely,
Delvan Neville

> --
> You received this message because you are subscribed to the Google Groups
> "iRobot Create Forum" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/irobot-create-forum/-/9WsRa4HfqOAJ.
> To post to this group, send email to irobot-cr...@googlegroups.com.
> To unsubscribe from this group, send email to
> irobot-create-f...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/irobot-create-forum?hl=en.

dnevill

unread,
Feb 25, 2012, 1:12:35 AM2/25/12
to irobot-cr...@googlegroups.com
As a follow up, here's the MSDN entry for the SerialPort object I mentioned
http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx

The MSDN site is pretty useful when you're working with a .NET language.

Sincerely,
Delvan Neville

Roy

unread,
Feb 25, 2012, 3:01:54 PM2/25/12
to iRobot Create Forum
Thanks for your help Delvan.

I won't be using the music at all. Really we're just going to make it
rotate and drive.
We don't really need the sensors except to prevent damage (like
falling off a cliff), but I think "Safe Mode" should prevent that.
We probably will need to interface with the sensor to see if we're
driving/pushing into a wall though.

Otherwise, we won't really need to interface with many of the sensors
or commands.

Yes, please if you have that file or a skeleton project/files to work
with, that would be very helpful,

Did you mean the whole Create Open Interface is inefficient or just
the CreateOI C# framework is inefficient?

Thanks,
Roy

dnevill

unread,
Feb 25, 2012, 3:24:29 PM2/25/12
to irobot-cr...@googlegroups.com
Oh, the Create Open Interface is great! The only thing about it I
dislike is you can't get raw wheel displacements like on a Roomba, it
calculates it's own distance traveled and angle turned, so if it's
turned through less than 1 degree it'll just report 0 degrees.

Yes, in safe mode it'll stop if the cliff sensors trip or if one of
the wheels drop. If you think you'll be using it around stairs, keep
in mind the cliff sensors are on the front and sides of the Create, so
be careful about driving in reverse.

Sensor packet ID 7 covers the bumper and wheel-drop states. There are
no drop-offs at my facility, so I only care about the bumper status.
Here's an edited version of my C# code for handling the bumper packet
once it's ready to be read.


byte wheelAndBump = (byte)yourSerialPortObjectHere.ReadByte();
if ((wheelAndBump & 0x01) == 1)
bumperRight = true;
else
bumperRight = false;
if ((wheelAndBump & 0x02) == 2)
bumperLeft = true; //If the first or second bits are
1, the bumper is pressed.
else
bumperLeft = false;

If you query for the distance or angle packets, they're two byte
values with the high byte sent first, so you can read them with
something like this:

int newDistance = (short)((yourSerialPortObjectHere.ReadByte() << 8) |
(yourSerialPortObjectHere.ReadByte() & 0xFF));

Sincerely,
Delvan Neville

> --
> You received this message because you are subscribed to the Google Groups "iRobot Create Forum" group.

OpCodes.cs

Roy

unread,
Feb 25, 2012, 10:07:58 PM2/25/12
to iRobot Create Forum
Thanks for the OpCodes file. I also found it just now in the CreateOI
and saw your improvements (like how odd it is he kept '130').

To start interfacing with the sensor (like the bump status code you
posted) I first need to initialize a stream, correct?

Seems there's several things needed to get up and running with just a
bot that moves forward, rotates on the spot, doesn't fall, and stops
at a wall - which is all we need.

If I can get the CreateOI C# Framework to work, it does have all that
(among tons of files! Didn't think the framework would require so much
code).
But you said you encountered problems with the framework?

It's a shame iRobot didn't put out just a barebones project that just
includes, for example, a drive forward and stop if bumper is hit. Then
the stream and objects would already be there, and developers can add
their actual movement.
>  OpCodes.cs
> 21KViewDownload

dnevill

unread,
Feb 25, 2012, 10:22:08 PM2/25/12
to irobot-cr...@googlegroups.com
There are two ways to go about your sensor data. You can define a
stream, then start the stream and have an interrupt in your code for
new packets from the 'bot. Or, you can use the sensor query (or query
list) opcodes to just ask for sensor data once, read the data, and
repeat this only as often as you want new data.

When you start up, make a new serial port object. Call Open() then
send OpCode.Mode Passive, wait a moment, then OpCode.Mode Safe

I have mine run a new set of packets every 100ms (stream by default is
every 15ms). You can make a Timer object to send & read your sensor
packets regularly.

If that's really all you want it to do, we're talking 10 or 20 lines
of code for that. A timer (you can use the visual studio component
toolbox to add it if you want) and have it send OpCode.Query 7 (the
bumper sensor packet ID), then reads a byte and updates your bumper
status variables like the code I posted and/or trigger whatever you
want to happen when it bumps into a wall.

Your drive, turn in place and stop functions are just one line each:
OpCode.DriveDirect [two bytes for one wheel] [two bytes for the other
wheel].

When you close your program, call the Close() routine on your serial port.

Sincerely,
Delvan Neville

Roy

unread,
Feb 25, 2012, 10:48:02 PM2/25/12
to iRobot Create Forum
So just basically Stream is for interrupting and instead you poll for
data.

The idea of adding objects in VS is very new to me :)

Are you comfortable with sharing your stripped down code with the
basics (your polling and serialport object, etc)? You don't need to
share the code that makes your bot unique.
If you're not comfortable with that, I understand. But I think it
would be useful to many people for getting started with the iRobot.
Github if you want to make it widely available, if you use Git.

Either way, thank you for your helpful advice.

Roy

dnevill

unread,
Feb 26, 2012, 12:38:42 AM2/26/12
to irobot-cr...@googlegroups.com
I'm still in the middle of working out IP rights for the bulk of the
project: since I'm a graduate student here a lot of the code in the
project I've been developing is technically owned by the university,
and by extension the State of Oregon, not by me. But if you lay down
for me what sensors you want to poll I'd be happy to lay out a basic
C# application that sets up the port, polls for data, and updates some
labels for you. I'm assuming you want a windows forms application
(i.e. a windows style GUI) rather than a console application, yeah?

Sincerely,
Delvan Neville

JoeCreate

unread,
Feb 26, 2012, 10:47:21 AM2/26/12
to irobot-cr...@googlegroups.com
At Laptop on a Robot that simply turns moves, and stops upon bump sounds a bit overkill.  You would be better off using the Command Module.  The example code I have for the command module does what you want to do.  It's written in C so you'd be able to modify very easily.

When you are trying to control the robot with a PC, it's up to You to decide what language you want to write it in, what development environment (IDE) you are comfortable with, and then figuring out how to interface with the robot via Serial or Bluetooth or TCP/IP.  There are lots of "libraries" out there for the iRobot Create for just about any language you decide to use.

I have some code written in C (GNU/GCC) in a Cygwin environment on windows, which may be a more familiar environment for you.  Find Cygwin (a unix-like shell environment for windows) and install GCC (which may already be in there, not sure).  If you do that, I can send you the source I have and you can see if you can make it work.

I have an ActiveX Control that will talk to the robot via serial port on the pc for you.  It collects sensor data for you and makes it available via ActiveX.  Your "app" can be written in client-side javascript or VBScript so your "interface" would simply be a browser.  You can get the activex control from my web site along with examples and instructions.  This might be the way to go for you if you can get the activex part to work.  

Create.exe allows you to control and watch the robot in real-time while at the same time allowing programmatic control via ActiveX.


On Saturday, February 25, 2012 8:07:58 PM UTC-7, Roy wrote:
...
 
It's a shame iRobot didn't put out just a barebones project that just
includes, for example, a drive forward and stop if bumper is hit. Then
the stream and objects would already be there, and developers can add
their actual movement.  
... 
 

dnevill

unread,
Feb 26, 2012, 11:54:21 AM2/26/12
to irobot-cr...@googlegroups.com
I'm sure the laptop is on the robot mainly for processing the data
from their Kinect rather that for 'bot logic.

Sincerely,
Delvan Neville

> --
> You received this message because you are subscribed to the Google Groups
> "iRobot Create Forum" group.

> To view this discussion on the web visit

> https://groups.google.com/d/msg/irobot-create-forum/-/WtEl5AEs6pAJ.

Roy

unread,
Feb 26, 2012, 1:27:19 PM2/26/12
to iRobot Create Forum
Exactly - the Kinect is why we need the laptop.
But I didn't post that we're using a Kinect on the forum, it was in a
private email to you, so JoeCreate wouldn't have known.

dnevill

unread,
Feb 26, 2012, 2:14:47 PM2/26/12
to irobot-cr...@googlegroups.com

Ah, gotcha, I handle the forums via email too, didn't realize that message wasn't there :D

On Feb 26, 2012 10:27 AM, "Roy" <royal...@gmail.com> wrote:

Exactly - the Kinect is why we need the laptop.
But I didn't post that we're using a Kinect on the forum, it was in a
private email to you, so JoeCreate wouldn't have known.


On Feb 26, 8:54 am, dnevill <dnev...@gmail.com> wrote:

> I'm sure the laptop is on the robot mainly...

> On Sun, Feb 26, 2012 at 7:47 AM, JoeCreate <2joes...@gmail.com> wrote:

> > At Laptop on a Robot th...

Joshua Pritt

unread,
May 16, 2014, 11:54:57 PM5/16/14
to irobot-cr...@googlegroups.com
Has anyone been able to turn the robot power on over the serial cable?  I've rigged up a hardwired switch to one of the pins in the mini din serial cable to power the robot on.  I would like to turn the iRobot Create on from the software over the serial commands if possible.  Does anyone know how to turn this on with a serial command?
Reply all
Reply to author
Forward
0 new messages