Go to the documentation of this file.00001
00002
00003 import rospy
00004 from roslib import message
00005 import sensor_msgs.point_cloud2
00006 from std_msgs.msg import String
00007 from std_msgs.msg import Header
00008 from geometry_msgs.msg import Point
00009 from sensor_msgs.msg import PointCloud2, PointField
00010 import geometry_msgs.msg
00011 import math
00012 import PyKDL
00013
00014
00015 import tf
00016 import tf2_ros
00017
00018 def transform_to_kdl(t):
00019 return PyKDL.Frame(PyKDL.Rotation.Quaternion(t.transform.rotation.x, t.transform.rotation.y,
00020 t.transform.rotation.z, t.transform.rotation.w),
00021 PyKDL.Vector(t.transform.translation.x,
00022 t.transform.translation.y,
00023 t.transform.translation.z))
00024
00025
00026 def do_transform_cloud(cloud, transform):
00027 res = pc2.create_cloud(cloud.header, cloud.fields, pc2.read_points(cloud))
00028 t_kdl = transform_to_kdl(transform)
00029 for p_in, p_out in [ pc2.read_points(cloud), pc2.read_points(res) ]:
00030 p = t_kdl * PyKDL.Vector(p_in.x, p_in.y, p_in.z)
00031 p_out.x = p[0]
00032 p_out.y = p[1]
00033 p_out.z = p[2]
00034 res.header = transform.header
00035 return res
00036 tf2_ros.TransformRegistration().add(PointCloud2, do_transform_cloud)
00037
00038 def FeatureTrackerMockup():
00039 publisher = rospy.Publisher('/feat_tracker/state', PointCloud2, queue_size=10)
00040 rospy.init_node('talker', anonymous=True)
00041 rate = rospy.Rate(1)
00042 fake_tracked_feats = PointCloud2()
00043 header = Header()
00044 point = Point()
00045
00046 cloud = [[1,2,3],[4,5,6],[7,8,9]]
00047
00048 fake_tracked_feats = pc2.create_cloud_xyz32(fake_tracked_feats.header, cloud)
00049
00050 fake_tracked_feats.header.frame_id = 'camera_rgb_optical_frame'
00051
00052 publisher.publish(fake_tracked_feats)
00053 rate.sleep()
00054
00055 transform = geometry_msgs.msg.TransformStamped()
00056 transform.transform.translation.x = 0.1
00057 transform.transform.translation.y = 0.05
00058 transform.transform.translation.z = 0.1
00059 q = tf.transformations.quaternion_from_euler(0, 0, math.pi/2)
00060 transform.transform.rotation.x = q[0]
00061 transform.transform.rotation.y = q[1]
00062 transform.transform.rotation.z = q[2]
00063 transform.transform.rotation.w = q[3]
00064
00065 while not rospy.is_shutdown():
00066 cloud_out = do_transform_cloud(fake_tracked_feats, transform.transform)
00067 fake_tracked_feats.header.stamp = rospy.Time.now()
00068 publisher.publish(fake_tracked_feats)
00069 rate.sleep()
00070
00071 if __name__ == '__main__':
00072 try:
00073 FeatureTrackerMockup()
00074 except rospy.ROSInterruptException:
00075 pass