FeatureTrackerMockup.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # license removed for brevity
3 import rospy
4 from roslib import message
6 from std_msgs.msg import String
7 from std_msgs.msg import Header
8 from geometry_msgs.msg import Point
9 from sensor_msgs.msg import PointCloud2, PointField
10 import geometry_msgs.msg
11 import math
12 import PyKDL
13 
14 # Because of transformations
15 import tf
16 import tf2_ros
17 
19  return PyKDL.Frame(PyKDL.Rotation.Quaternion(t.transform.rotation.x, t.transform.rotation.y,
20  t.transform.rotation.z, t.transform.rotation.w),
21  PyKDL.Vector(t.transform.translation.x,
22  t.transform.translation.y,
23  t.transform.translation.z))
24 
25 # PointStamped
26 def do_transform_cloud(cloud, transform):
27  res = pc2.create_cloud(cloud.header, cloud.fields, pc2.read_points(cloud))
28  t_kdl = transform_to_kdl(transform)
29  for p_in, p_out in [ pc2.read_points(cloud), pc2.read_points(res) ]:
30  p = t_kdl * PyKDL.Vector(p_in.x, p_in.y, p_in.z)
31  p_out.x = p[0]
32  p_out.y = p[1]
33  p_out.z = p[2]
34  res.header = transform.header
35  return res
36 tf2_ros.TransformRegistration().add(PointCloud2, do_transform_cloud)
37 
39  publisher = rospy.Publisher('/feat_tracker/state', PointCloud2, queue_size=10)
40  rospy.init_node('talker', anonymous=True)
41  rate = rospy.Rate(1) # 10hz
42  fake_tracked_feats = PointCloud2()
43  header = Header()
44  point = Point()
45 
46  cloud = [[1,2,3],[4,5,6],[7,8,9]]
47 
48  fake_tracked_feats = pc2.create_cloud_xyz32(fake_tracked_feats.header, cloud)
49 
50  fake_tracked_feats.header.frame_id = 'camera_rgb_optical_frame'
51 
52  publisher.publish(fake_tracked_feats)
53  rate.sleep()
54 
55  transform = geometry_msgs.msg.TransformStamped()
56  transform.transform.translation.x = 0.1
57  transform.transform.translation.y = 0.05
58  transform.transform.translation.z = 0.1
59  q = tf.transformations.quaternion_from_euler(0, 0, math.pi/2)
60  transform.transform.rotation.x = q[0]
61  transform.transform.rotation.y = q[1]
62  transform.transform.rotation.z = q[2]
63  transform.transform.rotation.w = q[3]
64 
65  while not rospy.is_shutdown():
66  cloud_out = do_transform_cloud(fake_tracked_feats, transform.transform)
67  fake_tracked_feats.header.stamp = rospy.Time.now()
68  publisher.publish(fake_tracked_feats)
69  rate.sleep()
70 
71 if __name__ == '__main__':
72  try:
74  except rospy.ROSInterruptException:
75  pass
def do_transform_cloud(cloud, transform)


feature_tracker
Author(s): Roberto Martín-Martín
autogenerated on Mon Jun 10 2019 14:06:08