|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
小弟在用python学习NAO机器人 想实现一个功能如下 不知用什么方法 没有一点思绪 希望大神可以给点指点。
在linux系统terminal中输入 python move_joint SOME_JOINTS_NAME 当SOME_JOINTS_NAME用具体关节替代时 具体关节可以动
比如输入 python move_joint HeadYaw,就会实现HeadYaw的这个功能
下面是个让头部关节动的代码:
# -*- encoding: UTF-8 -*-
# this script shows how to move the head
import sys
import argparse
import time
from math import radians
from naoqi import ALProxy
DEFAULT_IP='127.0.0.1'
DEFAULT_PORT=9559
def stiffnessChangeHead(motionProxy, stiffness):
pNames = [ "HeadYaw"]
pStiffnessLists = stiffness
pTimeLists = 1.0
motionProxy.stiffnessInterpolation(pNames, pStiffnessLists, pTimeLists)
# this function shows how to move just one joint
def moveHeadOneJoint(motionProxy, moveInSecs, holdSecs, moveOutSecs):
calcTimes = [moveInSecs, moveInSecs + holdSecs, moveInSecs + holdSecs + moveOutSecs]
# Joint names and angle lists must be in the same order.
# There is one angle list for each joint name and each angle list has
# the same number of elements as the times list above.
# We supply angles in degrees and convert to radians using the math.radians function
# see http://doc.aldebaran.com/2-1/family/robots/joints_robot.html
# for joint names and permitted angle range
# angle1 = target, angle2 = hold, angle3 = return to original
names = ["HeadYaw"]
times = [calcTimes, ]
angles = [[radians(-119.5), radians(119.5), radians(0), ]] # HeadYaw
motionProxy.angleInterpolation(names, angles, times, True);
def main():
parser = argparse.ArgumentParser(description="Move Head")
parser.add_argument('--ip', default=DEFAULT_IP, help='robot/naoqi IP address to use')
parser.add_argument('--port', default=DEFAULT_PORT, help='robot/naoqi port to use')
args = parser.parse_args()
try:
motionProxy = ALProxy("ALMotion", args.ip, args.port)
except Exception, e:
print "Could not create proxy"
print "Error was: ", e
return
stiffnessChangeHead(motionProxy, 0.7) # switch on stiffness
moveHeadOneJoint(motionProxy, 1.0, 2.0, 1.0)
stiffnessChangeHead(motionProxy, 0.0) # switch off stiffness
#
# This is where the script starts executing and it simply calls the function
# main to get everything going
#
if __name__ == "__main__":
main()
print("the range of degree is -119.5 to 119.5") |
|