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

时间:2022-12-12 15:36:11

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

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)

实例二,控制左右胳膊

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#-*-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