Home
FAQ
Player
Stage
Gazebo
Contrib
Documentation
Publications
Contributors
Users

Project
Download
Bugs/Feedback
Mailing lists

Radish

Old news
Old stuff

libplayerc_py
[Client Libraries]

Python bindings for libplayerc are generated automatically using SWIG. The bindings are object-oriented, using standard Python classes (for those familiar with SWIG, these are standard SWIG shadow classes).

General usage

libplayerc is based on a device proxy model, in which the client maintains a local proxy for each of the devices on the remote server. Thus, for example, one can create local proxies for the position and laser devices. There is also a special client proxy, used to control the Player server itself.

Programs using the libplayerc Python bindings will generally have the following structure:

# Desc: A simply joystick controller
# Author: Andrew Howard

import math
from playerc import *


def main(host, port):

    # Connect to the server
    client = playerc_client(None, host, port)
    if client.connect() != 0:
        raise playerc_error_str()

    # Open a joystick device
    joystick = playerc_joystick(client, 0)
    if joystick.subscribe(PLAYERC_READ_MODE) != 0:
        raise playerc_error_str()

    # Open a position device
    position = playerc_position(client, 0)
    if position.subscribe(PLAYER_ALL_MODE) != 0:
        raise playerc_error_str()

    # Enable the motors
    position.enable(1)

    while 1:

        # Read data from the server
        pid = client.read()

        # Print out current position
        if pid == position.info.id:
            print '%+.3f %+.3f' % (position.px, position.py)

        # Send velocity commands to the robot
        if pid == client.id:
            vel_x = -joystick.py * 0.50
            vel_yaw = -joystick.px * math.pi / 4
            position.set_cmd_vel(vel_x, 0, vel_yaw, 1)
            
    return




if __name__ == '__main__':

    main('localhost', 6665)

The steps in this program mirror those described for standard C clients. The key syntactical difference between the C-version and the Python version is the use of Python's object-oriented features.

Proxy reference

Generally speaking, the Python bindings are one-to-one mappings to the libplayerc API. Thus, the C documentation can be used as a guide, so long as one makes some minor mental translations; e.g.:

proxy = playerc_position_create(...); -> proxy = playerc_position(...) playerc_position_set_speed(proxy, ...); -> proxy.set_speed(...)

Detailed information for each C proxy can be found in the Reference section.


Generated on Tue May 3 14:16:13 2005 for Player by doxygen 1.3.6