Webots is used to simulate the work of the different kind of robots. We’re interested in the module for NAO simulation specifically.
Installation:
- Download Webots: https://www.cyberbotics.com/download
- Create an account here: https://www.cyberbotics.com/register
- Activate trial license after the registration. To do this, click at the corresponding button on the profile page: https://www.cyberbotics.com/my_account/profile
- Once the program is installed, enter login and password of the account you’ve just created and agree to upload modules when offered.
Choregraphe Suite And Python SDK Installation
Choregraphe suite is a quite convenient development environment, designed for the NAO visual programming. It is really useful, when getting acquainted with the robot’s basic features and creating small programs for it. For the real programming, however, we’ll be using NaoQi Python SDK.
- Create an Aldebaran account: https://store.aldebaran.com/default/customer/account/create/
- Register in the developers program: https://community.aldebaran.com/en/developerprogram#section3. Please do not forget to specify you are going to use Python, so that needed SDK is available.
- Upload the Choregraphe suite and Python SDK on the Resources page: https://community.aldebaran.com/en/resources/software/language/en-gb/robot/nao-2
- Upload Python 2.7 x86 https://www.python.org/downloads/windows/
- Set the Choregraphe suite and Python SDK. When requested the license key, enter the one, which you received by mail when registered in the developers program.
- In the Python console check ifwhether the SDK was successfully installed: type “import naoqi". If error doesn’t appear, it means NaoQi SDK was installed correctly.
Baby, I can dance
Now, lets get started. Run Webots then go to File -> Open Sample World. Select robots -> aldebaran -> nao.wbt. Please make sure simulation works and timer runs, as shown on the screen below:
You can try to orient in space in rendering window right away. As for me, controls are not really convenient:
- • to rotate the camera around the selected object you should press hold the right mouse button;
- • to move right-left, up and down you should press and hold the left mouse button;
- • to zoom and rotate right-left – press and hold the mouse wheel;
- • when you’re scrolling with mouse wheel, zooms really slow, while holding the mouse wheel zooms really fast.
I suppose you can get used to it, but not in a couple of days.
Then you should start the Choregraphe, and create the project. In the created project connect to the Webots, using the Connect to button, as shown on the screen below:
Now you can build a simple project — add the “Tai Chi Chuan" dance block and connect it to the input and output. You can look at Video Monitor to ensure robot’s camera from the Webots simulations is shown there, as seen on the screen below.
Now we can run out small project and can look at dancing NAO in Webots.
After that it makes sence to experiment with Choregraphe — to build an interesting project using existing blocks or create something new,зібра by adding Python Script block. What is more you can export your Choregraphe project and share it with your friends. This is a great environment for the experiments and the only thing you’re limited to is your imagination.
Mute Webots
There are two features Webots is sorely lacking: voice recognition module (unfortunately, the simulator doesn’t have the “ALSpeechRecognition" module) and displaying what NAO is saying at the moment (fortunately, перуку is a workaround to do that).
It is possible to use Monitor program, which was included to the Choregraphe package. There you should click at Load Plugin -> logviewermonitor. If you select Log Level: Info, you’ll be able to see what NAO had said in the logs with ease. As an example you can see the one-block (“Animated Say") Choregraphe project’s execution log, shown on the screenshot below:
From the log on the screenshot above you can see, that NAO says “Hello".
First Steps
Now we finally can get to business and write some code. Open our beloved Python IDE or the console and execute following (Please note, Webots should be run, simulation should work):
import naoqi
host = "localhost"
port = 9559
postureProxy = naoqi.ALProxy("ALRobotPosture", host, port)
postureProxy.goToPosture("StandInit", 1)
motionProxy = naoqi.ALProxy("ALMotion", host, port)
motionProxy.moveTo(1.0, 0.0, 0.0)
Ater doing so, in the Webots we can see NAO walking a meter forward.
To simplify the example, host and port were hardcoded, as well as parameters, which call moveTo.
To make robot perform certain actions in Python SDK, module’s local proxy is used. When executing naoqi.ALProxy(“ALMotion", host, port) the object is created. This object’s method calls are delegated to the real module ALMotion, which is executed in the robot. This allows code to be executed on the robot and server sides at the same time.
In this example we’ve moved NAO to it’s standard position after initialization using postureProxy.goToPosture(“StandInit", 1). After that we’ve moved him one meter forward using the motionProxy.moveTo(1.0, 0.0, 0.0).
Now we’d like NAO to move his head and speak while walking
import naoqi
host = "localhost"
port = 9559
postureProxy = naoqi.ALProxy("ALRobotPosture", host, port)
postureProxy.goToPosture("StandInit", 1)
motionProxy = naoqi.ALProxy("ALMotion", host, port)
motionProxy.post.moveTo(1.0, 0.0, 0.0)
textToSpeechProxy = naoqi.ALProxy("ALTextToSpeech", host, port)
textToSpeechProxy.post.say("I'm walking and moving my head")
jointNames = ["HeadYaw", "HeadPitch"]
angles = [[1, 0.5, 0, -0.5, -1.0], [0.5, 0.25, 0, -0.25, -0.5]]
times = [range(1, 6), range(4, 9)]
motionProxy.angleInterpolation(jointNames, angles, times, False)
motionProxy.stopMove()
Firstly, as in the previous example, we’ve initialized the robot and moved it one meter forward. But here, instead of calling moveTo on the motionProxy object, the method is called on it’s the post field. It means method moveTo is executed asynchronously in another thread and program execution will continue, while robot is moving.
Than we’re asynchronously calling module’s ALTextToSpeech say method. After its execution NAO will start saying “I’m walking and moving my head".
After that we’re synchronously executing module’s motionProxy angleInterpolation method. In this metod we’re setting the engines’ names for which we’re setting the rotation angles, the rotation angles themselves and the time, then egine should rotate. For instance, in one second the “HeadYaw" rotaion angle will be equal to 1. In two seconds — 0.5 and so on.
Using this scheme quite complex animation can be created, although this will require some hard work. To do stuff like this it is better to have the real robot or, at least, to use the Choregraphe animation module.
Sometimes, when the simulation is started, Webots does not respond, even if it is only initialization. In this case, first thing you should do is stop the simulation and check whether the naoqi-bin process is running. If it is — stop it. Sometimes it runs by itself:
So you can imagine what is NAO, what it is capable of and start developing software for it. Official documentation can be really helpful:
You can learm more about NAO’s software development basic concepts: http://doc.aldebaran.com/2-1/dev/naoqi/index.html — this article is necessary to understand the way everything works.
API Description: http://doc.aldebaran.com/2-1/naoqi/index.html
Python tutorials: http://doc.aldebaran.com/2-1/dev/python/tutorials.html
Python Examples: http://doc.aldebaran.com/2-1/dev/python/examples.html — here you can find a lot of different exemples, which will help you to get more general understanding of how everything works.