1. Pyro For Projects
This page outlines some hints that might help you in going beyond what is provided with Pyro.
1.1. Making New Robots
1.2. Making New Simulated Robots and Sensors
In the Pyrobot world file, you can define your own sensors, based on existing ones:
from pyrobot.simulators.pysim import *
class Pioneer4FrontLightSensors(LightSensor):
def __init__(self):
# make sure outside of bb!
LightSensor.__init__(self, (
(.225, .175, 0),
(.225, .0875, 0),
(.225, -.0875, 0),
(.225, -.175, 0),
),
noise=0.0)
self.groups = {"front-all": (0, 1, 2, 3),
"all": (0, 1, 2, 3),
"front": (1, 2),
"front-left": (0, ),
"front-right": (3, ),
'left' : (0, 1),
'right' : (2, 3),
'left-front' : (0,),
'right-front' : (3, ),
'left-back' : [],
'right-back' : [],
'back-right' : [],
'back-left' : [],
'back' : [],
'back-all' : []}
def INIT():
# (width, height), (offset x, offset y), scale:
sim = TkSimulator((441,434), (22,420), 40.357554)
# x1, y1, x2, y2 in meters:
sim.addBox(0, 0, 10, 10)
# (x, y) meters, brightness usually 1 (1 meter radius):
sim.addLight(5, 5, 1)
# port, name, x, y, th, bounding Xs, bounding Ys, color
# (optional TK color name):
sim.addRobot(60000, TkPioneer("RedPioneer",
3, 3, -0.86,
((.225, .225, -.225, -.225),
(.175, -.175, -.175, .175))))
# add some sensors:
sim.robots[0].addDevice(PioneerFrontSonars())
sim.robots[0].addDevice(Pioneer4FrontLightSensors())
return sim
1.3. Accessing the Pyrobot Simulator from a Robot Brain
The simulator device has an eval method that takes a string, sends it to the simulator for evaluation, and returns the result (if one). You may send expressions or commands. Here is a command to set the brightness of a light in the world, followed by a command to redraw the simulator screen:
self.robot.simulation[0].eval("self.lights[0].brightness = .5")
self.robot.simulation[0].eval("self.redraw()")
Note that "self" in the string is the simulator object.
