python实现nao机器人手臂动作控制
本文实例为大家分享了python实现nao机器人手臂动作的具体代码,供大家参考,具体内容如下
这些天依然在看nao公司文档的东西,把读过的代码顺手敲了出来。代码依然很简单,但是为什么我要写博客呢?这其中有很大的原因在于,代码是死的,可是读着读着就感觉代码活了,而且,每次读都会有不同的感受。咱就直接看正题吧。
#-*-encoding:UTF-8-*-
importsys
importmotion
importalmath
fromnaoqiimportALProxy
defStiffnessOn(proxy):
#weusethebodynametosignifythecollectionofalljionts
pName="Body"
pStiffnessLists=1.0
pTimeLists=1.0
proxy.stiffnessInterpolation(pName,pStiffnessLists,pTimeLists)
defmain(robotIP):
'''exampleshowingapathoftwoposition
'''
try:
motionProxy=ALProxy("ALMotion",robotIP,9559)
exceptException,e:
print"couldnotcreateaproxytoalmotion"
printstr(e)
try:
postureProxy=ALProxy("ALRobotPosture",robotIP,9559)
exceptException,e:
print"couldnotcreateaproxytoalRobotPosture"
printstr(e)
#setthenaostiffnesson
StiffnessOn(motionProxy)
#setthenaotostandinit
postureProxy.goToPosture("StandInit",0.5)
effector="LArm"
space=motion.FRAME_ROBOT
#AXIS_MASK_VEL=7
axisMask=almath.AXIS_MASK_VEL
isAbsolute=False
#sinceweareinrelative,thecurrentpositioniszero
currentPos=[0.0,0.0,0.0,0.0,0.0,0.0]
#definethechangesinrelativetothecurrentposition
dx=0.03#translationaxisx
dy=0.03#translationaxisy
dz=0.00#translationaxisz
dwx=0.00#rotationaxisx
dwy=0.00#rotationaxisx
dwz=0.00#rotationaxisx
targetPos=[dx,dy,dz,dwx,dwy,dwz]
#gotothetargetandbackagain
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"
iflen(sys.argv)<=1:
print"usedefault:127.0.0.1"
else:
robotIP=sys.argv[1]
main(robotIP)
接下来是另一个:
#-*-encoding:UTF-8-*-
'''Cartesiancontrol:armtrajectoryexample'''
importsys
importmotion
importalmath
fromnaoqiimportALProxy
defStiffnessOn(proxy):
pName="Body"
pStiffnessLists=1.0
pTimeLists=1.0
proxy.stiffnessInterpolation(pName,pStiffnessLists,pTimeLists)
defmain(robotIP):
'''showingahandellipoid
'''
try:
motionProxy=ALProxy("ALProxy",robotIP,9559)
exceptException,e:
print"couldnotcreateaproxy"
print"errorwas",e
try:
postureProxy=ALProxy("ALRobotProxy",robotIP,9559)
exceptException,e:
print"couldnotcreateaproxy"
print"errorwas",e
#sendnaoinstiffnesson
setStiffnessOn(motionProxy)
#sendnaotoposeinit
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"
iflen(sys.argv)<=1:
print"usagelocalip"
else:
robotIP=sys.argv[1]
main(robotIP)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。