Controlling RoboSapien using LEGO IR-Tower

Trondheim-Bratislava, July 2005 - January 2006

Slovak version

See also: Controlling RoboPet from RCX

RoboSapien is a humanoid toy robot with many pre-programmed behaviors that can be started from a handy remote control. In order to steer the robot from the PC, one needs to send infrared control signals to the robot. LEGO RCX infrared tower connected to a serial port is a device capable of doing it. It emits the IR light according to the state on the TxD pin of the serial port. Thus knowing the protocol of the Robosapien IR communication, we could easily write a program that sends the control commands to the robot.

First, Richard has made some investigations of the LEGO IR tower and realized that it really emits the signals the way we wish:

Read more about IR tower.

Then Pavel wrote a program using high-precision timers in Windows that was sending the walk IR sequence to the tower, however, the robot did not move. So Richard analyzed the situation:

Read more about what the program did

and we concluded that the thread that is sending the required signals gets scheduled out by Windows, and thus the proper sequence is not transmitted. Therefore we changed the program so that it would run on the highest possible priority, and now it seems to control the robot reliably. You can use it to send all the possible commands RoboSapien recognizes, and you can even write a little script with time delays, which will be sequentially sent to the robot. When you run the program from the command window without arguments, it will print its usage.

Download:

December 23rd 2007, experimental: sapieniso.zip - combined archive with both synchronous and asynchronous version now with the support for the
i-SOBOT!

Older:
sapienX.zip- controling RoboSapien using LEGO IR-tower (WIN32 console application)
This version allows controlling LEGO robots too (using rcxrepeater program). Even more! Control your WowWee robot through LEGO robot even using LEGO USB IR-tower (by relaying through RCX), or store sequences of commands into your RCX and invoke them with PRGM button (or from PC). Lately, the communication part has been rewritten using the asynchronous communication, featuring no need for administrator or superuser priviledges, and CPU utilization falling from 100% to 0%. Read more about how the WowWee robots are controlled using serial protocol...
Previous version (without RCX support, more stable): sapiena.zip.

Old version sapien2i.zip utilizes direct control of TxD and thus avoids spurious impulses generated in asynchroneous communication due to start/stop bits (on the cost of higher CPU load and administrator rights requirement).

This program controls both RoboSapien, RoboSapien V2, RoboPet, and with raw hex values also some other WowWee robots. It contains a simple DLL that allows you to control a robot from your own Windows applications. Linux version included. Java and C# support included. OCX version (support for Imagine Logo). VisualBasic.NET example. Many thanks to Ruby Duck and Robert Oschler for valuable feedback!
Visit EvoSapien site for RoboSapien Dance Machine project, Voice Controlled Robopet Video, and more.

ir2ir.zip - Windows console application for IR-codes conversion (UIRT, Pronto, Sapien hex-codes)

RoboSapien video:

(c) 2005 www.robotika.sk Pavel (ppetrovic (at) acm.org) and Richard (balogh (at) elf.stuba.sk).


Where to buy? In Slovakia and Czech Republic, you can buy RoboSapien from www.gameexpress.sk and www.gameexpress.cz.
(purchasing after clicking on this link will support www.robotika.sk).
User comments: (Poznamky:)

  Robert Oschler, 2006-01-08 17:12:05, reply
Don't forget to tell people about your amazing project where you control a Robopet robot from a Lego Mindstorms RCX computer (Roverbot)!: http://www.robotika.sk/projects/robsapien/petnrcx.php
  Pavel, 2006-01-08 22:56:33, reply
Yes, thanks. The link is also on top of this page: "See also:"
  Andrea, 2006-01-11 10:27:54, reply
controling RoboSapien using LEGO IR-tower is very good

my problem is controls the RoboSapien, RoboSapien V2, RoboPet, to program in to VisualBasic6.

pleas you are simple example for me?..

Andrea
  Pavel, 2006-01-12 07:31:19, reply
Thanks for feedback. Please check the new version sapien2h.zip (link above). I have removed the HANDLE type from the DLL interface, because VB doesn't like it much. New release contains an example in VisualBasic.NET. It should work somehow also with VisualBasic 6 (I cannot test), but some modifications might be needed... Let us know.
  Automated forex trading, 2011-09-05 08:26:01, reply
I wanted to follow up and let you know how , a great deal I loved discovering your web blog today. I would consider it an honor to do things at my office and be able to make use of the tips shared on your web site and also take part in visitors¡¯ remarks like this. Should a position connected with guest writer become offered at your end, make sure you let me know.
  ', 2014-03-31 08:12:21, reply
'
  ', 2014-03-31 08:12:54, reply
'
  , 2014-03-31 08:13:19, reply
  sgray136, 2006-01-09 05:26:10, reply
What is the Serial tower RSV2 code for break wind or fart?
  Pavel, 2006-01-09 06:00:37, reply
Shaughn, :-) How about a hug instead? (Hug:0x379). The codes can be seen here: RoboSapien V2 IR Codes.
  from e-mail communicatoin (RubyDuck said:), 2006-01-10 18:21:41, reply
I couldn't always wake Robopet using the early version of sapien,
so I have tended to use guard mode to start and end sapien scripts.
(I have a feeling that wakeup is more reliable in the web version
using Pavel's dll, but I can't check at the moment as I don't have
the robots.)
  and then Robert replied:, 2006-01-10 18:22:15, reply
RubyDuck,

The Robopet Sleep/Wake command has to be transmitted in a tight repeat
loop for several seconds, until he wakes up. I found that out when
modifying Robosapien Dance Machine to get him to wake up properly. Now it's
very reliable.
  sgray136, 2006-01-15 19:38:31, reply
Has anyone documented a list of IR codes for the Robopet as available for the RS1 and RSV2?
  RubyDuck, 2006-01-16 01:31:55, reply
I think sapien is the only place you will find them (sapien -commandspet).
Program and Execute are missing, so if you can find them let Pavel know.
  panver, 2006-03-22 17:24:45, reply
I want to send IR codes thru LEGO IR-Tower and VB6. When send code for walking or move arms RSV2 execute 1 step and then doesn't respond to any command for about 10 secs. Can someone help?
  Pavel, 2006-03-23 03:02:32, reply
Hello Panver, I do not have V2, cannot help, but perhaps you can tell more about your setup. How are you sending the codes to V2? You can probably just run the external sapien program from your VB application instead of calling DLL functions - the interface is a bit different for VB6 and VB.NET - I do not have access to VB6 here right now, but in principle it should not be a problem to call DLL functions from VB6 too. There are many examples for this online, for example: Calling a C++ DLL from Visual Basic. Write me a mail if you have more.
  joe, 2006-04-12 19:53:03, reply
Pavel, thank you very much for making your code available to Robosapien fans. Just a quick note to let you know that the OCX in the sapiena file works well with VB6. When added as a component to a project I have access to the four functions inside, and have managed to both control RS with single commands and a string of multiple commands, once I worked out the time delay between them. Again, thanks. Regards, Joe.
  Brent Morgan, 2006-05-10 03:09:51, reply
Thanks for making such a wonderful program. It works perfectly with a Lego tower I got off Ebay. Is going to make th v2.0 Sapien from Sharper image much more interactive. Now I just have to make it work in Visual Basic Excel 2000 enviroment. Thats where I am most comfortable programming.

  rishi, 2006-12-08 15:09:38, reply
i'm trying to use the sapien.exe from the sapienx.zip file to talk to the usb lego ir, and it fails on seup of port buffers....the control panel diagnostics says that everything is working fine with the tower, and the code seems to get through the createfile, but don't know why the setupcomm call in sap_open is failing.
any ideas? thanks for any help.
  Palo, 2006-12-08 22:16:10, reply
Many thanks. Please try with the currently linked archive sapienX.zip above.

The story is that the USB tower cannot be configured as a serial port, this must have been introduced when the USB tower was not here to test the release.
We appreciate the feedback.
  rishi, 2006-12-09 07:50:06, reply
thanks for the reply....i am trying with the sapien x archive...i unzipped it and opened up the soln in visual studio.net and am running the sapiena project.
i put some GetLastError() and it reports back 87 (bad/invalid parameters)
on the setupcomm, getcommstate, setcommstate in sap_open....i commented these out to just see what would happen if i just used the defaults (commented out from if (!SetupComm(f, 64, 1024)) to right before the #else
and it compiles and you can run it then without error, but the robosapien (v1)
doesn't seem to respond.

do you have any suggestions as to what to try or how to debug?
thanks again
  rishi, 2006-12-09 07:51:25, reply
sorry...forgot to say that you see the lego ir tower green led go on for awhile when you send the command but the robosapien doesn't respond, so i think the
ir tower is trying to send something but not sure if it's wrong format/something
  Palo, 2006-12-09 10:54:25, reply
Hi! You are right. I am getting back to it... The issue is that the USB tower cannot be used, because it cannot be changed the baud rate, this is hard constrained. So we circumvented this by relaying through RCX. If you got an RCX,
you can relay commands to Sapien by sending them in the path
PC-USB tower-RCX-Sapien. This is done with the -rcx switch. And the RCX needs to be configured first with 'firmdl3 --tty=usb brickOS.srec', and 'dll --tty=usb repeater2.lx' from the rcxrepeater foler. Then one can send a command for example as: 'sapien dance -port //./legotower1 -rcx'. Direct sending functionality is thus available only with the serial tower. Sorry for the confusion!
  rishi, 2006-12-13 16:29:14, reply
this might be a stupid ? but i haven't used the lego rcx before...i got a rcx 1.0 brick and tried to upload the firmware like you said and i get transfer data failed...i tried the slow option as well and it still failed...the debug option gives me this output (see below).

do you have ideas/links? tried to do a search but couldn't find much on this error.
thanks for any help

Hary Mahesan - USB IR Tower Mode.

Transferring "brickOS.srec" to RCX...

0%

1%
mode = slow
sendrecv 6:
Hary Mahesan - USB mode: nbread(len=7, maxlen=4096) break...timed out
recvlen = 7
R 0000: 55 ff 00 9a 65 9a 65
status = no error
sendrecv 6:
Hary Mahesan - USB mode: nbread(len=9, maxlen=4096) break...timed out
recvlen = 9
R 0000: 55 ff 00 8a 75 00 ff 8a 75
status = no error
sendrecv 206:
Hary Mahesan - USB mode: nbread(len=9, maxlen=4096) break...timed out
recvlen = 9
R 0000: 55 ff 00 b2 4d 00 ff b2 4d
status = no error
sendrecv 206:
Hary Mahesan - USB mode: nbread(len=9, maxlen=4096) break...timed out
recvlen = 9
R 0000: b5 00 ba 45 00 ff ba 45 ff
status = bad response from rcx
Hary Mahesan - USB mode: nbread(len=10, maxlen=4096) break...timed out
recvlen = 10
R 0000: 00 d5 00 ba 45 00 ff ba 45 83
status = bad response from rcx
Hary Mahesan - USB mode: nbread(len=9, maxlen=4096) break...timed out
recvlen = 9
R 0000: d5 00 ba 45 00 ff ba 45 c0
status = bad response from rcx
Hary Mahesan - USB mode: nbread(len=10, maxlen=4096) break...timed out
recvlen = 10
R 0000: ed ./firmdl3: transfer data failed
00 ba 45 00 ff ba 45 06 fe
status = bad response from rcx
Hary Mahesan - USB mode: nbread(len=9, maxlen=4096) break...timed out
recvlen = 9
R 0000: ff d5 00 ba 45 00 ff ba 45
status = bad response from rcx
Hary Mahesan - USB mode: nbread(len=8, maxlen=4096) break...timed out
recvlen = 8
R 0000: b5 00 ba 45 00 ff ba 45
status = bad response from rcx
Hary Mahesan - USB mode: nbread(len=11, maxlen=4096) break...timed out
recvlen = 11
R 0000: d5 00 ba 45 00 ff ba 45 80 ff ff
status = bad response from rcx
Hary Mahesan - USB mode: nbread(len=10, maxlen=4096) break...timed out
recvlen = 10
R 0000: b5 00 ba 45 00 ff ba 45 c1 fe
status = bad response from rcx
Hary Mahesan - USB mode: nbread(len=8, maxlen=4096) break...timed out
recvlen = 8
R 0000: ed 00 ba 45 00 ff ba 45
status = bad response from rcx
Hary Mahesan - USB mode: nbread(len=9, maxlen=4096) break...timed out
recvlen = 9
R 0000: a0 ed 00 ba 45 00 ff ba 45
status = bad response from rcx
status = bad response from rcx
  Palo, 2006-12-13 16:39:47, reply
Hi Rishi,

First, please remove the batteries, press the ON/OFF button, and reinsert
the batteries, before downloading the BrickOS firmware.

If it won't help, please try to use fresh batteries in RCX.
Try to shield sources of daylight in your room.
The IR technology is unfortunately unreliable,
and sometimes there seem to be some additional interference
of unkown origin. Try to use some other software - such as
original RIS, RoboLab, or NQC to see if they can download
the original firmware, if they can, the firmdl3 will do too
(after erasing the previous firmware with the battery-remove
operation). I hope you get further than this.
  rishi, 2006-12-15 12:56:32, reply
sweet! i used brixcc to help me download the firmware but i had to have
the tower right up against the rcx port....but after i got the firmware and program loaded, it was cool. i got hold of a serial ir tower...that's a lot easier i'd have to say. thanks for your help!
  from jurong high school jiangsu of China, 2007-05-11 16:05:32, reply
i an from China ,Thanks for your experience of robot ! I'm got a lot ,Thank you!
  Pavel, 2007-05-11 22:25:35, reply
You are very welcome. Thank you for your visit and greetings to China!
Let us know how are you using your robot, and we can post your information here.
  random, 2008-08-08 01:51:49, reply
how do i install
  Pavel, 2008-08-08 11:07:40, reply
Thank you for your comment. Please send us a mail at ppetrovic (at) acm.org.
  Bilal, 2014-01-10 20:11:30, reply
I'm learning robots programming and I've always wanted to have a robot, robosapien is not expensive now compared to other robots so I wanted to know if I could program it using IR tower to send the commands, if yes with which software ?
And can I add any components to the Robosapien ?
Thanks for your help already

Add your comment to the end of this page (napiste sem nieco)