nao机器人触摸头部行走

整理之前的代码

#!/usr/bin/env python
#在#!/usr/bin/env中找到python的安装路径,然后去执行它,这个可执行的python路径不管是不是在/usr/bin下

#-*- coding:utf-8 -*-  解决中文输出问题
from naoqi import ALProxy
import threading
IP="192.168.1.109"
port=9559
#构建代理
motionPrx=ALProxy("ALMotion",IP,port)
touchProxy=ALProxy("ALTouch",IP,port)
memory=ALProxy("ALMemory",IP,port)

config=[
      ["MaxStepX",0.04],
      ["MaxStpY",0.02],
      ["StepHeight",0.02],
      ["MaxStepFrequency",0.3] ]
#定义一个行走的函数
def move():
     while True:
           motionPrx.moveTo(0.5,0.0,0.0,config)
           if Front==1:
               break
#定义一个触摸的函数
def touch():
     while True:
          global Front
          Front=memory.getData("FrontTactilTouched")
          if Front==1:
              motionPrx.rest()
              break

if __name__=='__main__':
     motionPrx.wakeUp()   #让机器人醒来
     t1=threading.Thread(target=touch)
     t2=threading.Thread(target=move)
     t1.start()
     t2.start()
     t1.join()
     t2.join()

你可能感兴趣的:(nao机器人)