sample_topic_ensync_for_capture_stereo_synchronizer.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import division
4 
5 from geometry_msgs.msg import PoseStamped
6 from pcl_msgs.msg import PointIndices
7 import rospy
8 from sensor_msgs.msg import CameraInfo
9 from sensor_msgs.msg import Image
10 from stereo_msgs.msg import DisparityImage
11 
12 
14 
15  def __init__(self):
16  self.pub_pose = rospy.Publisher(
17  '~output/pose', PoseStamped, queue_size=1)
18  self.pub_mask = rospy.Publisher(
19  '~output/mask', Image, queue_size=1)
20  self.pub_mask_indices = rospy.Publisher(
21  '~output/mask_indices', PointIndices, queue_size=1)
22  self.pub_left_image = rospy.Publisher(
23  '~output/left_image', Image, queue_size=1)
24  self.pub_left_camera_info = rospy.Publisher(
25  '~output/left_camera_info', CameraInfo, queue_size=1)
26  self.pub_right_camera_info = rospy.Publisher(
27  '~output/right_camera_info', CameraInfo, queue_size=1)
28  self.pub_disparity = rospy.Publisher(
29  '~output/disparity', DisparityImage, queue_size=1)
30 
31  self.latest_pose = None
32  self.latest_mask = None
33  self.latest_mask_indices = None
34  self.latest_left_image = None
37  self.latest_disparity = None
38 
39  rospy.Subscriber('~input/pose', PoseStamped, self._pose_cb)
40  rospy.Subscriber('~input/mask', Image, self._mask_cb)
41  rospy.Subscriber('~input/mask_indices', PointIndices, self._indices_cb)
42  rospy.Subscriber('~input/left_image', Image, self._left_image_cb)
43  rospy.Subscriber(
44  '~input/left_camera_info', CameraInfo, self._left_camera_info_cb)
45  rospy.Subscriber(
46  '~input/right_camera_info', CameraInfo, self._right_camera_info_cb)
47  rospy.Subscriber(
48  '~input/disparity', DisparityImage, self._disparity_cb)
49 
50  r = rospy.Rate(rospy.get_param('~rate', 10))
51  while not rospy.is_shutdown():
52  self._publish()
53  try:
54  r.sleep()
55  except rospy.ROSTimeMovedBackwardsException:
56  pass
57 
58  def _pose_cb(self, msg):
59  self.latest_pose = msg
60 
61  def _mask_cb(self, msg):
62  self.latest_mask = msg
63 
64  def _indices_cb(self, msg):
65  self.latest_mask_indices = msg
66 
67  def _left_image_cb(self, msg):
68  self.latest_left_image = msg
69 
70  def _left_camera_info_cb(self, msg):
71  self.latest_left_camera_info = msg
72 
73  def _right_camera_info_cb(self, msg):
74  self.latest_right_camera_info = msg
75 
76  def _disparity_cb(self, msg):
77  self.latest_disparity = msg
78 
79  def _publish(self):
80  if self.latest_pose is None or \
81  self.latest_mask is None or \
82  self.latest_mask_indices is None or \
83  self.latest_left_image is None or \
84  self.latest_left_camera_info is None or \
85  self.latest_right_camera_info is None or \
86  self.latest_disparity is None:
87  return
88 
89  now = rospy.Time.now()
90  self.latest_pose.header.stamp = now
91  self.latest_mask.header.stamp = now
92  self.latest_mask_indices.header.stamp = now
93  self.latest_left_image.header.stamp = now
94  self.latest_left_camera_info.header.stamp = now
95  self.latest_right_camera_info.header.stamp = now
96  self.latest_disparity.header.stamp = now
97 
98  self.pub_pose.publish(self.latest_pose)
99  self.pub_mask.publish(self.latest_mask)
100  self.pub_mask_indices.publish(self.latest_mask_indices)
101  self.pub_left_image.publish(self.latest_left_image)
102  self.pub_left_camera_info.publish(self.latest_left_camera_info)
103  self.pub_right_camera_info.publish(self.latest_right_camera_info)
104  self.pub_disparity.publish(self.latest_disparity)
105 
106 
107 if __name__ == '__main__':
108  rospy.init_node('sample_topic_ensync_for_capture_stereo_synchronizer')
110  rospy.spin()


jsk_pcl_ros
Author(s): Yohei Kakiuchi
autogenerated on Mon May 3 2021 03:03:47