def getpercepts(self, beliefbase): dist = pi2go.getDistance() beliefbase['distance'] = dist irR = pi2go.irRight() beliefbase['obstacle_right'] = irR irL = pi2go.irLeft() beliefbase['obstacle_left'] = irL irC = pi2go.irCentre() beliefbase['obstacle_centre'] = irC irLL = pi2go.irLeftLine() beliefbase['line_left'] = irLL irRL = pi2go.irRightLine() beliefbase['line_right'] = irRL switch = pi2go.getSwitch() beliefbase['switch_pressed']= switch lightFL = pi2go.getLightFL() beliefbase['lightFL'] = lightFL lightFR = pi2go.getLightFR() beliefbase['lightFR'] = lightFR lightBL = pi2go.getLightBL() beliefbase['lightBL'] = lightBL lightBR = pi2go.getLightBR() beliefbase['lightBR'] = lightBR super() return
def getpercepts(self, beliefbase): dist = 50 beliefbase['distance'] = dist irR = robohat.irRight() beliefbase['obstacle_right'] = irR irL = robohat.irLeft() beliefbase['obstacle_left'] = irL irLL = robohat.irLeftLine() beliefbase['no_line_left'] = irLL irRL = robohat.irRightLine() beliefbase['no_line_right'] = irRL super() return
def getpercepts(self, beliefbase): dist = initio.getDistance() beliefbase['distance'] = dist irR = initio.irRight() beliefbase['obstacle_right'] = irR irL = initio.irLeft() beliefbase['obstacle_left'] = irL irLL = initio.irLeftLine() beliefbase['line_left'] = irLL irRL = initio.irRightLine() beliefbase['line_right'] = irRL super() return
import simclient.simrobot as initio import time speed = 60 turn_speed = 50 initio.init() # main loop try: while True: print initio.irLeft(), initio.irRight() if initio.irAll(): if initio.irLeft(): initio.spinRight(turn_speed) elif initio.irRight(): initio.spinLeft(turn_speed) while initio.irAll(): time.sleep(0.2) else: initio.forward(speed) time.sleep(0.2) except KeyboardInterrupt: initio.cleanup()
import time import simclient.simrobot as initio stop_range = 100.0 turn_speed = 50 move_speed = 60 sonar_wait = 1.5 PAN = 0 initio.init() try: while True: print initio.getDistance(), initio.irLeft(), initio.irRight() if initio.getDistance() < stop_range: initio.stop() print "range less than %f, looking around" % stop_range left = right = 0 initio.setServo(PAN, -70) time.sleep(sonar_wait) right = initio.getDistance() print "right range: %f" % right initio.setServo(PAN, 70) time.sleep(sonar_wait) left = initio.getDistance() print "left range: %f" % left initio.setServo(PAN, 0) time.sleep(sonar_wait) turn = 0