Python SDK入门(2)——让NAO行走并说话

Python SDK入门(2)——让NAO行走并说话

 1. 使NAO刚化

  • 除非你将NAO的stiffness的值设为非0数,否则它是不会移动的

  • 而要做到这点其实很简单,只要通过调用ALMotionProxy::setStiffnesses()进行设置即可:

    from naoqi import ALProxy
    motion = ALProxy("ALMotion", "nao.local", 9559)
    motion.setStiffnesses("Body", 1.0)

2. 使NAO移动

为了让NAO移动,我们应该使用 ALMotionProxy::moveInit()函数(以使NAO处于合适的姿势),然后再调用ALMotionProxy::moveTo()

from naoqi import ALProxy
motion = ALProxy("ALMotion", "nao.local", 9559)
motion.moveInit()
motion.moveTo(0.5, 0, 0)

3. 使NAO同时说话并行走

我们创建的每一个代理(proxy)都有一个叫做”post”的属性,且可以通过使用它在后台调用很多方法。

这可以帮助我们使机器人同时做很多事:

from naoqi import ALProxy
motion = ALProxy("ALMotion", "nao.local", 9559)
tts = ALProxy("ALTextToSpeech", "nao.local", 9559)
motion.moveInit()
motion.post.moveTo(0.5, 0, 0)
tts.say("I'm walking")

当然,如果需要等待一个任务结束,我们可以使用ALProxy中的等待方法,使用寄出的方法(the post usage)所返回的任务ID:

from naoqi import ALProxy
motion = ALProxy("ALMotion", "nao.local", 9559)
motion.moveInit()
id = motion.post.moveTo(0.5, 0, 0)
motion.wait(id, 0)

完整的程序

from naoqi import ALProxy
import argparse

motion = ALProxy("ALMotion", "192.168.1.114", 9559)         #NAO的动作对象
tts = ALProxy("ALTextToSpeech", "192.168.1.114", 9559)      #NAO的语言对象
posture = ALProxy("ALRobotPosture", "192.168.1.114", 9559)  #NAO的姿势对象

#首先唤醒NAO
motion.wakeUp()

#让NAO站好
posture.goToPosture("StandInit", 0.5)

#将其刚化
motion.setStiffnesses("Body", 1.0)

#初始化
motion.moveInit()

#让NAO向前走1米,同时返回任务ID给id
id = motion.post.moveTo(1, 0, 0)

tts.say("I'm walking")

#直到id传过来了,再执行wait()函数
motion.wait(id, 0)

tts.say("I will not walk anymore")

#让NAO休眠
motion.rest()

猜你喜欢

转载自blog.csdn.net/li827437709/article/details/80073297