SoftBank Robotics documentation What's new in NAOqi 2.5?

Hello World 2 - using Python in Choregraphe

Audience

Level All beginners Time 5 min
OS Linux - Windows - Mac Preparation 15 min

Preparation time is given for the case you have to install tools prior the tutorial.

Before starting

Let’s do it

Step Action
Start Choregraphe.

Click the Connect to button and connect Choregraphe to your robot.

../_images/helloworld_cho_00.png

For further details, see How to connect your NAO.

Your robot appears in the Robot view.

Right click the grey area and choose Create a new Box > Python... in the contextual menu.

../_images/helloworld_cho_py_00.png

Type a name, for example: My hello world, and click the OK button.

../_images/helloworld_cho_py_01.png

Double click the box.

The Script editor appears.

../_images/helloworld_cho_py_02.png

Add the 2 following lines:

After:

def __init__(self):
   GeneratedClass.__init__(self)

Add:

self.tts = ALProxy('ALTextToSpeech')

After:

def onInput_onStart(self):
    #~ self.onStopped() #~ activate output of the box

Add:

self.tts.say("Hello young Padawan")

The Script should look like this.

../_images/helloworld_cho_py_03.png

Click the Play button.

../_images/helloworld_cho_py_04.png

Double click the onStart input of your box.

../_images/helloworld_cho_py_05.png

Result

Your robot says “Hello, young Padawan”. In the meantime, the Robot view displays the message.

How it works

This script uses the say method of the ALTextToSpeech module. ALTextToSpeech is the module of NAoqi dedicated to speech. The say method makes the robot pronounce the string given in parameter.
For further details about this module, see ALTextToSpeech.

Let’s explain the 2 lines you wrote:

self.tts = ALProxy('ALTextToSpeech')

This line creates an object, called tts.

  • self is there to make sure tts will be available not only locally, but in all the code blocks of the script.
  • tts is the name we gave to the object instance (could have been myspeechmodule or speakingmodule).
  • ALProxy() is a class of objects, allowing you to have acces to all the methods of a module.
  • ALTextToSpeech is the name of the module of NAOqi we want to use.
self.tts.say("Hello young Padawan")

This line uses the object tts to send an instruction to the NAOqi module.

  • self.tts is the object we use.
  • say() is the method.
  • “Hello young Padawan” is the parameter.

What you have learned

To make the robot do something, you have to:

  1. Create an object giving access to one of the NAOqi modules, then
  2. call one of its available methods.

You can manually start the execution of a box by double-clicking on its on Start input.

To go further

Next step

What about creating your first dialog topic?
Try to create Dialog using Choregraphe editor: Hello World 3 - using Dialog topic in Choregraphe.