鱼C论坛

 找回密码
 立即注册
查看: 463|回复: 1

python小白求助

[复制链接]
发表于 2018-11-23 00:05:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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")
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2018-11-23 00:11:00 | 显示全部楼层
第一次发帖子,不太知道规矩,不好意思。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-28 01:24

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表