Interfacing Your Own Robot

1. Interfacing Your Own Robot

There are three example files to explore in making your own robot, device, or brain. They are all named "" and are found in the file selection dialog when selecting robot, device, or brain. The files are found in pyrobot/plugins/ITEM/ where ITEM is robots, devices, or brains.

1.1. Robot

The robot "" (pyrobot/plugins/robots/ simply creates and loads a base Robot(). But you can overload that. Here is a stub for creating your own robot:

from pyrobot.robot import Robot
class TestRobot(Robot):
    def setup(self):
        self.builtinDevices = [] # list of built-in devices
        self.supportedFeatures = [] # meta devices
    def connect(self): pass
    def disconnect(self): pass
    def move(self, translate, rotate): pass
    def translate(self, val): pass
    def rotate(self, val): pass
    def startDeviceBuiltin(self, item): pass
    def update(self):
    def localize(self, x = 0, y = 0, th = 0):
        print "need to override LOCALIZE in robot"
def INIT():
    return TestRobot()

To create your own robot, you will need to define how it moves (move(), translate(), rotate()) how it connects to a server (if it does, use connect() and disconnect()), and any intialization (setup()). If the robot needs to compute something before or after it updates it devices, then you can add that to the update() method.

localize() is needed if you want to be able to tell the robot where it is in the world. Many commercial robots have the ability to keep track (through dead reckoning) where they are in the world, and you can reset them at any point to an arbitrary position.

If you have special devices, you can define them here. Simply add the name to builtinDevices and create them in startDeviceBuiltin(). If it is a general device that other robots can use, make it a stand-alone device described in the following section.

1.2. Device

What is a device? Anything can be seen as a device, but generally if you have the need for something to update with the robot, and maybe wish to have a graphical view, then you might want to make this functionality a device. Current devices are hardware such as lasers, sonars, grippers, cameras, but also visualization tools that plot some aspect of the robot or sensor. See for example the View devices in pyrobot/plugins/devices/ (loadable from the Load -> Device... menu option.)

If you create a device as a loadable device, then it implies that it can be loaded by different kinds of robots (otherwise you would just put it in the robot defining class as above). Then again, this makes it easy to select it from a menu. Before you define a new type of device, you should consider adapting an existing type:

The device "" (pyrobot/plugins/devices/ simply creates and loads a basic Device(). Here it is:

from pyrobot.robot.device import Device
class TestDevice(Device):
    def setup(self):
        self.type = "test"
        self.visible = 1
        self.specialvalue = 42
    def makeWindow(self):
        print "[[[[ made window! ]]]]"
    def updateWindow(self):
        print "update window! -------------" # when visible, few times a second
    def updateDevice(self):
        print "------------- update device!" # about 10 times a second!
def INIT(robot):
    return {"test": TestDevice()}

1.3. Brain

The brain "" (pyrobot/plugins/brains/ simply creates and loads a simple Brain(). Here it is:

from pyrobot.brain import Brain
class SimpleBrain(Brain):
   # Only method you have to define is the step method:
   def setup(self):
      # create any vars you need here
def INIT(engine):
   return SimpleBrain("SimpleBrain", engine)

1.4. Server

Your robot may need a service started so that you can connect onto it. For example, maybe you want to write a test simulator to connect onto. Use the programs in pyrobot/plugins/servers/ as an example. These programs are designed to run from inside Pyro; when Pyro stops, it will automatically stop the server.

If you wish to write a simulator in Python, check out the The Pyrobot Simulator.

Up: PyroHardware