Hello World 2 - using Python in Choregraphe ¶
|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 ¶
- Make sure you have a robot ready to use. Otherwise, read NAO - Out of the box.
Make sure Choregraphe is installed on your computer.If it is not the case, see Installing Choregraphe suite.
Let’s do it ¶
Click the Connect to button and connect Choregraphe to your robot.
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.
Type a name, for example: My hello world, and click the OK button.
Double click the box.
The Script editor appears.
Add the 2 following lines:
The Script should look like this.
Click the Play button.
Double click the onStart input of your box.
Your robot says “Hello, young Padawan”. In the meantime, the Robot view displays the message.
How it works ¶
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:
- Create an object giving access to one of the NAOqi modules, then
- call one of its available methods.
You can manually start the execution of a box by double-clicking on its on Start input.