Descarga la aplicación para disfrutar aún más
Esta es una vista previa del archivo. Inicie sesión para ver el archivo original
Practica.py # robot goes forward and then slows to a stop when it detects something from pyrobot.brain import Brain import math def adjust(theta): while theta > math.pi: theta -= 2 * math.pi while theta < - math.pi: theta += 2 * math.pi return theta class Practica(Brain): # Give the front two sensors, decide the next move def determineMove(self, front, left, right): if front < 0.5: #print "obstacle ahead, hard turn" return(0, .3) elif left < 0.8: #print "object detected on left, slow turn" return(0.1, -.3) elif right < 0.8: #print "object detected on right, slow turn" return(0.1, .3) else: #print "clear" return(0.5, 0.0) def step(self): # front = min([s.distance() for s in self.robot.range["front"]]) # left = min([s.distance() for s in self.robot.range["left-front"]]) # right = min([s.distance() for s in self.robot.range["right-front"]]) # translation, rotate = self.determineMove(front, left, right) goal_x = 4.5 goal_y = 8.0 x = self.robot.simulation[0].getPose(0)[0] y = self.robot.simulation[0].getPose(0)[1] th = self.robot.simulation[0].getPose(0)[2] phi = math.atan2(goal_y-y, goal_x-x) - math.pi/2 cmd = adjust(phi) - adjust(th) print phi, adjust(phi), th, adjust(th), cmd self.robot.move(0.5, cmd) def INIT(engine): return Practica('Practica', engine) PrWorld.py """ A PyrobotSimulator world. A large room with two robots and two lights. (c) 2005, PyroRobotics.org. Licensed under the GNU GPL. """ from pyrobot.simulators.pysim import * def INIT(): # (width, height), (offset x, offset y), scale: sim = TkSimulator((443,466), (22,420), 40.357554) # x1, y1, x2, y2 in meters: sim.addBox(0, 0, 10, 10) sim.addLight(4.5, 8.0, 0.1, "blue") # port, name, x, y, th, bounding Xs, bounding Ys, color # (optional TK color name): sim.addRobot(60000, TkPioneer("RedPioneer", 4.99, 1.32, 6.28, ((.225, .225, -.225, -.225), (.175, -.175, -.175, .175)), "red")) # add some sensors: sim.robots[0].addDevice(PioneerFrontSonars()) return sim
Compartir