# #Example of Behavior based control with two simple behaviors. # (See future example for 3 behaviors) # # Jay Summet # Sep 22nd, 2008, released to the public domain. from myro import * init() #Move behavior: Always recommends that the robot move. def move(): return( [ True, -1.0 , 0.0 ] ) #Avoid behavior, makes the robot turn away from obstacles. def avoid(): sensorVals = getIR() leftV = sensorVals[0] rightV = sensorVals[1] if (leftV == 0) or (rightV == 0): return( [ True, 0.0 , 1.0 ] ) else: return( [ False, 0.0, 0.0 ] ) #Calls each behavior in the ordere listed. If a behavior gives a recommendation, # arbitrate passes the recommended action on to the robot and then skips the # rest of the behaviors. (So avoid has a higher priority than move.) def arbitrate(): behaviors = [avoid, move] for behavior in behaviors: values = behavior() hasRec = values[0] transVal = values[1] rotVal = values[2] print "behavior:, ", behavior, "has values:", hasRec, transVal, rotVal if (hasRec == True): translate(transVal) rotate(rotVal) return() #Main code, does the behavior for 10 seconds, then stops the robot: while( timeRemaining(10)): arbitrate() stop()