Monday, January 26, 2009

In the middle of bits, PWMs, wires, resin, and electromagnetic waves, TORP (CP01) was born...


January, 25th, around 8:00 pm, during Campus Party 2009, that's when TORP was firstly fully assembled for the first time.
The project aimed at building the first humanoid open source robot in Brazil and it was called TORP (www.theopenrobotproject.org).
The idea was to create a robot that would work as a study platform whose modules would be able to be hot plugged and they could also be interchangeable, since it's hard to unplug a hand from one robot and to couple it to another because of the lack of standards.
Without prior support from public research funds, CP01 (the name of the first assembled version of TORP) was sponsored by several institutes and industries, namely: E3 Futura, Instituto Tecnológico de Aeronáutica, Universidade do Estado de São Paulo, Micropress, RIMA and Campus Party.
For more information about the project, I'd suggest taking a look at http://www.theopenrobotproject.org/ .
I'd really like to thank everyone from the team (please remind me if I've forgotten someone, specially contributers from Campus Party, whose names I couldn't take note):
Alan Morgensztern, Alexandre Simões, Esther Colombini, Guilherme Andrade, Jackson Paul Matsuura, Kauê Silva, Maira, Marcelo Franchin, Melissa Sanchez Freitas, Paulo Vitor Lima, Rafael Ribeiro da Silva, Rafael Toschi Chiafarelli, Ronaldo Carrion, Victor Nalin, and my girlfriend Kathy for all the support. Thanks for my bro and Dé for being there as well :)
And thank You, God, of course, for everything running smoothly :)

If there's anyone interested in the lecture about Computer Vision, here's a link to it (Portuguese only... in case you want it in English, please leave a comment):
http://www.slideshare.net/dannyxyz22/campus-party-computer-vision-presentation


I've tried to gather all news about the project here:
http://tecnologia.terra.com.br/interna/0,,OI3470641-EI12933,00.html
http://oglobo.globo.com/tecnologia/mat/2009/01/25/apresentado-na-campus-party-primeiro-robo-livre-do-mundo-754136596.asp
http://www.gluon.com.br/blog/2009/01/25/noite-de-premiacao-na-campus-party-2009/
http://colunistas.ig.com.br/tecnologia/2009/01/24/cp01-nasce-ao-vivo-na-campus-party/
http://www.ita.br/online/2009/noticias09/campusparty.htm
http://www.unesp.br/int_noticia_2imgs.php?artigo=4041

For photos:
http://www.flickr.com/photos/33142604@N00/tags/campus/

Please, leave your comment about TORP, we'd love to hear your feedback!

Thursday, January 15, 2009

TORP - The Open Robot Project

So, just in case some of you might be interested, here's a link to the official site of TORP - The Open Robot Project (http://www.theopenrobotproject.org/).
Make sure you'll check it out at Campus Party Brasil '09 :)

Tuesday, January 13, 2009

Compiling OpenCV for Gumstix

It's common sense that OpenCV is one of the best computer vision libraries available nowadays and it's certainly very useful to benefit from it in embedded environments. There's a trade-off between locally processing images and uploading them for remote processing, but some algorithms might as well run smoothly on embedded devices.

In order to compile OpenCV for Gumstix, firstly one needs to download it from:
http://sourceforge.net/project/showfiles.php?group_id=22870

The version I've testes was opencv-linux 1.1pre1, but I believe any other release will barely follow the same ideas provided here.
After the file has been extracted (tar -xzvf opencv-1.1pre1.tar.gz), one should configure the environment variables for the compiler:

export CC=/home/developer/gumstix/gumstix-oe/tmp/cross/bin/arm-angstrom-linux-gnueabi-gcc
export CXX=/home/developer/gumstix/gumstix-oe/tmp/cross/bin/arm-angstrom-linux-gnueabi-g++

$ ./configure --host=arm-linux --build=i686-linux --prefix=/home/developer/opencvgum --without-gthread --without-gtk --without-python --disable-apps

Notice that we've defined that the prefix=/home/developer/opencvgum is the place it will be installed when we type 'make install'. By the way, make sure you have created this directory.
Be sure to substitute the /home/developer path to your user path, as well as the /gumstix/gumstix-oe/ to your installed gumstix environment.
We've also disabled the gtk environment since we are not interested in running the GUI applications inside the gumstix. I've also disabled python and building the applications.
Now that configuration has been successful. Type:

$ make


And then:

$ make install

If everything went well, you'll have the binaries and samples installed to /home/developer/opencvgum
Now, it would be useful to try and compile the samples so that we are sure they will run in the Gumstix.
In order to build them, go to /home/developer/opencvgum/share/opencv/samples/c and edit the build_all.sh script.
Make it executable:

$chmod +x ./build_all.sh

And then change all gcc and g++ to its arm-likes. My build_all.sh ended up like this:

#!/bin/sh
export PKG_CONFIG_PATH=/home/developer/opencvgum/lib/pkgconfig/

if [[ $# > 0 ]] ; then
        base=`basename $1 .c`
        echo "compiling $base"
        /home/developer/gumstix/gumstix-oe/tmp/cross/bin/arm-angstrom-linux-gnueabi-gcc -ggdb `pkg-config opencv --cflags --libs` $base.c -o $base
else
        for i in *.c; do
            echo "compiling $i"
            /home/developer/gumstix/gumstix-oe/tmp/cross/bin/arm-angstrom-linux-gnueabi-gcc -ggdb `pkg-config --cflags opencv` -o `basename $i .c` $i `pkg-config --libs opencv`;
        done
        for i in *.cpp; do
            echo "compiling $i"
            /home/developer/gumstix/gumstix-oe/tmp/cross/bin/arm-angstrom-linux-gnueabi-g++ -ggdb `pkg-config --cflags opencv` -o `basename $i .cpp` $i `pkg-config --libs opencv`;
        done
fi

Notice that we've also defined the export PKG_CONFIG_PATH=/home/developer/opencvgum/lib/pkgconfig/ so that the correct includes and linked libraries are built correctly.
Run this command and you'll notice the executable files will be created. I think that if you don't disable the flag "--disable-apps" in the configure application and make this change to the build_all.sh earlier it might also work.

Well, now that OpenCV has been built, you should be able to copy it to your gumstix. There's a small problem though. If you compact the files, you'll notice it's very big, so, a good idea is to delete a couple files we are sure we are not going to use.
An advice would be to delete some of the haarcascades.

Choose some of them you are sure you won't use, like the haarcascade_profileface.xml inside the data sub-directory, for instance. Delete a couple others as well.
This way, you'll be able to create a .tar.gz of around 6.5MB.
When it's done, copy it to your gumstix through scp:

$scp opencvgum.tar.gz root@192.168.YOUR-GUM.IP:/tmp

Make sure you copy it to /tmp, because you'll probably be out of space copying it somewhere else.
Extract it and then try to run one of the demos that does not use windows... the  ./letter_recog application, for instance... it's located at:
/tmp/opencvgum/share/opencv/samples/c

Well, you might be able to see it running. Else, some libstdc++.so is missing error could also happen.
This means you don't have this library installed. One easy way to install it is through the command

$ipkg install libstdc++6

In case some other libraries are missing as well, repeat the procedure with their names. Notice that some packages have odd names.
For instance, if you had typed:
$ root@gumstix-custom-verdex:/usr/share$ ipkg install libstdc++

Then you'd have received the following message:

Nothing to be done
An error ocurred, return value: 4.
Collected errors:
Cannot find package libstdc++.
Check the spelling or perhaps run 'ipkg update'

Actually the name of the library is libstdc++6. Make sure you type the correct library name.

Well, in case libstdc++ is really installed, you might as well get some error like:

./letter_recog: error while loading shared libraries: libcxcore.so.2: cannot open shared object file: No such file or directory

It means the LD_LIBRARY_PATH is not pointing at your opencv libraries.
Simply type:

$ export LD_LIBRARY_PATH=/tmp/opencvgum/lib/

You will eventually be able to run your letter_recognition application.
Well, in case you want to run other applications, like the face recognition one, make sure you disable the GUI related functions and write your results to files.
We'll be able to see it working at Campus-Party Brasil
Make sure you'll be there!

Gumstix UVC drivers

This post describes gumstix uvc driver installation for a Logitech QuickCam Pro 9000. It follows this wiki page as a guideline.
It requires that the steps in this wiki have been performed.
Firstly check-out the old driver sources from:

 svn co svn://svn.berlios.de/linux-uvc/linux-uvc/trunk

After file checkout, one should change the Makefile.
Change the KERNEL_DIR var to point to your gumstix kernel path, as in:

KERNEL_DIR    :=
/home/developer/gumstix/gumstix-oe/tmp/work/gumstix-custom-verdex-angstrom-linux-gnueabi/gumstix-kernel-2.6.21-r1/linux-2.6.21/

Define the CROSS_COMPILE var:

CROSS_COMPILE   := /home/developer/gumstix/gumstix-oe/tmp/cross/bin/arm-angstrom-linux-gnueabi-

Change make lines so that they include your CROSS_COMPILE and ARCH=arm vars:
From:
       @(make -C $(KERNEL_DIR) M=$(PWD) CROSS_COMPILE=$(CROSS_COMPILE) modules)

to:

       @(make -C $(KERNEL_DIR) M=$(PWD) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) modules)

And from:
       @(make -C $(KERNEL_DIR) M=$(PWD) INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) INSTALL_MOD_PATH=$(INSTALL_MOD_PATH) modules_install)
to:
       @(make -C $(KERNEL_DIR) M=$(PWD) ARCH=arm
INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) INSTALL_MOD_PATH=$(INSTALL_MOD_PATH)
modules_install)

Now, type make uvcvideo
The file uvcvideo.ko is built. This file should be copied to /lib/modules/2.6.21/kernel/drivers/media/video/uvcvideo.ko

Nevertheless, if you type make, you'll notice a message like:

-------------------------------- WARNING ---------------------------------------
 The USB Video Class driver has moved to http://linuxtv.org/.
 Using the Berlios SVN repository is now deprecated.
 Please check http://linux-uvc.berlios.de/ for download instructions.
 If you really want to compile this historical version, run 'make uvcvideo'.
--------------------------------------------------------------------------------
which tells us that we are using deprecated files for the driver.
I've tried to use the latest drivers from the Mercurial clone repository, but I'm getting this error:

"/home/developer/uvc-new/uvcvideo-90c7dc24fb4d/v4l/cx18-driver.h:65:4: error: #error "This driver requires kernel PCI support." "

In order to build it, I've changed the root Makefile to:

CROSS_COMPILE   := /home/developer/gumstix/gumstix-oe/tmp/cross/bin/arm-angstrom-linux-gnueabi-

install:
        $(MAKE) -C $(BUILD_DIR) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) install

%::
        $(MAKE) -C $(BUILD_DIR) ARCH=arm CROSS_COMPILE=$(CROSS_COMPILE) $(MAKECMDGOALS)

And the v4l/Makefile to:

OUTDIR ?= /home/developer/gumstix/gumstix-oe/tmp/work/gumstix-custom-verdex-angstrom-linux-gnueabi/gumstix-kernel-2.6.21-r1/image/lib/modules/2.6.21/build
SRCDIR ?= /home/developer/gumstix/gumstix-oe/tmp/work/gumstix-custom-verdex-angstrom-linux-gnueabi/gumstix-kernel-2.6.21-r1/image/lib/modules/2.6.21/source

I've tried to issue some "make -i" command, but I doubt it will work. If you've made any progress with the new drivers, feel free to comment.
The old drivers have worked pretty fine as well.