Difference between revisions of "Nao tutorial 2: First module"

From robotica.unileon.es
Jump to: navigation, search
Line 1: Line 1:
 
The [http://robotica.unileon.es/mediawiki/index.php/Nao_tutorial_1:_First_steps first tutorial] focused about giving you a painless introduction to Nao's world. You turned the robot on, connected to him through the web interface and SSH, configured some parameters and learnt a bit about the most important files and folders.
 
The [http://robotica.unileon.es/mediawiki/index.php/Nao_tutorial_1:_First_steps first tutorial] focused about giving you a painless introduction to Nao's world. You turned the robot on, connected to him through the web interface and SSH, configured some parameters and learnt a bit about the most important files and folders.
  
Now, it is time for you to delve deeper into the subject, and the best way is to code and test your own example module. Nao has some good default applications that allow you to control his behaviour (like Choregraphe), but this is nothing compared with the freedom that compiling your own applications gives to you. Hence, you will now practice with the [http://users.aldebaran-robotics.com/ official SDK] (section <span style="color:#228B22">"Software/Download"</span>)
+
Now, it is time for you to delve deeper into the subject, and the best way is to code and test your own example module. Nao has some good default applications that allow you to control his behaviour (like Choregraphe), but this is nothing compared with the freedom that compiling your own applications gives to you. Hence, you will now practice with the [http://users.aldebaran-robotics.com/ official SDK] (section <span style="color:#228B22">"Software/Download"</span>).
  
 
<span style="color:#606060">'''''NOTE: This tutorial is targeted for version 1.10.10 of the SDK and OS. Older versions like 1.8.16 or 1.6.13 are not likely to work.'''''</span>
 
<span style="color:#606060">'''''NOTE: This tutorial is targeted for version 1.10.10 of the SDK and OS. Older versions like 1.8.16 or 1.6.13 are not likely to work.'''''</span>
Line 9: Line 9:
 
I guess that your testing environment is the same as in the previous tutorial, only with your Nao connecting via wifi now. Also, you will need to download some software from Aldebaran's webpage, but if you are reading this wiki, it's because you are connected to the internet (duh!). Remember to turn your robot off if it isn't already.
 
I guess that your testing environment is the same as in the previous tutorial, only with your Nao connecting via wifi now. Also, you will need to download some software from Aldebaran's webpage, but if you are reading this wiki, it's because you are connected to the internet (duh!). Remember to turn your robot off if it isn't already.
  
==Downloading the software==
+
==Official SDK==
 
 
===Official SDK===
 
  
 
The guys from Aldebaran Robotics have an official SDK (Software Development Kit) available for registered users, on their [http://users.aldebaran-robotics.com/ webpage]. Navigate to this link, enter your login info (you have it, right?), then click the <span style="color:#228B22">"Software"</span> and <span style="color:#228B22">"Download"</span> links.
 
The guys from Aldebaran Robotics have an official SDK (Software Development Kit) available for registered users, on their [http://users.aldebaran-robotics.com/ webpage]. Navigate to this link, enter your login info (you have it, right?), then click the <span style="color:#228B22">"Software"</span> and <span style="color:#228B22">"Download"</span> links.
Line 19: Line 17:
 
You must download the last version of the Linux SDK (1.10.10 currently). After clicking on it, you have to scroll down the user license agreement, <span style="color:#228B22">"I agree"</span>, and <span style="color:#228B22">"Click here to proceed"</span>. Wait for the 162 MB file to download (it's called <span style="color:#1E90FF">''naoqi-sdk-1.10.10-linux.tar.gz''</span>). Extract its contents, and it will spawn a folder named <span style="color:#FF8C00">''naoqi-sdk-1.10.10-linux/''</span>. Move it to the location you like most.
 
You must download the last version of the Linux SDK (1.10.10 currently). After clicking on it, you have to scroll down the user license agreement, <span style="color:#228B22">"I agree"</span>, and <span style="color:#228B22">"Click here to proceed"</span>. Wait for the 162 MB file to download (it's called <span style="color:#1E90FF">''naoqi-sdk-1.10.10-linux.tar.gz''</span>). Extract its contents, and it will spawn a folder named <span style="color:#FF8C00">''naoqi-sdk-1.10.10-linux/''</span>. Move it to the location you like most.
  
===Dependencies===
+
==Dependencies==
  
 
A couple of Linux packages are needed to create and build your own applications. Luckily, this can be as easy as entering the following command in a terminal (Debian or Ubuntu only, folks):
 
A couple of Linux packages are needed to create and build your own applications. Luckily, this can be as easy as entering the following command in a terminal (Debian or Ubuntu only, folks):
Line 26: Line 24:
  
 
=Helloworld example in Naoqi=
 
=Helloworld example in Naoqi=
 +
 +
==Introduction to the SDK==
  
 
Open your <span style="color:#FF8C00">''naoqi-sdk-1.10.10-linux/''</span> folder and take a good look at it. Two text files can be found at the root, <span style="color:#1E90FF">''README.txt''</span> and <span style="color:#1E90FF">''release-note.txt''</span>. Read carefully both. You can also explore the whole content, but there is no need to, as I will now enumerate the most important files and folders of the SDK:
 
Open your <span style="color:#FF8C00">''naoqi-sdk-1.10.10-linux/''</span> folder and take a good look at it. Two text files can be found at the root, <span style="color:#1E90FF">''README.txt''</span> and <span style="color:#1E90FF">''release-note.txt''</span>. Read carefully both. You can also explore the whole content, but there is no need to, as I will now enumerate the most important files and folders of the SDK:
  
 
* <span style="color:#1E90FF">''naoqi''</span> : a shell script located at the root of the folder. It will conveniently start Naoqi after setting all needed environment variables.
 
* <span style="color:#1E90FF">''naoqi''</span> : a shell script located at the root of the folder. It will conveniently start Naoqi after setting all needed environment variables.
* <span style="color:#1E90FF">''toolchain-pc.cmake''</span> : this file must be feed to Cmake when you want to compile something for your local Naoqi (not for the robot).
+
* <span style="color:#1E90FF">''toolchain-pc.cmake''</span> : this file must be fed to Cmake when you want to compile something for your local Naoqi (not for the robot).
 
* <span style="color:#1E90FF">''bin/flash-usbstick''</span> : another script, in this case for formatting an USB stick with a given version of Nao's OS.
 
* <span style="color:#1E90FF">''bin/flash-usbstick''</span> : another script, in this case for formatting an USB stick with a given version of Nao's OS.
 
* <span style="color:#1E90FF">''doc/index.html''</span> : local version of Aldebaran's official documentation. You won't need to go to the website anymore.
 
* <span style="color:#1E90FF">''doc/index.html''</span> : local version of Aldebaran's official documentation. You won't need to go to the website anymore.
Line 38: Line 38:
 
* <span style="color:#FF8C00">''lib/naoqi/''</span> : this is where your Naoqi-compiled modules (libraries) will be placed.
 
* <span style="color:#FF8C00">''lib/naoqi/''</span> : this is where your Naoqi-compiled modules (libraries) will be placed.
 
* <span style="color:#FF8C00">''modules/src/examples/''</span> : all pre-made examples can be found here, like Helloworld.
 
* <span style="color:#FF8C00">''modules/src/examples/''</span> : all pre-made examples can be found here, like Helloworld.
 +
 +
This is almost everything you should know about the SDK for this moment. The normal COA (course of action) when creating a new module is simple: you would usually run <span style="color:#1E90FF">''module_generator.py''</span> to generate a default module with pre-made code. You would then edit it according to your needs, use Cmake to generate the corresponding Makefiles, and use the latter ones to compile the code and build your module. Finally, you would start Naoqi to test it. Naoqi, included with the SDK, lets you create and test code without touching the real Nao. Obviously, not all functionality will be available when doing this.
 +
 +
==Checking the code==
 +
 +
I won't make you generate your own code yet. As this is your first time, we will use one of the available examples. Go to <span style="color:#FF8C00">''naoqi-sdk-1.10.10-linux/modules/src/examples/helloworld''</span>, where 6 files await you. Only the ones with C++ code matter to you, that is, <span style="color:#1E90FF">''alhelloworld.h''</span>, <span style="color:#1E90FF">''alhelloworld.cpp''</span> and <span style="color:#1E90FF">''helloworldmain.cpp''</span>. Open them (any editor will do, like Gedit). <span style="color:#1E90FF">''helloworldmain.cpp''</span> is the least important and just creates an instance of the module, so you will almost never modify it.
 +
 +
The other two are the definition (.h) and implementation (.cpp) of the <span style="color:#FF1493">"ALHelloWorld"</span> module itself. This example in question has only one function, <span style="color:#FF1493">"helloWorld"</span>, that prints the message <span style="color:#FF1493">"Hello World!"</span>, and does nothing more (well, what did you expect?).
 +
 +
==Compiling==
 +
 +
==Testing==
 +
 +
=Module example in Nao=
 +
 +
Working with the real robot instead of Naoqi is as easy as specifying a different toolchain file for Cmake, moving the compiled example to the <span style="color:#FF8C00">''/home/nao/naoqi/lib/naoqi/''</span> folder of your Nao, and appending the name of your module to the <span style="color:#1E90FF">''/home/nao/naoqi/preferences/autoload.ini''</span> file.
 +
 +
==Generating the code==
 +
 +
==Compiling==
 +
 +
==Testing==
  
 
=Troubleshooting=
 
=Troubleshooting=
Line 58: Line 80:
  
 
==How to flash Nao==
 
==How to flash Nao==
 +
 +
=Conclussions=
  
 
----
 
----
  
 
Previous tutorial: [[Nao tutorial 1: First steps]]
 
Previous tutorial: [[Nao tutorial 1: First steps]]

Revision as of 12:19, 2 February 2011

The first tutorial focused about giving you a painless introduction to Nao's world. You turned the robot on, connected to him through the web interface and SSH, configured some parameters and learnt a bit about the most important files and folders.

Now, it is time for you to delve deeper into the subject, and the best way is to code and test your own example module. Nao has some good default applications that allow you to control his behaviour (like Choregraphe), but this is nothing compared with the freedom that compiling your own applications gives to you. Hence, you will now practice with the official SDK (section "Software/Download").

NOTE: This tutorial is targeted for version 1.10.10 of the SDK and OS. Older versions like 1.8.16 or 1.6.13 are not likely to work.

Getting everything ready

I guess that your testing environment is the same as in the previous tutorial, only with your Nao connecting via wifi now. Also, you will need to download some software from Aldebaran's webpage, but if you are reading this wiki, it's because you are connected to the internet (duh!). Remember to turn your robot off if it isn't already.

Official SDK

The guys from Aldebaran Robotics have an official SDK (Software Development Kit) available for registered users, on their webpage. Navigate to this link, enter your login info (you have it, right?), then click the "Software" and "Download" links.

Aldebaran's software download website.

You must download the last version of the Linux SDK (1.10.10 currently). After clicking on it, you have to scroll down the user license agreement, "I agree", and "Click here to proceed". Wait for the 162 MB file to download (it's called naoqi-sdk-1.10.10-linux.tar.gz). Extract its contents, and it will spawn a folder named naoqi-sdk-1.10.10-linux/. Move it to the location you like most.

Dependencies

A couple of Linux packages are needed to create and build your own applications. Luckily, this can be as easy as entering the following command in a terminal (Debian or Ubuntu only, folks):

sudo apt-get install build-essential cmake python-all libboost-all-dev libmpfr-dev -y

Helloworld example in Naoqi

Introduction to the SDK

Open your naoqi-sdk-1.10.10-linux/ folder and take a good look at it. Two text files can be found at the root, README.txt and release-note.txt. Read carefully both. You can also explore the whole content, but there is no need to, as I will now enumerate the most important files and folders of the SDK:

  • naoqi : a shell script located at the root of the folder. It will conveniently start Naoqi after setting all needed environment variables.
  • toolchain-pc.cmake : this file must be fed to Cmake when you want to compile something for your local Naoqi (not for the robot).
  • bin/flash-usbstick : another script, in this case for formatting an USB stick with a given version of Nao's OS.
  • doc/index.html : local version of Aldebaran's official documentation. You won't need to go to the website anymore.
  • modules/src/module_generator.py : Python application for generating your examples from a template. Very handy!
  • preferences/autoload.ini : Configuration file that states which modules should be loaded by Naoqi at startup. Do never mix this autoload.ini with Nao's one!
  • bin/ : this is where your Naoqi-compiled executables will be placed.
  • lib/naoqi/ : this is where your Naoqi-compiled modules (libraries) will be placed.
  • modules/src/examples/ : all pre-made examples can be found here, like Helloworld.

This is almost everything you should know about the SDK for this moment. The normal COA (course of action) when creating a new module is simple: you would usually run module_generator.py to generate a default module with pre-made code. You would then edit it according to your needs, use Cmake to generate the corresponding Makefiles, and use the latter ones to compile the code and build your module. Finally, you would start Naoqi to test it. Naoqi, included with the SDK, lets you create and test code without touching the real Nao. Obviously, not all functionality will be available when doing this.

Checking the code

I won't make you generate your own code yet. As this is your first time, we will use one of the available examples. Go to naoqi-sdk-1.10.10-linux/modules/src/examples/helloworld, where 6 files await you. Only the ones with C++ code matter to you, that is, alhelloworld.h, alhelloworld.cpp and helloworldmain.cpp. Open them (any editor will do, like Gedit). helloworldmain.cpp is the least important and just creates an instance of the module, so you will almost never modify it.

The other two are the definition (.h) and implementation (.cpp) of the "ALHelloWorld" module itself. This example in question has only one function, "helloWorld", that prints the message "Hello World!", and does nothing more (well, what did you expect?).

Compiling

Testing

Module example in Nao

Working with the real robot instead of Naoqi is as easy as specifying a different toolchain file for Cmake, moving the compiled example to the /home/nao/naoqi/lib/naoqi/ folder of your Nao, and appending the name of your module to the /home/nao/naoqi/preferences/autoload.ini file.

Generating the code

Compiling

Testing

Troubleshooting

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

Imports

Libraries

Cmake fails to run

Can't compile my module

Nao doesn't load my module

Proxy fails to connect

How to flash Nao

Conclussions


Previous tutorial: Nao tutorial 1: First steps