python实现nao机器人手臂动作控制

 更新时间:2019年04月29日 10:23:02   作者:Earl_Martin  
这篇文章主要为大家详细介绍了python实现nao机器人手臂动作控制,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了python实现nao机器人手臂动作的具体代码,供大家参考,具体内容如下

这些天依然在看nao公司文档的东西,把读过的代码顺手敲了出来。代码依然很简单,但是为什么我要写博客呢?这其中有很大的原因在于,代码是死的,可是读着读着就感觉代码活了,而且,每次读都会有不同的感受。咱就直接看正题吧。

#-*-encoding:UTF-8-*-
import sys
import motion
import almath
from naoqi import ALProxy
 
def StiffnessOn(proxy):
    #we use the body name to signify the collection of all jionts
    pName="Body"
    pStiffnessLists=1.0
    pTimeLists=1.0
    proxy.stiffnessInterpolation(pName,pStiffnessLists,pTimeLists)
 
def main(robotIP):
    ''' example showing a path of two position
    '''
    try:
      motionProxy=ALProxy("ALMotion",robotIP,9559)
    except Exception ,e:
        print"could not create a proxy to almotion"
        print str(e)
 
    try:
      postureProxy=ALProxy("ALRobotPosture",robotIP,9559)
    except Exception ,e:
        print"could not create a proxy to alRobotPosture"
        print str(e)
    #set the nao stiffness on
    StiffnessOn(motionProxy)
 
    #set the nao to standinit
    postureProxy.goToPosture("StandInit",0.5)
 
    effector="LArm"
    space=motion.FRAME_ROBOT
    # AXIS_MASK_VEL=7
    axisMask=almath.AXIS_MASK_VEL
    isAbsolute=False
    #since we are in relative, the current position is zero
    currentPos=[0.0,0.0,0.0,0.0,0.0,0.0]
    #define the changes in relative to the current position 
    dx=0.03      #translation axis x
    dy=0.03      #translation axis y
    dz=0.00      #translation axis z
    dwx=0.00     #rotation axis x
    dwy=0.00     #rotation axis x
    dwz=0.00     #rotation axis x
 
    targetPos=[dx,dy,dz,dwx,dwy,dwz]
 
    #go to the target and back again
    path=[targetPos,currentPos]
    times=[2.0,4.0]#seconds
    motionProxy.positionInterpolation(effector,space,path,axisMask,times,isAbsolute)
 
if __name__=="__main()__":
    robotIP="127.0.0.1"
    if len(sys.argv)<=1:
      print "use default :127.0.0.1"
    else:
      robotIP=sys.argv[1]       
main(robotIP)

接下来是另一个:

#-*-encoding:UTF-8-*-
''' Cartesian control :arm trajectory example'''
 
import sys
import motion
import almath
from naoqi import ALProxy
def StiffnessOn(proxy):
    pName="Body"
    pStiffnessLists=1.0
    pTimeLists=1.0
    proxy.stiffnessInterpolation(pName,pStiffnessLists,pTimeLists)
 
 
def main(robotIP):
    '''showing a hand ellipoid
    '''
    try:
      motionProxy=ALProxy("ALProxy",robotIP,9559)
    except Exception,e:
      print"could not create a proxy "
      print"error was ",e
 
    try:
      postureProxy=ALProxy("ALRobotProxy",robotIP,9559)
    except Exception ,e:
      print"could not create a proxy"
      print "error was",e
 
    #send nao in stiffness on
    setStiffnessOn(motionProxy)
    #send nao to pose init
    postureProxy.goToPosture("StandInit",0.5)
 
    effector="LArm"
    space=motion.FRAME_ROBOT
    path=[
        [0.0,-0.05,+0.00,0.0,0.0,0.0],    #pose1
        [0.0,+0.00,+0.04,0.0,0.0,0.0],    #pose2
        [0.0,+0.04,+0.00,0.0,0.0,0.0],    #pose3
        [0.0,+0.00,-0.02,0.0,0.0,0.0],    #pose4
        [0.0,-0.05,+0.00,0.0,0.0,0.0],    #pose5
        [0.0,+0.00,+0.00,0.0,0.0,0.0]
        ]                #pose6
    axisMask=7
    times=[0.5,1.0,2.0,3.0,4.0,4.5]       #seconds 
    
    isAbsolute=False
    motionProxy.positionInterpolation(effector,space,path,axisMask,times,isAbsolute)
    
if __name__=="__main__":
    robotIP="127.0.0.1"
    if len(sys.argv)<=1:
        print "usage local ip "
    else:
        robotIP=sys.argv[1]
    main(robotIP) 

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。       

相关文章

  • python聚类算法解决方案(rest接口/mpp数据库/json数据/下载图片及数据)

    python聚类算法解决方案(rest接口/mpp数据库/json数据/下载图片及数据)

    这篇文章主要介绍了python聚类算法解决方案(rest接口/mpp数据库/json数据/下载图片及数据),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2019-08-08
  • Django之importlib模块的具体使用

    Django之importlib模块的具体使用

    本文主要介绍了Django之importlib模块的具体使用,importlib模块是Python中用于动态加载和导入模块的内置模块,有需要了解jquery event事件用法的朋友可参考
    2023-11-11
  • python解析html开发库pyquery使用方法

    python解析html开发库pyquery使用方法

    PyQuery是一个类似于jQuery的Python库,也可以说是jQuery在Python上的实现,能够以jQuery的语法来操作解析 HTML 文档,易用性和解析速度都很好
    2014-02-02
  • Python实现的选择排序算法示例

    Python实现的选择排序算法示例

    这篇文章主要介绍了Python实现的选择排序算法,结合实例形式分析了Python选择排序的概念、原理及简单实现技巧,需要的朋友可以参考下
    2017-11-11
  • 在keras里实现自定义上采样层

    在keras里实现自定义上采样层

    这篇文章主要介绍了在keras里实现自定义上采样层,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-06-06
  • 基于python实现简单日历

    基于python实现简单日历

    这篇文章主要为大家详细介绍了基于python实现简单日历,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-07-07
  • Python元组拆包和具名元组解析实例详解

    Python元组拆包和具名元组解析实例详解

    这篇文章主要介绍了Python元组拆包和具名元组解析,下面的内容就围绕元组作为数据记录属性展开,并介绍带字段名的具名元组函数namedtuple,列表属性不再本文中叙述。
    2018-03-03
  • python 实现人和电脑猜拳的示例代码

    python 实现人和电脑猜拳的示例代码

    这篇文章主要介绍了python 实现人和电脑猜拳的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-03-03
  • Python中__new__与__init__方法的区别详解

    Python中__new__与__init__方法的区别详解

    这篇文章主要介绍了Python中__new__与__init__方法的区别,是Python学习中的基础知识,需要的朋友可以参考下
    2015-05-05
  • 人生苦短我用python python如何快速入门?

    人生苦短我用python python如何快速入门?

    这篇文章主要教大家如何快速入门python,一个简短而全面的入门教程带你走入Python的大门,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-03-03

最新评论