-
Notifications
You must be signed in to change notification settings - Fork 275
Open
Description
Hello,
Yesterday, I encountered something non deterministic with destroying subscribers. I have a subscriber that I instantiate and then destroy after a task. Then, maybe 3 minutes later, I did the same thing and got the issue that you saw in the title.
My code is the following
from task_execution.command.command import *
import os
import cv2
from cv_bridge import CvBridge
from sensor_msgs.msg import CompressedImage
from rclpy.qos import QoSProfile, QoSReliabilityPolicy, QoSHistoryPolicy, QoSDurabilityPolicy
class TakePicture(Command):
def __init__(self, path_images, name_task, executor):
super().__init__()
self.path_images = path_images
self.name_task = name_task
self.image = None
self.executor = executor
self.br = CvBridge()
self.qos_profile = QoSProfile(
reliability=QoSReliabilityPolicy.BEST_EFFORT,
durability=QoSDurabilityPolicy.VOLATILE,
history=QoSHistoryPolicy.KEEP_LAST,
depth=1,
)
self.sub_camera = self.executor.create_subscription(
CompressedImage, "/ROVER/feed_camera_hd_0", self.take_picture, qos_profile=self.qos_profile)
def execute(self):
current_frame = self.br.compressed_imgmsg_to_cv2(self.image)
name = self.name_task + str(time.strftime("%Y-%m-%d_%H:%M:%S", time.localtime())) + '.png'
image_dir = os.path.join(
'/home/xplore/dev_ws/photos_competition',
self.path_images
)
os.makedirs(image_dir, exist_ok=True)
image_path = os.path.join(image_dir, name)
cv2.imwrite(image_path, current_frame)
self.executor.destroy_subscription(self.sub_camera)
#self.sub_camera = None
def take_picture(self, image):
self.image = image
So in summary, I instantiate TakePicture() and call execute() one time and it works well. And then sometimes, when I do the same thing another time, so instantiate TakePicture() and call execute(), I got the error.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels