RAPP Platform Wiki  v0.6.0
RAPP Platform is a collection of ROS nodes and back-end processes that aim to deliver ready-to-use generic services to robots
 All Files Pages
(hard) In-robot-application-for-NAO-in-Python:-Create-a-cognitive-game-(hard)

This is an example application for Cognitive Exercises.

In this tutorial we will focus on a step-by-step guidance through implementing the Cogntive Exercises RApp (Robotic Application).

The complete implemnention of the CognitiveExercises RApp can be found here

Preparation steps

For this tutorial we will use the following tools:

Of course the standard prerequisites are an editor and a terminal.

RAPP Robots API libraries setup

The first step is to clone the appropriate GitHub repository in your PC:

```bash $ mkdir ~/rapp_nao $ cd ~/rapp_nao $ git clone https://github.com/rapp-project/rapp-robyyots-api.git ```

The next step is to transfer the RAPP Python libraries to the NAO robot. This will be done via scp, assuming that the NAO robot's IP is 192.168.0.101 and username and password are nao:

```bash $ cd ~/rapp_nao/ $ tar -zcvf rapp_robots_api.tar.gz rapp-robots-api/ $ scp rapp_robots_api.tar.gz nao@1.nosp@m.92.1.nosp@m.68.0..nosp@m.101:/home/nao ```

Now connect in NAO via ssh by ssh nao@192.168.0.101 giving nao as password. Then untar the API:

```bash $ tar -xvf rapp_robots_api.tar.gz $ rm rapp_robots_api.tar.gz ```

The next step is to update the PYTHONPATH variable. Since NAO has Gentoo as OS, we will modify the bash_profile file:

```bash $ echo 'export PYTHONPATH=$PYTHONPATH:/home/nao/rapp-robots-api/python/abstract_classes' >> /home/nao/.bash_profile $ echo 'export PYTHONPATH=$PYTHONPATH:/home/nao/rapp-robots-api/python/implementations/nao_v4_naoqi2.1.4' >> /home/nao/.bash_profile $ source ~/.bash_profile ```

The last step to configure the rapp-robots-api is to declare the NAO IP. Since the robot API is in-robot, the IP must be localhost: 127.0.0.1.

The IP must be declared in the first line of this file, thus the nao_connectivity file located under /home/nao/rapp-robots-api/python/implementations/nao_v4_naoqi2.1.4/nao_connectivity should contain:

``` 127.0.0.1 9559 ```

RAPP Platform API (Python) libraries setup

The first step is to clone the rapp-api GitHub repository in your PC:

```bash $ cd ~/rapp_nao $ git clone https://github.com/rapp-project/rapp-api.git ```

The next step is to transfer the Python libraries to the NAO robot. This will be done via scp, assuming that the NAO robot's IP is 192.168.0.101 and username and password are nao:

```bash $ cd ~/rapp_nao/ $ tar -zcvf rapp_api.tar.gz rapp-api/ $ scp rapp_api.tar.gz nao@1.nosp@m.92.1.nosp@m.68.0..nosp@m.101:/home/nao ```

Now connect in NAO via ssh by ssh nao@192.168.0.101 giving nao as password. Then untar the API:

```bash $ tar -xvf rapp_api.tar.gz $ rm rapp_api.tar.gz ```

The next step is to update the PYTHONPATH variable. Since NAO has Gentoo as OS, we will modify the bash_profile file:

```bash $ echo 'export PYTHONPATH=$PYTHONPATH:/home/nao/rapp-api/python' >> /home/nao/.bash_profile $ source ~/.bash_profile ```

Writing the Cognitive Exercises RApp

We will work on the host machine while implementing the RApp and then we are going to transfer the application source files to the NAO Robot and execute.

Let's create a package for the application:

```bash $ mkdir -p ~/rapp_nao/rapps/cognitive_exercises $ cd ~/rapp_nao/rapps/cognitive_exercises $ mkdir rapps && cd rapps $ touch cognitive_exercises.py $ chmod +x cognitive_exercises.py ```

Import the required components into the code:

```python #!/usr/bin/env python

Import the RAPP Robot API

from rapp_robot_api import RappRobot

Create an object in order to call the desired functions

rh = RappRobot()

from RappCloud import RappPlatformService from RappCloud.CloudMsgs import ( CognitiveExerciseSelect, CognitiveRecordPerformance, SpeechRecognitionSphinx, SetNoiseProfile) ```