ArmarX Python Bindings

ArmarX provides python bindings to conveniently access interfaces via Python.

See also
More examples:
The Python 3 bindings on the H²T GitLab:
The remainder of this page contains legacy documentation.

Setting up the ArmarX python module

If you did not install ArmarXCore and are using it from source, you have to register the ArmarX python module:

cd ${ArmarXCore_DIR}/../etc/python
python develop --user

Loading a Slice interface

First, you need to load the interface defintion file. These are located in each package in the source/${PackageName}/interface folder. To load and compile these files for python you can use the load_armarx_slice function from the module armarx.interface_helper. The function expects the package name as the first paramter and a relative path to the interface folder (to the path given above) as the second parameter. Afterwards, the interface module is available and needs to be imported. An example looks like this:

from armarx.interface_helper import load_armarx_slice
load_armarx_slice('VisionX', 'core/')
from visionx import ImageProviderInterfacePrx

All ArmarX slice interfaces can be found here: armarx_documentation: Slice Documentation

Example: Moving the platform via Python

This is a simple example to control the platform. The proxy to the PlatformUnit is obtained by calling get_proxy from the interface_helper module. In the next step, the platform is moved to postion 3000, 8000 with respect to the world coordinate system.

#!/usr/bin/env python

from armarx.interface_helper import load_armarx_slice, get_proxy
load_armarx_slice('RobotAPI', 'units/')

from armarx import PlatformUnitInterfacePrx

def main():
    platform_unit = get_proxy(PlatformUnitInterfacePrx, 'Armar3PlatformUnit')
    platform_unit.moveTo(3000, 8000, 0, 10.0, 0.1)

if __name__ == '__main__':

Example: event based listener

The python interface can also be used to register a class to a topic. In this example the 'ExampleListenerInterface' is implemented and the function on_example_event is registered to the topic 'ExampleTopicName'

First, an instance of the class is created by

ice_object = ExampleListener()

. The instance is then registered to and connected to the topic via

proxy = register_object(ice_object, 'ExampleListener')
topic = using_topic(proxy, 'ExampleTopicName')

The function on_example_event is triggered now automatically by the middleware on each event. Please do not forget to unsubscribe from the topic via:


The full example is as follows.

#!/usr/bin/env python

import time
import logging
from armarx.interface_helper import load_armarx_slice, ice_helper
from armarx.interface_helper import get_proxy, register_object, using_topic

load_armarx_slice('YourArmarXPackageName', 'component/')
from armarx import ExampleListenerInterface

logger = logging.getLogger(__name__)

class ExampleListener(ExampleListenerInterface):

    def __init__(self):
        super(ExampleListenerInterface, self).__init__()

    def on_example_event(self, current=None):'called')

def main():
    ice_object = ExampleListener()
    proxy = register_object(ice_object, 'ExampleListener')
    topic = using_topic(proxy, 'ExampleTopicName')

        while not ice_helper.iceCommunicator.isShutdown():
            logger.debug('still alive')
    except KeyboardInterrupt:
  'shutting down')

if __name__ == '__main__':