forked from federicocorrao/Nao-Computer-Vision-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_whole_body_motion.py
More file actions
91 lines (71 loc) · 2.74 KB
/
example_whole_body_motion.py
File metadata and controls
91 lines (71 loc) · 2.74 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# -*- encoding: UTF-8 -*-
''' Whole Body Motion: Head orientation control '''
import sys
import time
import math
from naoqi import ALProxy
def StiffnessOn(proxy):
# We use the "Body" name to signify the collection of all joints
pNames = "Body"
pStiffnessLists = 1.0
pTimeLists = 1.0
proxy.stiffnessInterpolation(pNames, pStiffnessLists, pTimeLists)
def main(robotIP):
''' Example of a whole body head orientation control
Warning: Needs a PoseInit before executing
Whole body balancer must be inactivated at the end of the script
'''
# Init proxies.
try:
motionProxy = ALProxy("ALMotion", robotIP, 9559)
except Exception, e:
print "Could not create proxy to ALMotion"
print "Error was: ", e
try:
postureProxy = ALProxy("ALRobotPosture", robotIP, 9559)
except Exception, e:
print "Could not create proxy to ALRobotPosture"
print "Error was: ", e
# Set NAO in Stiffness On
StiffnessOn(motionProxy)
# Send NAO to Pose Init
postureProxy.goToPosture("StandInit", 0.5)
effectorName = "Head"
# Active Head tracking
isEnabled = True
motionProxy.wbEnableEffectorControl(effectorName, isEnabled)
# Example showing how to set orientation target for Head tracking
# The 3 coordinates are absolute head orientation in NAO_SPACE
# Rotation in RAD in x, y and z axis
# X Axis Head Orientation feasible movement = [-20.0, +20.0] degree
# Y Axis Head Orientation feasible movement = [-75.0, +70.0] degree
# Z Axis Head Orientation feasible movement = [-30.0, +30.0] degree
targetCoordinateList = [
[ 2.0, 00.0, 00.0], # target 0
[-20.0, 00.0, 00.0], # target 1
[ 00.0, +70.0, 00.0], # target 2
[ 00.0, +70.0, +30.0], # target 3
[ 00.0, +70.0, -30.0], # target 4
[ 00.0, -75.0, 00.0], # target 5
[ 00.0, -75.0, +30.0], # target 6
[ 00.0, -75.0, -30.0], # target 7
[ 00.0, 00.0, 00.0], # target 8
]
# wbSetEffectorControl is a non blocking function
# time.sleep allow head go to his target
# The recommended minimum period between two successives set commands is
# 0.2 s.
for targetCoordinate in targetCoordinateList:
targetCoordinate = [target*math.pi/180.0 for target in targetCoordinate]
motionProxy.wbSetEffectorControl(effectorName, targetCoordinate)
time.sleep(3.0)
# Deactivate Head tracking
isEnabled = False
motionProxy.wbEnableEffectorControl(effectorName, isEnabled)
if __name__ == "__main__":
robotIp = "127.0.0.1"
if len(sys.argv) <= 1:
print "Usage python motion_wbEffectorControlHead.py robotIP (optional default: 127.0.0.1)"
else:
robotIp = sys.argv[1]
main(robotIp)