Tutorial?

Up:Tutorial?        Next: The first application using Python

Background

Sigverse has been created for Human robot interaction. Despite its very novel architecture and functionalities, very few people seem to be using it. One of the reasons that I perceive is it might be hard for beginners to use. Since human robot interaction involves, integration of various modalities used for interaction like Computer Vision, Speech, Gestures etc to make robot learn to behave in a certain way. And we want to integrate all these aspects in simplest way possible. Now, there are already several software packages that have been written in Python for the computational needs for HRI.

Thus, I want to embed python to solve all sorts of problems that are painful in C++ and painless in Python – computation of kinematics and dynamics, machine learning applications, computer vision tasks, natural language processing, speech recognition and synthesis and basically anything else that isn’t core algorithms (for performance reasons) or system interaction (for compatibility).

There are two basic models for combining C++ and Python:

  • extending, in which the end-user launches the Python interpreter executable and imports Python “extension modules” written in C++. Think of taking a library written in C++ and giving it a Python interface so Python programmers can use it. From Python, these modules look just like regular Python modules.
  • embedding, in which the end-user launches a program written in C++ that in turn invokes the Python interpreter as a library subroutine. Think of adding scriptability to an existing application.

This work focuses on embedding, thus our program ( called as Controller in terms of sigverse usage), is written in C++ and we would like to invoke python functions from C++.

Here were my initial requirements:

  * instantiate Python objects and interact with them in a natural way
  * pass data into Python functions
  * extract data from Python functions and objects
  * handle errors from with the Python code

At it’s core, embedding Python is very simple, and requires no C++ code whatsoever – the libraries provided with a Python distribution include C bindings. We can do it in two ways:

  • The Python/C API.
  • Boost::python: It provides class wrappers and polymorphic behavior much more consistent with actual Python code than the C bindings would allow.

Using Boost.Python

This section explains how to install Boost.Python [#re25158e]

※ This sample is tested using Ubuntu 12.04 installed using VMWare on Window 7 64-bit PC.

Install Boost.Python

The most reliable way to get a copy of Boost is to download a distribution from SourceForge from the link given on this page http://www.boost.org/doc/libs/1_54_0/libs/python/doc/building.html.

Please visit Section '3.1 Basic Procedure on this page' and download the boost distribution for your system. This work is tested on Ubuntu 12.04, so please download the boost distribution for Unix/Linux variants.

The following are the steps for installation:

1. Download boost_1_54_0.tar.bz2. [latest on 28.08.2013]

2. In the directory where you want to put the Boost installation, execute

       $tar --bzip2 -xf /path/to/boost_1_54_0.tar.bz2

3. Then, do this from the boost download directory:

       $ ./bootstrap.sh --prefix=$HOME/pool --libdir=$HOME/pool/lib --with-libraries=signals,thread,python 
       $ ./bjam variant=release link=shared install

On recent versions, the second line should read

      $./b2
      $./b2 install

A few notes:

  • You may omit --with-libraries=... if you want to build all of boost, but it will make the compile take somewhat longer
  • You may adapt the file and directory names to suit your liking, however the rest of this tutorial will assume that you use these paths.

Also, do the following to install the Boost libraries from the command line using apt-get utility:

       $ sudo apt-get install libboost-all-dev
       $ sudo apt-get upgrade

Up:Tutorial?        Next: The first application using Python

Counter: 3792, today: 2, yesterday: 1

Front page   Edit Freeze Diff Backup Upload Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes
Last-modified: 2014-01-13 (Mon) 03:22:25 (3755d)