python控制nao机器人身体动作实例详解

作者:Earl_Martin 时间:2023-08-26 11:33:17 

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

今天读的代码,顺便写了出来,与文档的对比,差不多。


import sys
import motion
import almath
import naoqi from ALProxy

def StiffnessOn(proxy):
       pName="Body"
       pStiffnessLists
       pTime=1.0
       proxy.stiffnessInterpolation(pName,pStiffnessLists,pTime)

def main(robotIP):
       try:
              motionProxy=ALProxy("ALMotion",robotIP,9559)
       except Exception,e:
              print:"could not create a proxy!"
              print:"error is ",e

try:
              postureProxy=ALProxy("ALRobotPosture",robotIP,9559)
       except Exception,e:
              print:"could not create a proxy!"
              print:"error is ",e

StiffnessOn(motionProxy)
       postureProxy.goToPosture("StandInit",0.5)

space=motion.FRAME_ROBOT
       coef=0.5
       times=[coef,2.0*coef,3.0*coef,4.0*coef]
       isAbsolute=False
       dy=+0.06
       dz=-0.03
       dwx==+0.30

effector="Torso"
       path=[
              [0.0,-dy,dz,-dwx,0.0,0.0],
              [0.0,0.0,0.0,0.0,0.0,0.0],
              [0.0,+dy,dz,+dwx,0.0,0.0],
              [0.0,0.0,0.0,0.0,0.0,0.0]
             ]

axisMask=almath.AXIS_MASK_ALL
       motionProxy.post.postionInterpolation(effector,space,path,times,isAbsolute)

#motion of arms with block process
       axisMask=almath.AXIS_MASK_VEL
       times=[1.0*coef,2.0*coef]
       dy=+0.03
       effecor="RArm"
       path=[
              [0.0,dy,0.0,0.0,0.0,0.0],
              [0.0,0.0,0.0,0.0,0.0,0.0]
             ]
       motionProxy.positionInterpolation(effector,space,path,axisMask,times,inAbsolute)

if __name__=="__main__":
       robotIP="127.0.0.1"

if len(sys.argv)<=1:
              print"useage default robotIP"
       else:
              robotIP=sys.arv[1]
       main(robotIP)

实例二,控制左右胳膊


#-*-encoding:UTF-8 -*-

import sys
import motion
import almath
form naoqi import ALProxy

def StiffnessOn(proxy):
       pName="Body"
       pStiffnessLists=1.0
       pTimeLists=1.0
       proxy.stiffnessInterpolation(pName,pStiffnessLists,pTimeLists)

def main(robotIP):

#create a proxy to almtion
       try:
              motionProxy=ALProxy("ALMotion",robotIP,9559)
       except Exception,e:
              print "could not create a proxy"
              print "error is ",e

#create a proxy to alrobotposture
       try:
              postureProxy=ALProxy("ALRobotPosture",robotIP,9559)
       except Exception,e:
              print "could not create a proxy"
              print "error is ",e

StiffnessOn(motionProxy)
       postureProxy.goToPosture("StandInit",0.5)
       space=motion.FRAME_ROBOT
       isAbsolute=False

effectorList=["LArm","RArm"]
       #motion of arms with block process
       axisMaskList=[almath.AXIS_MASK_VEL,almath.AXIS_MASK_VEL]
       timeLists=[[1.0],[1.0]]
       pathList=[  
                 [
                   [0.0,-0.04,0.0,0.0,0.0,0.0]],
                 [
                   [0.0,0.04,0.0,0.0,0.0,0.0]]
               ]
       motionProxy.positionInterpolation(effectorLists,space,pahtLists,axisMaskList,timeLists,isAbsolute)

effectorLists=["LArm","RArm","Torso"]
       axisMaskLists=[
              almath.AXIS_MASK_VEL,
              almath.AXIS_MASK_VEL,
              almath.AXIS_MASK_ALL
              ]
       timeLists=[
              [[0.0,0.0,0.0,0.0,0.0,0.0]],
              [[0.0,0.0,0.0,0.0,0.0,0.0]],
              [0.0,+dy,0.0,0.0,0.0,0.0],
              [0.0,-dy,0.0,0.0,0.0,0.0],
              [0.0,0.0,0.0,0.0,0.0,0.0]
              ]
       motionProxy.positionInterpolations(effectorList,space,pathList,axisMaskList,timeList,isAbsolute)

if __name__=="__main__":
       robotIP="127.0.0.1"
       if(sys.argv<1):
              print"usege default ip"
       else:
              robotIP=sys.arv[1]
       main(robotIP)

感受:

这些小的程序最不好处理的就是path中的数据了。这些数据是怎么获得的?最大的可能就是在choregraph中3D视图中测试得到,当然还有一种可能就是将choregraph与实体机连接,将机器人置于practice状态,这样操作来获得数据。后者操作性更强,但由于实际原因,用前者的可能性是最大的。

来源:https://blog.csdn.net/u011181878/article/details/21618239

标签:python,nao,机器人
0
投稿

猜你喜欢

  • fso怎样判断一个盘上是否有文件

    2007-09-26 12:35:00
  • 学习Python3 Dlib19.7进行人脸面部识别

    2022-03-18 00:01:30
  • python实现烟花小程序

    2022-10-02 09:45:23
  • OpenCV半小时掌握基本操作之分水岭算法

    2023-04-10 11:24:51
  • 在Python程序中进行文件读取和写入操作的教程

    2023-05-22 10:31:56
  • Python标准库之Math,Random模块使用详解

    2021-02-09 22:33:13
  • 微信小程序实战之仿android fragment可滑动底部导航栏(4)

    2023-07-02 16:22:38
  • thinkphp实现发送邮件密码找回功能实例

    2024-05-02 17:16:54
  • 理解JavaScript变量作用域更轻松

    2024-04-16 09:25:07
  • Python实现AI自动抠图实例解析

    2021-12-25 11:04:22
  • 如何实现删除numpy.array中的行或列

    2022-05-09 14:55:03
  • Go 自定义error错误的处理方法

    2024-02-16 09:03:45
  • Python利用matplotlib模块数据可视化绘制3D图

    2023-07-25 07:48:24
  • 教你怎么用Python实现GIF动图的提取及合成

    2023-11-29 14:16:15
  • 简述:我为什么选择Python而不是Matlab和R语言

    2021-05-13 06:51:27
  • python3.6+selenium实现操作Frame中的页面元素

    2023-10-13 01:37:00
  • Vue网页html转换PDF(最低兼容ie10)的思路详解

    2024-06-07 15:25:12
  • numpy中loadtxt 的用法详解

    2022-03-21 09:46:39
  • 深入解析Linux下MySQL数据库的备份与还原

    2024-01-25 14:57:22
  • JS实现键值对遍历json数组功能示例

    2024-04-10 10:52:40
  • asp之家 网络编程 m.aspxhome.com