-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdown_sampled_camera_frequency.py
More file actions
44 lines (39 loc) · 1.42 KB
/
down_sampled_camera_frequency.py
File metadata and controls
44 lines (39 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import rclpy
from rclpy.node import Node
from sensor_msgs.msg import Image
from rclpy.qos import QoSProfile, QoSReliabilityPolicy, QoSHistoryPolicy
class DownsampledCameraNode(Node):
def __init__(self):
super().__init__('downsampled_camera_node')
qos_profile = QoSProfile(
reliability=QoSReliabilityPolicy.BEST_EFFORT,
history=QoSHistoryPolicy.KEEP_LAST,
depth=10
)
self.original_sub = self.create_subscription(
Image,
'/wilbur/forward/color/image_rect_color',
self.image_callback,
qos_profile
)
self.downsampled_pub = self.create_publisher(
Image,
'/wilbur/forward/color/image_rect_color/down_sampled',
10
)
self.timer = self.create_timer(1.0/15.0, self.timer_callback) # 15 Hz (1/15 seconds interval)
self.latest_image = None
def image_callback(self, msg):
self.latest_image = msg
def timer_callback(self):
if self.latest_image is not None:
self.downsampled_pub.publish(self.latest_image)
self.latest_image = None # Reset to avoid republishing the same image
def main(args=None):
rclpy.init(args=args)
downsampled_camera_node = DownsampledCameraNode()
rclpy.spin(downsampled_camera_node)
downsampled_camera_node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()