Up:Tutorial   Previous: Embedding Python Interpreter      Next:Computation of Inverse kinematics for 3dof planar robot

Before making the first application

Header files

We will use the static boost::python library (libboost_python.a) and the dynamic version of the Python library (libpython.so). We will change the path in the Makefile to point to your boost installation directory.

Let’s get some code running. You’ll need to include the correct headers, as you might imagine.

These header files are added in the beginning of the program as usual.

Initalize Python Interpreter

Add namepaces:

Then move to the member function onInit()and add the following lines.

Note that you must initialize the Python interpreter directly (line 1). After initializing, the __main__ module is imported and the namespace is extracted. This results in a blank canvas upon which we can then call Python code, adding modules and variables.

Note: The initialization of interpreter, import of __main__ module and namespace is independent of the member functions that are first used in. Thus you can do this in some other member function like onAction() which is a loop function in Sigverse. The only requirement is that they should be used before using any python functionality. Also, you dont have to use loop/loop functions to initialize the interpreter.

Thus, its recommended to initialize the interpreter inside onInit() member function.

We need to add the following code before initializing the interpreter. The reason for this is explained in FAQ section and is not really important for this tutorial.

We had already included the header file for the above function.

Thus, to begin with for all cases we need to have following two lines.

The first application

Hello World

Go to onInit() member function and copy the following:

The blank canvas is created upon which we can call python code now, add modules and variables.

The 'exec' function runs the arbitrary code in the string parameter within the specified namespace. All of the normal, non-imported code is available. Of course, this isn’t very useful without being able to import modules and extract values. But this will be target of our next tutorial. Now let's execute this program.

Creating Makefile.

Then type on console to compile the code:


Now, you need to set the library path using. It is better to add it in your bashrc file.

Then, load the xml file using sigviewer:

    $sigserver.sh -w ./WorldFile.xml 

After the world loads, push "Start Button" to see the results of python code.

Up:Tutorial   Previous: Embedding Python Interpreter      Next:Computation of Inverse kinematics for 3dof planar robot

Counter: 2021, today: 3, yesterday: 0

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-02-12 (Wed) 01:46:48 (1646d)