8.2 Using the Nao robot
8.2.1 Introduction
The Nao robot is a humanoid robot developed by Aldebaran Robotics. This section explains how to use Nao robot simulated in Webots together with the Choregraphe program of Aldebaran Robotics. Currently Webots supports four different models of the Nao robot: the H21 V3.3, the H21 V4.0, the H25 V3.3 and the H25 V4.0.
The Webots installation includes several world files with Nao robots. You will find some in this folder: WEBOTS_HOME/projects/robots/nao/worlds. The nao.wbt and nao_indoors.wbt are meant to be used with Choregraphe (see below). The nao_demo.wbt is a demonstration of a very simple controller that uses Webots C API instead of Choregraphe. The nao2_matlab.wbt world is an example of programming Webots using the Matlab API.
In addition Nao robots are also used in the world files of the Robotstadium contest. These files are located in this folder: WEBOTS_HOME/projects/contests/robotstadium/worlds.
8.2.2 Using Webots with Choregraphe
These instructions have been tested with Webots 7.0.0 and Choregraphe 1.14.x.x.
Start Webots and open this world file: WEBOTS_HOME/projects/robots/nao/worlds/nao.wbt You should see a orange Nao H25 V4.0 in an empty environment. If the simulation is stopped, then please start it by pushing the Real-time button in Webots.
When the simulation starts the robot should move down slightly until its feet reach the floor. The Nao was initially in "Zero" pose, its should have moved to the "Init" pose. If the nao robot did not move, this is probably due to a problem with the "naoqisim" controller. The camera images in Webots (small purple viewports) should reflect what the robot sees.
A bunch of text information should be printed to Webots console, e.g. :
[naoqisim] ===== starting naoqisim controller ===== |
The message "NAOqi is ready..." appears in the console, to indicate that NAOqi was started correctly.
Now you can start Choregraphe. Please make sure the Choregraphe version matches the NAOqi version printed in Webots console. In Choregraphe choose the menu Connection > Connect to.... Then in the list, select the NAOqi that was started by Webots, on you local machine, it will have the port number 9559, unless you change it. Note that the NAOqi will not appear in the list if the simulation was not started in Webots.
At this point a Nao model matching the Webots model should appear in Choregraphe. The Nao in Choregraphe and Webots should both have the same pose: the "Init" pose. Now, in Choregraphe toggle the "Enslave all motors on/off" button; it should turn red.
Then double-click on any of the Nao parts in Choregraphe: a small window with control sliders appears. Now, move any of the sliders: the motor movement in Choregraphe should be reflected in the Webots simulation. If you open the Video monitor in Choregraphe you should see the picture of the Nao camera simulated by Webots.
8.2.3 Using motion boxes
Now we can test some of the motion boxes of Choregraphe. We want to see if it is possible to make the robot stand up from from the floor. In Choregraphe, select the "Stand Up" box from Box libraries > default. Drag and drop that box in central view. Then connect the global "onStart" input to the "Stand Up" box's "onStart" input. Now, make the robot fall in Webots: use the right-mouse-button while the shift key is down, and rotate the mouse, this makes the robot rotate on one axis axis. Quickly release and press again the shift to change the rotation axis. Now make sure the simulation is running, push Real-time in Webots if necessary: the robot should fall. Once the robot is lying on the floor, push the Play button in Choregraphe. This starts the Choregraphe "Stand Up" box and the robot should now try to stand up, using its hands. In order to stand up the Choregraphe program should select the most appropriate motion sequence according to Nao's initial situation.
8.2.4 Using the cameras
Webots simulates Nao's top and bottom cameras. Using Aldebaran's Choregraphe or the Monitor programs, it is possible to switch between these cameras. In Choregraphe, use the "Select Camera" box in Box Library > Vision. The simulated camera image can be viewed in Choregraphe: View > Video monitor. The resolution of the image capture can be changed in Webots using the cameraWidth and cameraHeight fields of the robot. Note that the simulation speed decreases as the resolution increases. It is possible to hide the camera viewports (purple frame) in Webots, by setting the cameraPixelSize field to 0. It is also possible to completely switch off the simulation of the cameras by adding the "-nocam" option before the NAOqi port number in the controllerArgs field, e.g. "-nocam 9559".
8.2.5 Using Several Nao robots
It is possible to have several Nao robots in your simulation, however each Nao robot must use a different NAOqi port. Here how to copy a Nao and assign the NAOqi port number:
-
Stop the simulation: push the Stop button in Webots 3D View
-
Revert the simulation: push the Revert button in Webots 3D View
-
In Webots Scene Tree, select a top level nodes, e.g. the Nao robot
-
Then push the Add New button, a dialog appears
-
In the dialog, select PROTO (Webots) > robots
-
Then select one of the Nao models from the list, the Nao is added to the current world
-
Select the Nao in the 3D view and move it away from the other one: SHIFT + left mouse button
-
Select the controllerArgs field in the newly created robot and increase the port number, e.g. 9560
-
Save the .wbt file: push the Save button
-
Now you can push the Real-time button to run the simulation with several robots
Repeat the above procedure for each additional robot that you need. Remember that every robot must have a different port number specified in controllerArgs.
8.2.6 Getting the right speed for realistic simulation
Choregraphe uses exclusively real-time and so the robot's motions are meant to be carried out in real-time. The Webots simulator uses a virtual time base that can be faster or slower than real-time, depending on the CPU and GPU power of the host computer. If the CPU and GPU are powerful enough, Webots can keep up with real-time, in this case the speed indicator in Webots shows approximately 1.0x, otherwise the speed indicator goes below 1.0x. Choregraphe's motions will play accurately only if Webots simulation speed is around 1.0x. When Webots simulation speed drifts away from 1.0x, the physics simulation gets wrong (unatural) and thus Choregraphe motions don't work as expected anymore. For example if Webots indicates 0.5x, this means that it is only able to simulate at half real-time the motion provided by Choregraphe: the physics simulation is too slow. Therefore it is important to keep the simulation speed as much as possible close to 1.0x. There is currently no means of synchronizing Webots and Choregraphe, but this problem will be addressed in a future release. It is often possible to prevent the simulation speed from going below 1.0x, by keeping the CPU and GPU load as low as possible. There are several ways to do that, here are the most effective ones:
-
Switch off the simulation of the Nao cameras with the "-nocam" option, as mentioned above
-
Increase the value of WorldInfo.displayRefesh in the Scene Tree
-
Switch off the rendering of the shadows: change to FALSE the castShadows field of each light source in the Scene Tree
-
Reduce the dimensions of the 3D view in Webots, by manually resizing the GUI components
-
Remove unnecessary objects from the simulation, in particular objects with physics
8.2.7 Known Problems
If for some unexpected reason Webots crashes, it is possible that the hal or naoqi-bin processes remain active in memory. In this case we recommend you to terminate these processes manually before restarting Webots.
On Windows, use the Task Manager (the Task Manager can be started by pressing Ctrl-Alt-Delete): In the Task Manager select the Processes tab, then select each hal.exe and naoqi-bin.exe line and push the "End Process" button for each one.
On Linux, you can use the killall or the pkill commands, e.g.:
$ killall hal naoqi-bin |
8.2.8 Source Code
The interface between Choregraphe and Nao is implemented as a special Webots controller called "naoqisim". The "naoqisim" controller comes precompiled with each Webots distribution. However, the source code of "naoqisim" is distributed with Webots EDU and Webots PRO. The "naoqisim" source code is located in: WEBOTS_HOME/resources/projects/robots/nao/controllers/naoqisim. Webots users can modify the source code and recompile "naoqisim" if necessary. If you make useful improvements to this project please drop a message to Webots developers so that they can incorporate your changes in future versions.