#FORMAT python # robot goes forward and then slows to a stop when it detects something from pyrobot.brain import Brain from pyrobot.brain.conx import * from time import * class NNBrain(Brain): # Give the front two sensors, decide the next move def determineMove(self, front): if front[0] < 0.5 or front[1] < 0.5: # about to hit soon, STOP print "collision imminent, stopped" return(0) elif front[0] < 0.8 or front[1] < 0.8: # detecting something, SLOWDOWN print "object detected" return(0.1) else: print "clear" # all clear, FORWARD return(0.3) def step(self): front = [s.distance() for s in self.robot.range["front"]] translation = self.determineMove(front) print "front sensors", front[0], front[1] self.move(translation, 0.0) def INIT(engine): return NNBrain('NNBrain', engine)