UserPreferences

PythonicPyroIntro


Pythonic Pyro Introduction

This should help you convert old Pyro code to the new Pythonic interface:

Old Path Interface                                   Using the Pythonic Interface
-----------------------------------------------      -----------------------------------------------
                                                     robot = self.robot
self.get('/robot/range/count')                       len(robot.range)
                                                     robot.range.count
self.get('/devices/laser0/count')                    len(robot.laser[0])
self.get('/robot/laser/count')                       len(robot.laser[0]) # same as above
                                                     robot.laser[0].count
self.get('/robot/range/3/value')                     robot.range[3].distance() 
                                                     robot.range[3].value
self.set('/robot/range/units', 'CM')                 robot.range[3].distance(unit='cm') # for one reading
                                                     robot.range.units = 'CM'           # for all readings
self.get('/robot/range/3/value') 
self.get('/robot/range/all/value')                   [sensor.distance() for sensor in robot.range]
                                                     [sensor.value for sensor in robot.range]
self.get("/robot/range/all/th")                      [sensor.angle() for sensor in robot.range]
self.get("/robot/range/all/thr")                     [sensor.angle(unit="radians") for sensor in robot.range]
# returns a dict for each sensor:                    # returns a tuple for each sensor:
self.get("/robot/range/all/value,th")                [(sensor.distance(), sensor.angle()) for sensor in 
                                                                                             robot.range]
self.get('/robot/range/2/x,y')                       robot.range[2].geometry()
      # returns dict {'y': y, 'x': x}                      # returns tuple (x,y,z,thr,arc)
self.get('/robot/range/front/value')                 [sensor.distance() for sensor in robot.range['front']]
self.get('/robot/range/1:5/value')                   [sensor.distance() for sensor in robot.range[1:5]]

# find the direction of the nearest obstacle: 
from pyrobot.brain import select, avg 
select(min, "value",                                 min([(sensor.distance(), sensor.angle()) for sensor in 
 self.get("/robot/range/all/pos,thr,value"))["thr"]                                 robot.range])[1]

Some forms were removed. The following have no short forms:

self.get('/robot/range/1,5/value')                   [sensor.value for sensor in robot.range[1,5]]         # uses special pyro syntax
self.get('/robot/range/1-5/value')                   [sensor.distance() for sensor in robot.range[1:6]]    # uses slice instead

Pyro Modules Table of Contents

Modules

  1. PyroModuleIntroduction

  2. PyroModuleObjectOverview

  3. PyroModulePythonIntro

  4. PyroModuleDirectControl

  5. PyroModuleSequencingControl

  6. PyroModuleBehaviorBasedControl

  7. PyroModuleReinforcementLearning

  8. PyroModuleNeuralNetworks

  9. PyroModuleEvolutionaryAlgorithms

  10. PyroModuleComputerVision

  11. PyroModuleMapping

  12. PyroModuleMultirobot

  13. FurtherReading

Additional Resources

  1. PyroIndex

  2. PyroAdvancedTopics

  3. PyroUserManual

  4. [WWW]Pyro Tutorial Movies

Reference: PyroSiteNotes