Nao troubleshooting

From robotica.unileon.es
Revision as of 08:10, 17 February 2011 by Victorm (talk | contribs)

Jump to: navigation, search

You may run into annoying problems while developing for Nao (I certainly did), some easier to solve than others. I will try to explain how to fix the most common ones. If you have any questions regarding this subject or know of a different bug, feel free to send me an email describing it, and I will add it to this section. Just remember to try Google first!

Python fails to run

Using Naoqi in a Python program requires some environment variables to be set. Also, forgetting to remove them before running "normal" programs may give an error. Read this section to know which variables you should declare, among other things.

Imports

If you get an error like "ImportError: No module named naoqi" while trying to run a test, do the following. Open your .bashrc file:

<geshi lang=Bash lines=0>nano ~/.bashrc</geshi>

Go to the end (Page Down) and add this, changing the first path so it points to the location where your SDK is:

<geshi lang=Bash lines=0>export AL_DIR=/media/data/naoqi-sdk-1.10.10-linux export LD_LIBRARY_PATH=$AL_DIR/lib export PATH=$AL_DIR/bin:$PATH export PYTHONHOME=$AL_DIR export PYTHONPATH=.:$AL_DIR/lib:$PYTHONPATH</geshi>

Save, close, exit the terminal and open it again so the changes are applied. Check it with this if you want:

<geshi lang=Bash lines=0>echo $PYTHONHOME</geshi>

You can try now rerunning the test. Please mind that "normal" Python programs (not for Nao) may fail with something like "ImportError: No module named os". This means that you will have to comment the two last exports (the Python ones) and reopen the terminal. It is a bit tiring, but necessary:

<geshi lang=Bash lines=0>export AL_DIR=/media/data/naoqi-sdk-1.10.10-linux export LD_LIBRARY_PATH=$AL_DIR/lib export PATH=$AL_DIR/bin:$PATH

  1. export PYTHONHOME=$AL_DIR
  2. export PYTHONPATH=.:$AL_DIR/lib:$PYTHONPATH</geshi>

Libraries

If you get an error like "ImportError: libtk8.5.so: cannot open shared object file: No such file or directory", it is because Python is trying to access that library using the wrong name. The following will fix it in a "brute force" way. First, locate the library in your system:

<geshi lang=Bash lines=0>sudo updatedb locate libtk8.5.so</geshi>

This will tell you the real location, mine was /usr/lib/libtk8.5.so.0. Python expects it to be just /usr/lib/libtk8.5.so. Let's fix it in an unglamorous fashion:

<geshi lang=Bash lines=0>sudo cp /usr/lib/libtk8.5.so.0 /usr/lib/libtk8.5.so</geshi>

And rerun the test. It is possible that you get the same error relating to libtcl8.5.so. It is fixed the same way, I just had to change the names. Of course, we could create symbolic links or adapt some files here and there, but I am not in the mood.

Cmake fails to run

Cmake is easier to get running in Debian than in Ubuntu, where it tends to complain a lot about undefined variables. If this happens to you, try to pass them as -D parameters, using absolute paths for files or directories. This is the only advice I can give to you.

Can't compile my module

Have you installed all dependencies? If you did, this issue may be similar to the one with Python: the compiler is looking for libraries that have the wrong name. For example, when compiling for Geode I got this: "error while loading shared libraries: libmpfr.so.1: cannot open shared object file: No such file or directory".

I solved it using the solution exposed before. I issued:

<geshi lang=Bash lines=0>sudo cp /usr/lib/libmpfr.so /usr/lib/libmpfr.so.1</geshi>

And tried again to compile.

Nao doesn't load my module

Probably your code has some error that allowed it to compile, but is making it crash when Nao tries to load it. Check Nao's OS logs, and try to debug your application using the common tools (GDB, etc).

It is wise to test your applications in Naoqi before moving them to the real robot (that is, if it is feasible, because Naoqi does not implement all features, like movement), as the debugging will be easier to carry out (and you can easily check the output, too).

Proxy fails to connect

In 99% of the cases, you provided the wrong IP address and/or port. Is Nao up and running, and is your module listed as loaded?

If not, check if the Python call uses the right module and function names.

How to create your own broker

I already told you a few times how important using your own brokers is. If your application hangs while it is "hooked" to Nao's default MainBroker, it will hang too, and the robot may fall to the ground. It is an undesirable situation, believe me.

Creating your own broker is so easy that it hurts. Connect to Nao via SSH as root and edit the module's file:

<geshi lang=Bash lines=0>nano /home/nao/naoqi/preferences/autoload.ini</geshi>

Then, seek the line where your module is, and prepend "[broker name]" to it, like:

<geshi lang=Bash lines=0>[mybroker]</geshi>

This tells Nao to create a new module with that name, that will load the module(s) specified next. Be aware that any other module(s) situated after yours will also be associated to this new broker, unless there is another "[broker name]" line before it/them.

Now you must reboot Nao. Then, before testing your new broker using a Python example, you must find the port it has binded to (it is no longer 9559). This can be easily done with Nmap (use your robot's IP address):

<geshi lang=Bash lines=0>sudo nmap 192.168.1.102 -p9500-10000 -sV</geshi>

The output will say something like "9561/tcp open unknown". That's the port of your new broker. Edit the Python code and you are a go.

How to flash Nao

Did you break something? Have you edited so many files of your Nao that there is no way you can make him run again? Fear not, as you can flash his USB unit anytime to return it to factory state. I will show you how, you just need a bit of patience. After this, he will boot without problems and you will be able to configure him again.

WARNING: Flashing Nao's USB drive will delete forever any file or configuration you uploaded to him. Be sure to backup them before you proceed.

The first thing is to download the OS image from here. Downloads section, "All Downloads", select your SDK's version (1.10.10 as I write this), "NAO OS", and download "NAOos RoboCup Image v1.10.10" (124 MB). Do not extract it! The file nao-system-image-robocup-1.10.10.gz must remain as it is.

Remove Nao's USB stick and plug it to your computer. Go to the bin/ subfolder of your SDK's directory, where a script named flash-usbstick lies. Open a terminal here and issue this, giving the path to the OS image:

<geshi lang=Bash lines=0>sudo ./flash-usbstick ../../nao-system-image-robocup-1.10.10.gz</geshi>

The script will try to detect and use a good enough removable USB drive, that is:

  • Not specially big (512 MB-2 GB).
  • Named "Kingmax".

The script will tell you to "Please umount: /dev/sdb1" (the device name may vary). You have to umount both partitions of the device:

<geshi lang=Bash lines=0>sudo umount /dev/sdb1 sudo umount /dev/sdb2</geshi>

And retry the script. Now it should take some minutes to format the drive and copy the files. After this, you can remove the stick and plug it back on Nao.

NOTE: You can force the script to use a certain drive with -d<device> (like "sda"), and -f (as in force).