COMP4461 Lab4

This repo is the Lab 4 material for UG course COMP4461 Human-Computer Interaction.

View the Project on GitHub

Robot Programming

Lab materials for how to program Pepper with Python.
Venue: Room 4221, Teaching Lab 1, Academic Building.
Date: Nov. 10, 2017

Python naoqi License PRs Welcome

In this lab, we will introduce how to program with Pepper robot by Python.

Table of Contents

Overview

What is NAOqi?

According to the official website, NAOqi is the main software running on the robot. Without NAOqi, the robot cannot perform any behaviors. NAOqi can run on the robot under NAOqi OS distribution, and can also run on your computer in order to test the code on a simulated robot. Here is an overview of all the SDKs.

Configuration

How to install Python?

Before we get started, we need to install Python package on the local machine.

Linux & MAC

For Linux users, you can directly run

sudo apt-get install python-2.7 python-pip

. Otherwise, you may refer to this link to see how to install the latest Python by downloading the install package from the official website.

For Mac users, you can install python by running:

brew install python

to install the latest version of Python 2.7.x.

Windows

First, you need to install Python on your laptop. Please download the .msi file from here. Then install the package in C:\Python27. You may change the path according to your situations. After installing the Python package, please go to My Computer > Properties > Advanced System Settings > Environment Variables. Under System variables, find Path and click the edit button, in the popped out window, add your path (e.g., C:\Python27) of Python directory in the last line. After the installation, you can check the current version of your Python environment by typing

python --version

in CMD. If the feedback is Python 2.7.XX, then you can go to the next step.

How to install NAOqi SDK?

You need a SoftBank Robotics account to get all the installer that you need. Create your account here. After you create the account, sign in and go to this page. Please find the Pepper SDKs and documentation 2.5.5 and download the corresponding SDK based on your operating system.

Linux & MAC

For Linux, please download Python 2.7 SDK 2.5.5 Linux 64; and for Mac, please download Python 2.7 SDK 2.5.5 Mac 64.

In Linux, please go to the folder where you download the file (e.g., ~/Downloads) and unzip the .tar.gz file by

tar -xvzf pynaoqi-python2.7-2.5.5.5-linux64.tar.gz

Then move the folder to your local library by the following command (if you get Permission denied, please add sudo at the beginning of this line of command).

mv -i ./pynaoqi-python2.7-2.5.5.5-linux64 /usr/local/lib/pynaoqi

By doing this, we rename the unzipped folder as pynaoqi and move it in our local environment. Next, go to /usr/local/lib/pynaoqi, then follow the instruction here to set up your local environment. Now your /path/to/python-sdk/lib/python2.7/site-packages should be /usr/local/lib/pynaoqi/lib/python2.7/site-packages Then type

export PYTHONPATH=${PYTHONPATH}:/usr/local/lib/pynaoqi/lib/python2.7/site-packages

, after that you can start to code in this environment.

However, you will find the path is invalid after you finish the current session or close the dialog window. Please add the last command at the end of your .bashrc file. In this way, you can get the working environment after restarting the terminal.

If you are using MAC, you need to do the same as for the Ubuntu users. Besides, please add the following additional line after the last PYTHONPATH setting command:

export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}::/usr/local/lib/pynaoqi/lib

Windows

For Windows, please download Python 2.7 SDK 2.5.5 Win 32 Binaries, and unzip the file into C:\pynaoqi. Then go to My Computer > Properties > Advanced System Settings > Environment Variables again, and under System variables, add a new user variable PYTHONPATH and set it as the path\to\python-sdk\lib (e.g., C:\pynaoqi\lib).

For other installation information, you can refer to here.

Implementation

After setting up the environment, you can type in the following code to test your environment setup:

from naoqi import ALProxy
tts = ALProxy("ALTextToSpeech", "<IP of your robot>", 9559)
tts.say("Hello, world!")

If the Pepper speaks Hello, world!, then you have set up the development environment successfully. We will announce the IP address during the class. If you forget the IP when you experiment, please press pepper’s Chest button, and it will say it.

There is a demo code provided in this repository for you to get aware how to call NAOqi APIs in python. This demo aims to detect human faces and tell their genders and expressions from what has been detected. After changing the IP address of the robot, you can run this code by simply typing

python expression_teller.py

in python environment. There are also plenty of demos offered on the official documentation website.

Tips

Contribute

We would love you for the contribution to Lab4, check the LICENSE file for more information.

Meta

Zhida Sun. Distributed under the MIT license. See LICENSE for more information.