Quick Start

Robot Raconteur® is a powerful communication library that has numerous features. This page is intended to provide a very fast start to using the library in Python that ignores most of the features and implements a simple function that can be called on a service by a client. The object also is capable of member types property, event, objref, pipe, callback, wire, and memory. See the Documentation page for full details. These examples require the Python Robot Raconteur® library to be installed. It can be downloaded from the Download page. A simple service has three steps: Initialize Robot Raconteur, register an object as a service, and finally shut down when completed. This example service creates a simple service that contains a single function to drive an iRobot Create through a serial port. This is a minimal subset of the full example in the documentation.

minimalcreateservice.py

import RobotRaconteur as RR
RRN=RR.RobotRaconteurNode.s
import threading
import serial
import struct

minimal_create_interface="""
service experimental.minimal_create

object create_obj
    function void Drive(int16 velocity, int16 radius)
end object
"""

class create_impl(object):
    def __init__(self, port):
        self._lock=threading.Lock()
        self._serial=serial.Serial(port=port,baudrate=57600)
        dat=struct.pack(">4B",128,132,150, 0)
        self._serial.write(dat)

    def Drive(self, velocity, radius):
        with self._lock:
            dat=struct.pack(">B2h",137,velocity,radius)
            self._serial.write(dat)

#Create and register a transport
t=RR.TcpTransport()
t.StartServer(52222)
RRN.RegisterTransport(t)

#Register the service type
RRN.RegisterServiceType(minimal_create_interface)

create_inst=create_impl("/dev/ttyUSB0")

#Register the service
RRN.RegisterService("Create","experimental.minimal_create.create_obj",create_inst)

#Wait for program exit to quit
raw_input("Press enter to quit")

This service can now be called by a connecting client. Because of the magic of Robot Raconteur, it is only necessary to connect to the service to utilize its members. In Python and MATLAB there is no boilerplate code, and in the other languages the boilerplate code is generated automatically.

minimalcreateclient.py

from RobotRaconteur.Client import *
import time

#RRN is imported from RobotRaconteur.Client
#Connect to the service.
obj=RRN.ConnectService('rr+tcp://localhost:52222/?service=Create')

#The "Create" object reference is now available for use
#Drive for a bit
obj.Drive(100,5000)
time.sleep(1)
obj.Drive(0,5000)

In MATLAB, this client is even simpler.

minimalcreateclient.m

o=RobotRaconteur.Connect('rr+tcp://localhost:52222/?service=Create');
o.Drive(int16(100),int16(5000));
pause(1);
o.Drive(int16(0),int16(0));