Robohub.org
 

Python programming your NAO robot


by
09 February 2017



share this:

These videos aim to teach you how to begin programming your NAO with Python. The NAO can be programmed using several programming languages, including C++, MATLAB, JAVA, LabVIEW and Python. Instead of using the drag and drop boxes in the Choreograph, we’re going to get our NAO robot walking and talking using coding.

Tutorial 1: Speech

Helpful hints:

Follow these steps to create a box that we could put our python code into, and have our robot speak: “Hello”. “Hello I am a robot”.

  1. Right click the main section box and go to “add new box”
  2. Create a name for the box
  3. Input main image
  4. Select the type of box

Now we’re having a look at the script. Go into the scripts and click ok. And there we have our NAO little box. If we click into it, we have the python code. What we are going to do is change some of the codes to get our robot to speak.

  1. Double click the box
  2. Select the piece of code you need to alter to get our robot to speak(“def onInput_onStart(self)”)
  3. Take out the pass section
  4. Type in “ttsproxy = ALProxy(“ALTextToSpeech”)”. (Make sure you get the comment in there).
  5. Underneath that, we are going to put “ttsproxy.say” and add the comment “Hello, I am a robot”.

The first line could create an object that gives us access to the robot’s text to speech capabilities. This object is assigned to the variable ttsProxy. We can access the object later through the name ttsProxy. I am going to mount the top line, and the alspeech is there. The second line calls a different function site. This function takes an argument “Hello, I am a robot” and then he uses a string or sequence of characters between two double quoted marks. The robot will speak the string that will pass to the say message aloud.  There are your simple first steps into python and choreograph.

You can now, hopefully, get your NAO robot to talk by using your python programming skills. Now have a play with it’s behavior to see if you can get your NAO to say a longer sentence, or maybe even sing a song. Have a play, and use your imagination!


Tutorial 2: Walking

Helpful hints:

No we’re going get your robot to walk using Python. The NAO can be program to walk to any point using the in-build Python Programming Language instead of using the drag and drop boxes in the choregraphe. Python is more expressive and allows you to do things like computing trigonometric calculations on the robot.

  1. Right click the main section box and go to “add new box”
  2. Create a name for the box
  3. Input main image
  4. Select the type of box

First, we want our robot to stand up. Drag a stand up icon into the box. I am actually using the NAO key so the 3D robot in the robot view, and this because we need to put the robot on connecting so we can see what’s going on quite clearly. Oversee when you are using this on the real robot and never forget to trigger on the motors and connect everything up properly.

Open the Code Box

  1. Go to “def onInput_onStart(self):”
  2. Write “motionProxy = ALProxy(“ALMotion”)”
  3. On the next line write “walkTo(0.2,0.0,0.0)”
  4. End it with “self.onStopped()”

The first line is a proxy called ALmotion, which what is we created here, which allows us to call the motion functions up. The second line is the walkTo, which moves the robot to a specific distance. Now, look on the decimal places: see that .2 is X and Y and the radius, so he’s going to move .2 forward. Then if I start playing with the other numbers here, he’ll move to the Y radius and then to the other turning point as well. The final bit is the self.on. To stop this, we will call and tell the choregraphe to stop the procedure when it is at the end and just simple loop and loop and loop.

If we are good, we should see this now on the 3D NAO. So if I hit play, we can see it walking along. Well done guys, you can now get your NAO Robot to walk by using
your Python programming skills. Tread carefully!


If you liked this article, you may also enjoy these:

See all the latest robotics news on Robohub, or sign up for our weekly newsletter.



tags: , , , , , , , , , ,


Philip English (aka "Robo-Phil) spends his days going to Robotics conventions, reviewing the latest Robots, interviewing Industry experts and trawling the internet for exciting news...
Philip English (aka "Robo-Phil) spends his days going to Robotics conventions, reviewing the latest Robots, interviewing Industry experts and trawling the internet for exciting news...





Related posts :



Robot Talk Episode 115 – Robot dogs working in industry, with Benjamin Mottis

  28 Mar 2025
In the latest episode of the Robot Talk podcast, Claire chatted to Benjamin Mottis from ANYbotics about deploying their four-legged ANYmal robot in a variety of industries.

Robot Talk Episode 114 – Reducing waste with robotics, with Josie Gotz

  21 Mar 2025
In the latest episode of the Robot Talk podcast, Claire chatted to Josie Gotz from the Manufacturing Technology Centre about robotics for material recovery, reuse and recycling.

Robot Talk Episode 113 – Soft robotic hands, with Kaspar Althoefer

  14 Mar 2025
In the latest episode of the Robot Talk podcast, Claire chatted to Kaspar Althoefer from Queen Mary University of London about soft robotic manipulators for healthcare and manufacturing.

Robot Talk Episode 112 – Getting creative with robotics, with Vali Lalioti

  07 Mar 2025
In the latest episode of the Robot Talk podcast, Claire chatted to Vali Lalioti from the University of the Arts London about how art, culture and robotics interact.

Robot Talk Episode 111 – Robots for climate action, with Patrick Meier

  28 Feb 2025
In the latest episode of the Robot Talk podcast, Claire chatted to Patrick Meier from the Climate Robotics Network about how robots can help scale action on climate change.

Robot Talk Episode 110 – Designing ethical robots, with Catherine Menon

  21 Feb 2025
In the latest episode of the Robot Talk podcast, Claire chatted to Catherine Menon from the University of Hertfordshire about designing home assistance robots with ethics in mind.

Robot Talk Episode 109 – Building robots at home, with Dan Nicholson

  14 Feb 2025
In the latest episode of the Robot Talk podcast, Claire chatted to Dan Nicholson from MakerForge.tech about creating open source robotics projects you can do at home.

Robot Talk Episode 108 – Giving robots the sense of touch, with Anuradha Ranasinghe

  07 Feb 2025
In the latest episode of the Robot Talk podcast, Claire chatted to Anuradha Ranasinghe from Liverpool Hope University about haptic sensors for wearable tech and robotics.





Robohub is supported by:




Would you like to learn how to tell impactful stories about your robot or AI system?


scicomm
training the next generation of science communicators in robotics & AI


©2024 - Association for the Understanding of Artificial Intelligence


 












©2021 - ROBOTS Association