From Computational Learning and Motor Control Lab

Teaching: InstructionsForNAOSimulatorInstallation

System Requirements:


TAR Archive with Robot Simulator (NOTE: extract with tar -zxf cs545lab.tgz)

Installation Instructions: (DO NOT try this before completing the requirements specified at System Requirements at the top of this page, to the best of your ability!!! When you got problems, please take a time to check common problems described in Problems at the bottom of this page, before emailing the TAs.)

To get what you need to fill-in in the <install_directory> above, on a terminal navigate to the directory that contains the cs545-lab directory, then there type 'pwd' (print current working directory) and copy the result into the <install_directory> field. Once you made the above changes, close the terminal, and open a new one (this is to make sure that the above changes take effect).
If you did not get the above print outs, that means something is wrong with the previous step. Do not proceed to the next step, instead please troubleshoot the previous step.
If any of the above command produces "...No such file or directory", then your configuration is still incorrect, and you need to re-check your environment variables as set previously in your ~/.cshrc or ~/.tcshrc or ~/.profile file.
If you have ROS (Robot Operating System) installed on your system already, you might have a compilation error in one of the steps above (usually it is something about ros.h header file cannot be found). To fix this problem, you can temporarily comment out the line:
source /opt/ros/<ROS_type_name>/setup.bash
(ROS_type_name is either indigo or groovy or kinetic, depending on your ROS version)
in ~/.bashrc file (so that it thinks that ROS has not been installed). Then remove the x86_64 or x86_64mac directory entirely (in the directory where make -s install failed last time) and then do make -s install again. After you successfully installed everything above, you can un-comment the above line in ~/.bashrc file again (so that ROS installation will work again).

NAO Joint/Degrees-of-Freedom Description

NAO Joint/Degrees-of-Freedom Description

Setting Up xnao Programming Environment in an IDE (Qt Creator IDE or Eclipse IDE)

For your convenience in programming in SL (I believe this will ease your life A LOT during programming on xnao), you may choose either one of Qt Creator IDE or Eclipse IDE:

  1. Qt Creator IDE
    • Please download and install Qt Creator IDE. For Ubuntu 12.04, you can get it here: For OS X, you can find it here:
    • Open a terminal (this assumes that you already installed xnao properly, including setting up environment variables such as PROG_ROOT, LAB_ROOT, etc. correctly). Execute the following commands:
      • cd $PROG_ROOT
      • qtcreator &
    • Qt Creator IDE will be opened for you (it is essential that you launch it from a terminal with correctly-setup environment variables such as PROG_ROOT, LAB_ROOT, otherwise the following steps might not be successful). Select File => Open File or Project => Go to Directory <install_directory>/cs545-lab/prog/naoUser/src/ and double-click on CMakeLists.txt. CMake Wizard window will open, then next to the “Build directory:“ click the “Browse“ button and select either the folder <install_directory>/cs545-lab/prog/naoUser/x86_64/ (for non-Mac users) or <install_directory>/cs545-lab/prog/naoUser/x86_64mac/ (for Mac users), and then click the “Open“ button. Click “Next“ button, and you will be in “Run CMake“ window. Click “Run CMake“ button. There should be no errors if everything was done correctly. Then finally click the “Finish“ button.
  2. Eclipse IDE
    • Please download latest version of Eclipse here:
    • Follow Eclipse IDE installation instruction, for example from here: (from USC's CSCI402 - Operating Systems class)
    • To add the xnao project to your installed Eclipse:
      • Open Eclipse
      • Select File => New => Makefile Project with Existing Code => on the “Existing Code Location”, click “Browse” => browse to inside the directory .../cs545-lab/ and click “OK” => on the “Toolchain for Indexer Settings”, select “Linux GCC” (or its equivalent Toolchain in Mac OS) => click “Finish” or “OK”

You are all set! Now, if you want to see the definition of a variable or a function or a procedure (either in Qt Creator IDE or in Eclipse IDE), you can simply move your mouse pointer over the variable/function/procedure of interest, hold <CTRL> button, and do <left-click> on your mouse.

How to Debug Your Codes in xnao (using GDB from a terminal)

For debugging your program in xnao using GDB (from a terminal), please see the following instructions:

  1. Install GDB: sudo apt-get install gdb (for Ubuntu; please look for a similar command on Mac)
  2. Download the following script file xtask_debug and put it in <install_directory>/cs545-lab/prog/naoUser/ directory.
  3. From a terminal, go to <install_directory>/cs545-lab/prog/naoUser/ directory: cd $PROG_ROOT/naoUser
  4. Change the xtask_debug script file rights to executable: sudo chmod +x xtask_debug
  5. From the terminal, run/execute the script: ./xtask_debug (all processes except xtask will run by the script execution)
  6. From the terminal, run GDB on xtask: gdb xtask
  7. Set breakpoint, such as: (gdb) break min_jerk_task.cpp:init_min_jerk_task()
  8. Run xtask inside GDB: (gdb) run (xtask will run inside GDB)
  9. You can troubleshoot in GDB as usual...

Understanding How an SL Task is Working

Please watch the lecture SL Lecture Video Recording. Also please particularly check the diagram of SL task switching here: on page 24. Then please try to answer the following questions yourself:

To answer these questions, please also try modifying some part of the code, re-compiling, and testing it.

Adding a New Task into SL/xnao

Please follow these steps in order to add a new task to be executed into xnao:

  1. Suppose you have a task file named min_jerk_task.cpp, then please execute this command: cd <install_directory>/cs545-lab/prog/naoUser/src/
  2. Edit the file CMakeLists.txt, for example using nano (or vim): nano CMakeLists.txt
    • Search for a line inside CMakeLists.txt which says
      • set(SRCS_XTASK
    • Add a new line before the closing parentheses, and type on the line min_jerk_task.cpp, such that it looks like:
      • ...
      • set(SRCS_XTASK
      • ...
      • min_jerk_task.cpp
      • )
      • ...
    • Save and close the file.
  3. Edit the file initUserTasks.c, for example using nano (or vim): nano initUserTasks.c
    • Search for the following line inside initUserTasks.c which says
      • extern void add_sample_task();
    • Add a new line exactly below it, such that it looks like:
      • ...
      • extern void add_sample_task();
      • extern void add_min_jerk_task();
      • ...
    • Search for the following line inside initUserTasks.c which says
      • add_sample_task();
    • Add a new line exactly below it, such that it looks like:
      • ...
      • add_sample_task();
      • add_min_jerk_task();
      • ...
    • Save and close the file.
  4. Go to directory <install_directory>/cs545-lab/prog/naoUser/ by executing: cd <install_directory>/cs545-lab/prog/naoUser/
  5. Remove the x86_64 or x86_64mac folder by executing: rm -rf x86_*
  6. Recompile, by executing: make -s install
  7. While executing xnao, inside nao.task window, you can type setTask or st, and you should see the Min Jerk Task listed there.

Setting Data-Saving Duration

To set the data-saving duration:

  1. Open the file <install_directory>/cs545-lab/prog/naoUser/prefs/default_script
  2. Set the desired duration to the right of task_default_sampling_time_sec, for example if you want to set the data-saving duration to 8 seconds, then modify the line into task_default_sampling_time_sec 8

Then, to save the data:

  1. In nao.task, type st, then select the task you want to run.
  2. Fill up the task parameters, if any, and execute the task.
  3. After the Nao start executing the task, type scd (abbreviation of "start collect data").
  4. Wait for 8 seconds (the duration of data-saving that you set above, inside the default_script file), nao.task will print out "time=7.990 : buffer is full", then type saveData, and the data file will be dumped inside <install_directory>/cs545-lab/prog/naoUser/ directory.

Lab Sessions Procedure

At every lab session, each team using the NAO robot is required to run the Tai-Chi Chuan dance on Choregraphe, once at the beginning of the session (before doing anything with the robot) and once at the end of the session (before the team members go home). If the robot falls when doing such dance or if any abnormalities are observed on the robot behavior, the team members need to report it to the Lab TA in charge.

Checklists/Notes for/before Running Your Codes on xrnao

You will be dealing with NAO robot(s), which costs $10,000 EACH, so please be careful, and pay attention to the following information:

  1. Make sure your code runs well first on xnao, before running it on the xrnao!!! If it does NOT work on the xnao simulator, DO NOT even try it on the real robot/xrnao!
  2. Verify that your code is real-time safe, i.e. there is no commands that could violate real-time safety, before testing it on the robot. For the list of commands which are forbidden to be called from inside a run_<task_name>(), please see the Real-Time Safety (especially for xrnao) section below.
  3. Only connect by ethernet/network cable!!! WiFi connection is forbidden!!! Please see Setting Wired Network Connection on Ubuntu (for xrnao, Connection with the REAL NAO Robot) section below.
  4. Be careful when first booting up/turning on the robot, watch the robot carefully before the robot actually say something (which means the boot up is successful); sometimes the robot will try to stand up, and then suddenly its joints become very compliant, and as a result, the robot will fall to the back (this is still a bug in the program that is yet to be fixed, but it happens pretty rarely, and you need to watch this out). Get your hands ready to catch the robot before it falls to the ground, if this happens!!!
  5. Steps for testing your program on xrnao: xrnao => <enter IP address that the robot mentioned when pushing its chest button once> => go0 => st => <select and run the task that you want to test on the robot>
  6. Steps for stopping/terminating the robot and xrnao: Once you finished running your program, the team members have to protect the robot while another team member is running the following commands in the task servo (cyan) window : freeze or f => go0. After running go0, the robot should go to the default posture. Before closing the xrnao windows by doing CTRL+C, you have to make sure the robot is STANDING STILL in the default posture (i.e. NO MORE MOVEMENTS on the robot, otherwise the robot will lose control and fall to the ground).
  7. At least 2 members of each group must present in order to be able to use the robot during any lab session. The reasoning is as follows: while one person is sending command to the robot from a laptop, the other person must watch if something wrong is happening on the robot (for example if the robot is about to fall), and be ready to catch the robot. Of course the more members of the group present, the better, in the hope that faster response could be given if the robot is about to fall/in danger.
  8. If the robot's motion is jerky/non-smooth:
    • Stop any task running on the robot, by pressing f on the cyan window
    • Terminate SL (CTRL+C on one of the window) on your computer
    • Disconnect the ethernet wire from the robot's back of its head
    • Reconnect the ethernet wire and try xrnao again
  9. In any case of emergency:
    • Try to push the robot's chest button TWICE (quick push and pull, not a holding push), to stop the robot from doing whatever it currently does
    • If still not stopping, do a force shutdown of the robot, by pushing-and-holding the robot's chest button for about 3-5 seconds.
    • Terminate SL (CTRL+C on one of the window) on your computer
    • Disconnect the ethernet wire from the robot's back of its head
  10. To shutdown (normally) the NAO robot:
    • FIRST: Terminate SL (CTRL+C on one of the window) on your computer
    • Push and hold the robot's chest button for about 3-5 seconds.

Real-Time Safety (especially for xrnao)

The following commands are forbidden to be called from inside a run_<task_name>() :

  1. printf()
  2. std::cout
  3. my_vector(), my_matrix(), etc. from cs545-lab/prog_root/utilities/src/utility.c (these are memory allocation routines, similar to malloc() in C programming language)
  4. my_free_vector(), my_free_matrix(), etc. from cs545-lab/prog_root/utilities/src/utility.c (these are memory de-allocation routines)

If you call them from inside the run_<task_name>(), you are in risk of damaging the robot, because of violation to real-time safety. However, the above commands are allowed to be called from inside the init_<task_name>() . Matrix-vector mathematical operation commands, like mat_vec_mult(), mat_mult_transpose_normal(), mat_mult_size(), etc. are allowed to be called from the run_<task_name>() .

Setting Ethernet/Wired Network Connection on Ubuntu (for Choregraphe and xrnao, Connection with the REAL NAO Robot)

For connecting with the real NAO robot via Choregraphe or xrnao, you will need a wired network connection between your computer and the robot. To make sure the wired connection is successful on Ubuntu 12.04 LTS or 14.04 LTS (<Ethernet_Port_Name> is the name appeared when executing the command ifconfig -a and marked with Link encap:Ethernet beside of lo and wlan0; usually it is eth0):

Ubuntu 12.04 LTS (well-tested)

are in your /etc/network/interfaces file (you can edit it by the command: sudo nano /etc/network/interfaces). Here is an example of the complete file: Ubuntu Network Interface Setting File
If a setting is already exist for <Ethernet_Port_Name>, please modify the setting for <Ethernet_Port_Name> to be like the above 2 lines.

Ubuntu 14.04 LTS (well-tested) or Ubuntu 16.04 LTS (NOT well-tested, might NOT work for non-on-board Ethernet port connection, i.e. if using USB-to-Ethernet adapter)

are in your /etc/network/interfaces file (you can edit it by the command: sudo nano /etc/network/interfaces ). Here is an example of the complete file: Ubuntu Network Interface Setting File
If a setting is already exist for <Ethernet_Port_Name>, please modify the setting for <Ethernet_Port_Name> to be like the above 2 lines.
at one line above the line:
After some moments, the <Ethernet_Port_Name>:avahi will appear when ifconfig -a is commanded, and you are ready to go.

After you made the above change(s), you need to reboot to make sure the configuration is loaded by your OS. After reboot, you might try to ping other computer with a similar network settings to see if the wired connection is working now (should be 100% success transmission rate when you ping).

Linear Algebra (Matrix-Vector Mathematical Operation) Commands

These commands, such as mat_vec_mult(), mat_mult_transpose_normal(), mat_mult_size(), etc. are available in cs545-lab/prog_root/utilities/src/utility.c

Getting delta_t or dt from inside a Task File (*.cpp/*.c)

In a task file, for example <install_directory>/cs545-lab/prog/naoUser/src/min_jerk_task.cpp, you can get the delta_t (or dt) by calling the following:

from inside an init_<task_name>() (e.g. init_min_jerk_task()) or inside a run_<task_name>() (e.g. run_min_jerk_task()).

(task_servo_rate is a global variable in SL, which is different from one robot to another...)


Ubuntu Installation alongside with existing Windows OS: Dual Boot Ubuntu-Windows OS (Recommended)

(Note: This is just added here to help you, and we provide no guarantees. Follow at your own risk. Be extremely careful while following the steps and options. As a precaution, it is highly suggested to backup all important data files from your Windows OS system to an external harddrive, before proceeding with the following installation steps.)
Recommended (Tested) Ubuntu OS version: Ubuntu 12.04 LTS (Long Term Support) 32-bit or 64-bit (depending on your computer)
Suppose currently you have an existing Windows OS installed on your laptop, here are the steps to install a Dual Boot Ubuntu-Windows OS:

  1. Create an Ubuntu-bootable USB Flashdisk/Stick (this way on step 2 below you do not need to burn the Ubuntu OS' ISO image onto a DVD), follow the instructions here:
  2. Install the Ubuntu OS, following the tutorial or .
  3. Sometimes, there is an issue that you cannot boot to Windows after installing Ubuntu, but do not panic! This does not mean that your Windows OS is gone, it is just that the boot pathway to Windows was not found. Here is how to fix it:

If you are totally new to Linux or Ubuntu, here are the rule of thumb, when you do something, you really need to know what you are doing (or at least get a rough idea of it). Unlike in Windows, where you can simply click Install Updates and everything will be done for you with almost 100% success rate, in Ubuntu installing updates is a risky thing. Hence never install updates, unless you really know what is it about.


Retrieved from
Page last modified on February 08, 2018, at 03:22 PM