NAO实验10

基础实验 用视觉线索破解迷宫

主要通过放在迷宫中的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        

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值