UserPreferences

NNOfflineProgram


  1 
  2 
  3 
  4 
  5 
  6 
  7 
  8 
  9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
 19 
 20 
 21 
 22 
 23 
 24 
 25 
 26 
 27 
 28 
# 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)