00001
00002 load('rosh_geometry', globals())
00003
00004 from lxml import etree
00005 from lxml.etree import Element
00006 import os
00007 from tf.transformations import quaternion_from_euler
00008 from math import pi
00009
00010 def make_tf_pub(parent, child, transform):
00011 attribs = dict(
00012 parent=parent,
00013 child=child,
00014 x=transform.pose.position.x,
00015 y=transform.pose.position.y,
00016 z=transform.pose.position.z,
00017 qx=transform.pose.orientation.x,
00018 qy=transform.pose.orientation.y,
00019 qz=transform.pose.orientation.z,
00020 qw=transform.pose.orientation.w
00021 )
00022 tr = Element(
00023 'node',
00024 type='static_transform_publisher',
00025 pkg='tf',
00026 name='%s_to_%s' % (parent, child),
00027 args='%(x)s %(y)s %(z)s %(qx)s %(qy)s %(qz)s %(qw)s %(parent)s %(child)s 100' % attribs
00028 )
00029 return tr
00030
00031 top_right = 'top_right'
00032 bottom_left = 'bottom_left'
00033
00034
00035 launch_tree = Element('launch')
00036 launch_tree.append(Element(
00037 'param',
00038 name='/screen/frame',
00039 value=bottom_left,
00040 ))
00041
00042
00043
00044 transforms._config.listener.waitForTransform(bottom_left, top_right, Time(0), Duration(5))
00045 parent = transforms[bottom_left]._config.listener.chain(bottom_left, Time(0), '/', Time(0), '/')[0]
00046 tr = transforms[parent](bottom_left)
00047 elem = make_tf_pub(parent, bottom_left, tr)
00048 launch_tree.append(elem)
00049
00050
00051 elem_pi = Element('arg', name='pi/2', value='1.5707963267948966')
00052 elem_optical_rotate = Element('arg', name='optical_rotate', value='0 0 0 -$(arg pi/2) 0 -$(arg pi/2)')
00053
00054 launch_tree.append(elem_pi)
00055 launch_tree.append(elem_optical_rotate)
00056
00057
00058 parent = 'projector_cam_rgb_optical_frame'
00059
00060 transform = PoseStamped(frame_id='world', position=Point(0,0,0.5), orientation=Quaternion(0,0,0,1))
00061 elem = make_tf_pub('world', 'projection_cam_link', transform)
00062 launch_tree.append(elem)
00063
00064
00065
00066
00067
00068 transform = PoseStamped(frame_id='world', position=Point(0,0,0.5), orientation=Quaternion(*quaternion_from_euler(-pi/2,0,-pi/2)))
00069
00070 elem_projection_cam_optical_rotate = Element(
00071 'node',
00072 type='static_transform_publisher',
00073 pkg='tf',
00074 name='projector_cam_optical_rotate',
00075 args='$(arg optical_rotate) projection_cam_link %s 100' % parent
00076 )
00077
00078 launch_tree.append(elem_projection_cam_optical_rotate)
00079
00080
00081
00082 orientation = quaternion_from_euler(0,0,pi)
00083 transform.pose.orientation = Quaternion(*orientation)
00084 transform.child_frame_id = 'face_cam_link'
00085 elem = make_tf_pub('world', 'face_cam_link', transform)
00086 launch_tree.append(elem)
00087
00088
00089 tr = transforms.bottom_left('top_right')
00090 width, height = tr.pose.position.x, tr.pose.position.y
00091
00092 launch_tree.append(Element(
00093 'param',
00094 name='/screen/width',
00095 value=str(width),
00096 type='double'
00097 ))
00098
00099 launch_tree.append(Element(
00100 'param',
00101 name='/screen/height',
00102 value=str(height),
00103 type='double'
00104 ))
00105
00106 rospy.set_param('/screen/width', str(width))
00107 rospy.set_param('/screen/height', str(height))
00108
00109
00110 import rospy
00111 while not rospy.has_param('/homography'):
00112 rospy.sleep(0.1)
00113
00114 homography = rospy.get_param('/homography')
00115 elem_h = Element('rosparam', param='/homography')
00116 elem_h.text = str(homography)
00117 launch_tree.append(elem_h)
00118
00119 launch_path = os.path.join(roslib.packages.get_pkg_dir('projector_interface'), 'study', 'launch', 'setup.launch')
00120
00121 with open(launch_path, 'w') as lf:
00122 lf.write(etree.tostring(launch_tree, pretty_print=True))
00123 print 'wrote', launch_path
00124
00125