Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
HOWTO use Lego Mindstorms with Gentoo Linux
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
Luud
Apprentice
Apprentice


Joined: 05 Jun 2003
Posts: 246
Location: Netherlands

PostPosted: Tue Apr 13, 2004 12:12 pm    Post subject: HOWTO use Lego Mindstorms with Gentoo Linux Reply with quote

HOWTO use Lego Mindstorms with Gentoo Linux
current version is 0.2

Contents
1. Introduction
2. Disclaimer
3. What is this Lego® Mindstorms™ thingy?
4. The robots
5. The USB Infrared Tower
6. Available Linux Software for Lego Mindstorms
6.a. brickOS
6.b. Not Quite C
6.c. leJOS (java for the RCX)
7. Installation of Linux Software for Lego Mindstorms
7.a. Lego USB Tower with Kernel 2.4
7.b. Lego USB Tower with Kernel 2.6
7.c. brickOS
7.d. Not Quite C
7.e. leJOS
8. References and online documentation about Lego Mindstorms and related stuff
9. Credits
10. Revisions


1. Introduction

This HOWTO is intended to get the novice 'Lego Mindstorms with Gentoo Linux' user started. I wrote this as a help to both others and myself as I am a novice to Lego Mindstorms too. I just received the RIS 2.0 kit a week ago. :D It is my hope that this HOWTO will evolve to into a useful resource for all Lego Mindstorms and Gentoo Linux enthusiasts.

IMPORTANT NOTE: This HOWTO is still under development. Any comments and feedback is very welcome. For discussion about this subject, please post in this thread: Lego Mindstorms (ebuilds and usb!).


2. Disclaimer

Use the information in this document at your own risk.
I disavow any potential liability for the contents of this document.
Use of the concepts, examples, and/or other content of this document is entirely at your own risk.
All copyrights are owned by their owners, unless specifically noted otherwise.
Use of a term in this document should not be regarded as affecting the validity of any trademark or service mark.
Naming of particular products or brands should not be seen as endorsements.
You are strongly recommended to take a backup of your system before major installation and backups at regular intervals.

This HOWTO is neither sponsored nor endorsed in any way by the LEGO(R) Group. LEGO(R), LEGO(R) Mindstorms(TM) Robotics Invention System, and the LEGO(R) logo are registered trademarks of the LEGO(R) Group.


3. What is this Lego® Mindstorms™ thingy?

For those who have never heard of Lego Mindstorms, here a quote from the Lego Mindstorms website: "LEGO® MINDSTORMS™ lets you design and program real robots that do what you want them to. With the Robotics Invention System 2.0™, the core set of the LEGO MINDSTORMS product range, you can create everything from a light-sensitive intruder alarm to a robotic rover that can follow a trail, move around obstacles, and even duck into dark corners." (see references at the end of this HOWTO.)

Although Lego typically makes toys for kids, the Lego Mindstorms products is also used in academics as it is cheap and easy to build all kinds of robots. (e.g. see the LEGOBots website of the Indiana University.)

On the O'Reilly Network there is a nice article giving some clues to the history of Lego Mindstorms: Lego MindStorms: Lego and MIT. Here a quote from the article: "Lego gives MIT money so they can investigate how children learn, how robots think, and other heavy topics. In return, Lego gets to take ideas developed by MIT and make products out of them. In fact, MindStorms is a borrowed name, originally used in a 1980 book by Seymour Papert titled MindStorms: Children, Computers, and Powerful Ideas."


4. The robots

These you have to build yourself. There is quite some information both online and offline on how to do this. This HOWTO will not go into details. Please see the Instructopedia that comes with the Robotics Invention Set or any of the fine books you can find on Amazon. More tips can be found in one or more of the references below.


5. The USB Infrared Tower

This is the important part that we need to get working with Linux before we can start programming our robot. The USB Infrared Tower is the communication means between the brick and the computer.

NOTE: older Mindstorms sets might have a serial infrared tower, these should work as well with Linux, but I have no experience with them.

To be able to use the USB infrared tower, you need a special kernel driver module. The LegoUSB project supports a Linux driver for the LEGO USB Tower found in the Robotics Invention System 2.0. The driver currently works with leJOS, NQC and brickOS. The driver is now officially part of the linux kernel 2.6.1. For older kernels please go to The LegoUSB Project

More information can be found below in the Installation section.


6. Available Linux Software for Lego Mindstorms

Here is a list of available software that allows you to program the RCX from a Linux host. I took the liberty to copy the description of each package from their respective websites to create a quick overview.

As of yet I have no experience with any of them. Remember, I'm learning in the process too :wink:

6.a. brickOS

brickOS is an alternative operating system for the Lego Mindstorms RCX Controller. It also provides a C/C++ development environment for RCX programs using gcc and g++ (the GNU C and C++ cross compilation tool chain) and the necessary tools to download programs to the RCX. If you program in C or C++ and would like to be able to write programs for your RCX in these same languages then brickOS is for you.

(brickOS™ is the new name for Markus L. Noga's legOS, the first open-source operating system for LEGO MINDSTORMS robots)

brickOS website

6.b. Not Quite C

Not Quite C is a simple language with a C-like syntax that can be used to program Lego's RCX programmable brick (from the Mindstorms set). If you are just getting started with programming, then graphical environments such as the Mindstorms RIS software or Robolab are probably better choices. If, however, you're a C programmer and prefer typing a few lines to drag and drop icon programming, then NQC may be perfect for you.

NQC website

6.c. leJOS (java for the RCX)

leJOS is replacement firmware for the Lego Mindstorms RCX brick - a JVM that fits within the 32kb on the RCX. Yes, you can program a Lego robot with Java!

leJOS website


7. Installation of Linux Software for Lego Mindstorms

Here are the steps to install the software and driver for the Lego USB IR Tower. I tested the USB tower and NCQ on three different machines and the three different USB drivers (UHCI, OHCI and EHCI). The installation is based on the unofficial ebuild set created by tomthewombat. These ebuilds have worked flawlessly for me with the procedures described here.

NOTE: I haven't tested brickOS and leJOS yet. Details for those will be added when I've had the time to test them. For now, please check out this thread: Lego Mindstorms (ebuilds and usb!).

For discussions about Lego Mindstorms, please post there and not here. I will read your post there :wink:


7.a. Lego USB Tower with Kernel 2.4

The Lego USB tower is reported to work well with kernel 2.4, as per LegoUSB website::
Quote:
usb-uhci contained a bug introduced in version 2.4.21 which will lock the kernel if used with legousbtower driver. Linux version 2.4.22-pre3 and above include the fix and are safe to use.

usb-ohci was fixed in Linux version 2.4.22-pre3 so that it will work with legousbtower.


If you are still using 2.4.x series, you can get the driver from CVS from the project page.

I haven't tested anything on 2.4 kernel versions myself. I think the ebuild set by tomthewombat will install the legousb tower driver with the legousb-0.5.4 ebuild when you are using kernel 2.4 (see next section for kernel 2.6).


7.b. Lego USB Tower with Kernel 2.6

As per kernel 2.6.1 the LEGO USB Tower driver is now officially part of the linux kernel. There seem to be issues with EHCI and UHCI. A patch against kernel 2.6.4 can be found here (lwn.net) and here (courtesy of tomthewonbat). The homepage of the author is here. This patch works good for me on all USB controller drivers: UHCI, OHCI and EHCI. The patch also works with the 2.6.5-gentoo-r1 kernel.

Here are the steps to get it to work (I assume here that gentoo-dev-sources will give you gentoo-dev-sources-2.6.5-r1):
Code:
# cd /root
# emerge gentoo-dev-sources
# wget http://www.wombatorium.net/ebuilds/legousbtower-0.9-linux-2.6.4.diff

(check if /usr/src/linux is a symlink to /usr/src/linux-2.6.5-gentoo-r1)
# cd /usr/src/linux
# cat /root/legousbtower-0.9-linux-2.6.4.diff | patch -p1


Now your kernel will be patched for the LegoUSBTower device. Build your kernel using the settings for your system. I assume you will know how to do this. I compiled the USB Tower into the kernel, not as module, although the latter should work just as well.

After rebooting with your lego enable kernel and when you are using udev, the device should show up as /dev/usb/legousbtower0. (I have udev-024-r1 installed. My initial /dev directory only contains /dev/console and /dev/null which is needed during boot, all other device are created by udev.) I do not know if devfs will also make the right device node.

Now you can install the software for programming you RCX brick. For this you need to install the ebuild set by tomthewombat. Here are the steps to integrate these ebuilds into you portage setup:
Code:
# cd /root
# wget http://www.wombatorium.net/ebuilds/lego-gentoo-0.1.tar.gz
# mkdir /usr/local/portage_overlay
# cd /usr/local/portage_overlay
# tar -xvzf /root/lego-gentoo-0.1.tar.gz

Now we need to tell portage to use the portage overlay tree. For this add the following to /etc/make.conf:
Code:
PORTDIR_OVERLAY="/usr/local/portage_overlay"

Also make sure that "usb" is present in your use flags!
Code:
USE="usb <and all your other use flags>"

Now all you have to do is install the software. Note that these all use the legousb-0.5.4 ebuild which is included in the ebuild set. For kernel 2.6 this doesn't do much as the legousbtower driver is already in the kernel. For kernel 2.4 this would install the driver module. I haven't tested this with 2.4 though.


7.c. brickOS

I have not tested this yet. To install you should be fine with running:
Code:
# emerge brickos

For now, please check out this thread: Lego Mindstorms (ebuilds and usb!).


7.d. Not Quite C

First get NQC installed.
Code:
# emerge nqc

When this is done you should be able to program the RCX, for example set the internal clock of the RCX to the current time of your linux machine by running:
Code:
# nqc -Susb -watch now

If all is well you should se the led inside the USB tower turn on for a moment and the time on the display of the RCX should be set to the host computer's time.

If you experience any problem, check out this thread: Lego Mindstorms (ebuilds and usb!). If you have questions, please post them there.


7.e. leJOS

I have not tested this yet, and I'm not so sure I will in the near future as I do not care about Java. Also, there is no ebuild for it in the ebuild set by tomthewombat. If anyone wants to experiment with this, please post back your experiences (preferably here to keep this thread clean). I will update this thread according to the feedback.


8. References and online documentation about Lego Mindstorms and related stuff

Here are some useful references:

Official Lego Mindstorms website: http://mindstorms.lego.com/
International LEGO Users Group Network (LUGNET): http://www.lugnet.com/
The LegoUSB Project: http://legousb.sourceforge.net/
Lego USB Tower author Jürgen Stuber's homepage: http://www.loria.fr/~stuber/
brickOS (former legOS): http://brickos.sourceforge.net/
Not Quite C: http://bricxcc.sourceforge.net/nqc/
Older Not Quite C information: http://www.baumfamily.org/nqc_old/index.html
leJOS: http://lejos.sourceforge.net/
Lego MindStorms: Lego and MIT: http://www.oreillynet.com/pub/a/network/2000/01/31/mindstorms/index1b.html
Lego Robot Pages at the Department of Computer Science, Utrecht University, the Netherlands: http://www.cs.uu.nl/people/markov/lego/
LEGOBots at Indiana University: http://www.indiana.edu/~legobots/
Lego Robot Pages at the Department of Computer Science, Utrecht University, the Netherlands: http://www.cs.uu.nl/people/markov/lego/
Lego based robotics by Prof. Hassoun: http://neuron.eng.wayne.edu/LEGO_ROBOTICS/lego_robotics.html
Educational Robotics Repository: http://satchmo.cs.columbia.edu/er/robots.html
Imaginations run wild with Java Lego robots: http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-lejos.html
JP Brown's Serious Lego: http://jpbrown.i8.com/index.html
MindStorms RCX Sensor Input Page: http://www.plazaearth.com/usr/gasperi/lego.htm
David Rees about The Lego Mindstorms Kit: http://www.dcs.ed.ac.uk/teaching/cs3/sysdesign/lego/
Mario Ferrari about Lego Mindstorms: http://www.marioferrari.org/lego_mindstorm.html
Liens Lego Site: http://membres.lycos.fr/vcallede/lego/lienslego.htm
RCX Internals : http://graphics.stanford.edu/~kekoa/rcx/
LDraw: http://www.ldraw.org/
LEGO Robot links: http://www.idi.ntnu.no/grupper/ai/eval/lego_links.html
lego.zappsite.nl (Dutch): http://lego.zappsite.nl/


9. Credits

Credits where credits are due. :wink:

- tomthewombat


10. Revisions

v0.1 (13-apr-2004) Launch of HOWTO. Only references and short description of resources that are available. No detailed installation instructions yet.
v0.2 (07-may-2004) Added detailed installation instruction for the Lego USB Tower driver and NQC when using kernel 2.6.5-gentoo-r1. Plus some other related changes.
_________________
"Great minds don't think alike. If they did, the patent office would only have about fifty inventions." - Wally


Last edited by Luud on Fri May 07, 2004 12:39 pm; edited 3 times in total
Back to top
View user's profile Send private message
dav1d
Tux's lil' helper
Tux's lil' helper


Joined: 31 Dec 2003
Posts: 134

PostPosted: Tue Apr 13, 2004 3:05 pm    Post subject: Reply with quote

Even though I don't use my mindstorms kit any more, I thought I should post this as there are no replies so far.

This looks like a very good set of documentation - very interesting and lots to read up on (good links). I remeber programming in NQC on windows (ah - the good old days), but now I have moved to linux, this would have been very useful if I still used the mindstorms kit (grown a bit old now and not as much time).

Good stuff!
Back to top
View user's profile Send private message
Luud
Apprentice
Apprentice


Joined: 05 Jun 2003
Posts: 246
Location: Netherlands

PostPosted: Fri May 07, 2004 12:26 pm    Post subject: Reply with quote

Added detailed installation instruction for the Lego USB Tower driver and NQC when using kernel 2.6.5-gentoo-r1. Plus some other related changes.

P.S. Thanks dav1d. And remember, you are never to old to play with Lego :lol:
_________________
"Great minds don't think alike. If they did, the patent office would only have about fifty inventions." - Wally
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum