Chapter 25

 25.1 Introduction
 25.2 Starting up
 25.3 Accessing joints
  25.3.1 Advanced parameters
 25.4 Leds
 25.5 Camera
  25.5.1 Slots
 25.6 Whole body motion
 25.7 Other sensors
 25.8 Interfacing with NaoQi
  25.8.1 Accessing the NaoQi shared memory region
  25.8.2 Accessing standard NaoQi modules
  25.8.3 Binding new NaoQi modules in Urbi
  25.8.4 Writing NaoQi modules in Urbi

25.1 Introduction

The Nao is a 60 centimeters tall humanoid robot built by Aldebaran Robotics. It has an onboard Geode processor running Linux, 25 degrees of freedom, two onboard cameras, speakers, microphones, accelerometers, ultrasound and IR sensors...

25.2 Starting up

Nao comes with an installed version of Urbi.

On some versions of Nao, Urbi is not automatically started upon start-up. If this is the case, you must take the following steps to activate Urbi:

Those lines might already be present but commented out.

You should be able to connect to your Nao on the port 54000 and send it urbiscript:

tts.say("Hello, I am Nao."), 
// Activate right arm. 
armR.load = 1; 
// Wave the arm: put it in position 
shoulderRollR.val = -0.3 time: 0.5s | 
shoulderPitchR.val = -1 speed: 0.9 | 
// Wave it 
timeout(6s) shoulderRollR.val = -0.4 sin:2s ampli:0.4; 
// And put it back down, using the uncompressed name this time 
robot.body.arm[right].shoulder.pitch.val = 2 speed:0.9; 
// Activate all motors. 
// Stand 
// Start walking... 
tag: robot.walk(1), 
// ... and interrupt the movement 
sleep(2s) | tag.stop; 
// Get the list of all devices and the interfaces they implement: 

25.3 Accessing joints

All the Nao joints are accessible through their standard Nao and Urbi names, and respect the Urbi standard specifications for servo motors: Basically each motor has a load field that is linked to the motor stiffness, and a val field that can be used to read or write the motor position.

Some motor groups are also provided: they can be used exactly as joints, but any action performed on a group is sent to all the joints that are a member of this group.

// Activate all motors 
motors.load = 1; 
// Or only all the head motors 
head.load = 1; 
// Move headYaw to 0.8 in one seconds. Since this commands takes 
// one second to execute, terminate with a comma to be able 
// to send other commands while it executes. 
headYaw.val = 0.8 time: 1s, 
// Move headPitch to -0.5 as fast as possible. 
headPitch.val = -0.5; 
// Move headYaw continuously in a sinusoidal trajectory... 
tag: headYaw.val = 0 sin:2s ampli:0.5, 
// ...and stop the movement 

The two hands are purposefully not included in the ’motors’ group. Although you can control them using the val slot, it is recommended that you use the open() and close() methods, since they stop the motors once the movement is finished.

25.3.1 Advanced parameters Trajectory generator period

The trajectory generators will issue write command at a period given by the System.period variable. The default is 10ms which is the native period of NaoQi. Motor back-end method

Urbi can use two different methods to send the joint commands: DCM::send(), or ALMotor::setAngle(). The mode can be changed by calling motor.setDCMWrite(bool).

In setAngle() mode, each write operation to a joint will synchronously call the setAngle() NaoQi method.

In DCM mode, Urbi will set a hook on the DCM update, and send all commands in this hook using the send() method. Urbi will send commands S milliseconds in the future. S defaults to 50ms, and can be changed by calling ALMotor.setDCMShift(shiftValue). Motor command debugging

The motors implements a debugging mode that can be activated by calling ALMotor::setTrace(1). While activated, it will write all sent commands to the file ‘/tmp/traj.log’. Each line will contain the motor number, the command timestamp, and the command position. Be careful not to let this feature active while not using it, as it would quickly fill-up the memory.

25.4 Leds

All Nao’s leds and led groups, as defined by NaoQi, are available as objects in urbiscript. You can set the led values by writing to the slots val (intensity between 0 and 1), r, g, b (color intensity between 0 and 1) or rgb (RGB value, one byte each, i.e. 0xFF0000 is red).

25.5 Camera

The Nao camera object is instantiated by default, under the standard name camera. It is deactivated by default, set its load field to 1 to activate. The default framerate is only 4fps, so you might want to increase it before activating the camera.

If you wish to use RTP instead of TCP to receive the camera image, you must:

RTP will then be used automatically.

25.5.1 Slots

25.6 Whole body motion

The whole body motion component of the NaoQi can be activated by reading and writing to the pos slot of both hands. This sets a target position in cartesian space for the hand. The NaoQi will use its whole body to try to reach it. Be careful to only ask for reachable positions.

25.7 Other sensors

The following sensors are available through a urbiscript variable. Reading the variable will give the latest available sensor value.

25.8 Interfacing with NaoQi

25.8.1 Accessing the NaoQi shared memory region

Many NaoQi modules communicate through a shared hash table handled by the ALMemory module. This module is available under the stm name in Urbi, and has the following slots:

25.8.2 Accessing standard NaoQi modules

All standard NaoQi modules (ALMemory, ALLogger, ALMotion, ALFrameManager, ALTextToSpeech, ALAudioPlayer...) are available in Urbi. You can call all their methods directly.

25.8.3 Binding new NaoQi modules in Urbi

You can create a proxy on every NaoQi module, local or remote. The method is similar to what is done in C++, with the addition that all the module’s methods can be directly called without using the meta-call ’call’ method:

// Instantiate a proxy for the ALMotion module. 
var motion = "ALMotion" ); 
// Bind its methods, declaring "waituntilWalkIsFinished" as a long method. 
motion.walkTo( 0.1, 0,0 ); 

The argument to generateALBindings() is a list of all the function names that you want to be asynchronous. You must pass in this list all the functions that takes a long(more than a few milliseconds) time to execute.

Synchronous calls have less overhead, but will freeze the urbiscript interpreter for the duration of the call.

Most of the standard modules are loaded by the initialization script ‘URBI.INI’.

25.8.4 Writing NaoQi modules in Urbi

You can create independent modules capable of answering requests and services from other NaoQi modules, written in C ++, urbiscript or ruby. Let’s see an example:

// ---------------------------------- 
// Simple module creation samples 
// ---------------------------------- 
// the name of your variable and of the module must be the SAME! 
var urbiHelloWorld ="urbiHelloWorld"); 
// create a new method doing some interesting things 
function urbiHelloWorld.sayHello() 
  // Use ALTextToSpeech, instantiated by URBI.INI 
// inform the world that theres a new method, and what its doing 
urbiHelloWorld.bindUrbiMethod("sayHello", "Nao will say Hello", [], []); 
// to test it outside of Urbi, you can for example type in a browser: 
// http://<Naos IP>:9559/?eval=urbiHelloWorld.version(); or 
// http://<Naos IP>:9559/?; and more naturally 
// http://<Naos IP>:9559/?eval=urbiHelloWorld.sayHello(); 
// ---------------------------------- 
// another module example 
// ---------------------------------- 
var mathematics ="mathematics"); 
function mathematics.add(a, b) 
  var res = a + b; 
  echo("mathematics.add => " + res); 
  return res; 
  "A powerful module to make remote computing in urbiscript :)"); 
mathematics.bindUrbiMethod( "add", "Compute the sum of two numbers", 
[["a",   "first number of the addition"], 
 ["b",   "second number of the addition"]], 
 ["sum", "the sum of the addition"] ); 
// to test it outside of urbi, you can for example enter in a browser: 
// http://<Naos IP>:9559/?eval=mathematics.add(2,3)