基础实验 用视觉线索破解迷宫
主要通过放在迷宫中的NAOMark标志引导NAO左转或者右转
NAOMark 64 表示 左转, 84表示 右转,Timer让NAO每隔5秒向前走0.04米
高级任务 破解迷宫的正确方法
其中,Explore maze的代码为:
class MyClass(GeneratedClass):
def __init__(self):
GeneratedClass.__init__(self)
def onLoad(self):
#put initialization code here
self.motionProxy = ALProxy("ALMotion")
self.front = False
self.rear = False
self.forwardDist = 0.1 #How far is each cell to walk across in m ?
def onUnload(self):
#put clean-up code here
pass
def onInput_onStart(self):
#self.onStopped() #activate the output of the box
pass
def onInput_onStop(self):
self.onUnload() #it is recommended to reuse the clean-up as the box is stopped
self.onStopped() #activate the output of the box
def onInput_Front(self):
self.front = True
def onInput_middle(self):
self.computeNextAction()
self.front = False
self.rear = False
def onInput_rear(self):
self.rear = True
def computeNextAction():
if(not self.rear): #no wall to the right
self.motionProxy.walkTo(0, 0, -1.57) #Turn to the right
self.motionProxy.walkTo(self.forwardDist, 0, 0)
elif(self.rear and not self.front): #Wall to the right, no wall in front
self.motionProxy.walkTo(self.forwardDist, 0, 0)
else :
self.motionProxy.walkTo(0, 0, 1.57) #Turn to the left