python实现nao机器人手臂动作控制
程序员文章站
2023-11-28 20:38:16
本文实例为大家分享了python实现nao机器人手臂动作的具体代码,供大家参考,具体内容如下
这些天依然在看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)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: PS制作医馆笑传宣传海报过程全解
下一篇: python机器人运动范围问题的解答