For this lab you may work in pairs to learn how to control robots through Pyro. You will create a wall following brain for a simulated Pioneer robot. On October 2nd, you'll get to test these brains on the real Pioneer robot and see how well they transfer from simulation to reality.
#File: Avoid.py
from pyrobot.brain import Brain
class AvoidBrain(Brain):
# Only method you have to define is the step method:
def step(self):
Ftolerance = 1.0
FLtolerance = 1.0
FRtolerance = 1.0
fleft = min([s.distance() for s in self.robot.range["left-front"]])
fright = min([s.distance() for s in self.robot.range["right-front"]])
front = min([s.distance() for s in self.robot.range["front"]])
if (front < Ftolerance):
print "obstacle front"
self.robot.move(0, 0.2)
elif (fright < FRtolerance):
print "obstacle right"
self.robot.move(0, .2)
elif (fleft < FLtolerance):
print "obstacle left"
self.robot.move(0, -.2)
else:
print "clear"
self.robot.move(0.2, 0)
# -------------------------------------------------------
# This is the interface for calling from the gui engine.
# Takes one param (the robot), and returns a Brain object:
# -------------------------------------------------------
def INIT(engine):
return AvoidBrain('AvoidBrain', engine)
Email me your robot brain file. Make sure that the file contains both names in it.
Turn in a print out in class.