test_cam_transform.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import sys
3 import roslib
4 roslib.load_manifest('nao_description')
5 import rospy
6 import tf
7 import numpy as np
8 from tf import TransformListener
9 from tf import transformations
10 
11 try:
12  import motion
13  from naoqi import ALProxy
14 except ImportError:
15  print("Error importing NaoQI. Please make sure that Aldebaran's NaoQI API is in your PYTHONPATH.")
16  exit(1)
17 
18 
19 # bla
20 def space_to_str(space):
21  if space == motion.SPACE_TORSO:
22  return "Torso"
23  elif space == motion.SPACE_WORLD:
24  return "Odom"
25  elif space == motion.SPACE_NAO:
26  return "BaseFootprint"
27 
28 def transform_to_str(result):
29  tstr = ''
30  maxColumnWidth = 20
31  for i in range(0,4):
32  row = result[4*i:4*i+4]
33  rstr = ''.join(["%s" %str(k).center(maxColumnWidth) for k in (row)] )
34  rstr = rstr + '\n'
35  tstr = tstr+rstr
36  #tstr.append('\n')
37  return tstr
38 
40  mm = list()
41  for i in range(0,4):
42  for j in range(0,4):
43  mm.append(m[i,j])
44 
45  return transform_to_str(mm)
46 
48  return np.matrix('0 0 1 0;-1 0 0 0; 0 -1 0 0; 0 0 0 1')
49 
50 if __name__ == '__main__':
51  rospy.init_node('test_tf')
52  listener = TransformListener()
53  ip = "ra.local"
54  port = 9559
55  proxy = ALProxy("ALMotion", ip, port)
56  print "motionproxy ready"
57  space = motion.SPACE_TORSO
58  chainName = "Head"
59  currentSensor = proxy.getPosition(chainName, space, True)
60  current = proxy.getPosition(chainName, space, False)
61  print "Position of %s in space %s:"%(chainName, space_to_str(space))
62  print currentSensor
63  print current
64  rpy = currentSensor[3:]
65  print rpy
66  DCM = apply(transformations.euler_matrix,rpy)
67  print DCM
68  tTHSensor = proxy.getTransform(chainName, space, True)
69  tTH = proxy.getTransform(chainName, space, False)
70  print "Transform %s to %s:"%(space_to_str(space),chainName)
71  print transform_to_str(tTHSensor)
72  #print transform_to_str(tTH)
73  chainName = "CameraTop"
74  tTCSensor = proxy.getTransform(chainName, space, True)
75  tTC = proxy.getTransform(chainName, space, False)
76  print "Transform %s to %s:"%(space_to_str(space),chainName)
77  print transform_to_str(tTCSensor)
78  print
79  T = np.matrix([tTCSensor[0:4],tTCSensor[4:8],tTCSensor[8:12],tTCSensor[12:]])
80  #print cam_rotation_matrix()
81  DCM = T*cam_rotation_matrix()
82  print "Transform %s to %s (with rotated coordinate frame):"%(space_to_str(space),chainName)
83  print np_mat_to_str(DCM)
84 
85  stamp = rospy.Time()
86  frame1 = 'Torso_link'
87  frame2 = 'CameraTop_frame'
88  try:
89  listener.waitForTransform(frame1,frame2,stamp,rospy.Duration(1.0))
90  (trans,rot) = listener.lookupTransform(frame1,frame2,stamp)
91  except tf.Exception as e:
92  print "ERROR using TF"
93  print "%s"%(e)
94  sys.exit(-1)
95 
96  m = transformations.quaternion_matrix(rot)
97  for i in range(0,3):
98  m[i,3] = trans[i]
99  print "[tf] Transform %s to %s:"%(frame1,frame2)
100  print np_mat_to_str(m)
101 
102  e = np.linalg.norm(DCM - m)
103  print "Error is: ",e
104  if e > 1e-5:
105  print "ERROR: Something is wrong with your TF transformations. Transforms do not match!"
106  else:
107  print "Test ok. Done"
108 
109 
def transform_to_str(result)


nao_description
Author(s): Armin Hornung, Stefan Osswald
autogenerated on Mon Jun 10 2019 14:05:03