ros2 / message_filters

BSD 3-Clause "New" or "Revised" License
76 stars 66 forks source link

create subscriber with message memory strategy #98

Open Derekglk opened 1 year ago

Derekglk commented 1 year ago

Hello,

My ROS2 node subscribes to two topics (left_image and right_image), and has a message filter (sync_exact policy) to get sychronized data.

Now I'm working on a custom memory allocator (following this tutorial), and in this example an rclcpp::message_memory_strategy has to be specified when creating the node subsription.

rclcpp::SubscriptionOptionsWithAllocator<Alloc> subscription_options;
auto msg_mem_strat = std::make_shared<rclcpp::message_memory_strategy::MessageMemoryStrategy<
       std_msgs::msg::UInt32, Alloc>>(alloc);
auto subscriber = node->create_subscription<std_msgs::msg::UInt32>(
       "allocator_tutorial", 10, callback, subscription_options, msg_mem_strat);

However I can't find a constructor in message_filters::Subscriber which takes message memory strategy as input. This is what I have right now, and should be changed to using custom memory allocator.

message_filters::Subscriber<sensor_msgs::msg::Image> left_img;  
message_filters::Subscriber<sensor_msgs::msg::Image> right_img;   
std::shared_ptr<message_filters::Synchronizer<exact_policy>> syncExact;
left_img.subscribe(this, left_topic, custom_qos_profile);
right_img.subscribe(this, right_topic, custom_qos_profile);
syncExact = std::make_shared<message_filters::Synchronizer<exact_policy>>(exact_policy(10), left_img, right_img);  
syncExact->registerCallback(exact_sync_callback);

Am I following the right approach? How to specify the message memory strategy when using message filter?

Thank you very much!

Best Regards.

Derek

clalancette commented 1 year ago

This feature is likely missing from message_filters, so would need to be added. We probably won't work on this right now, but if you'd like to contribute a pull request we'd be happy to review it.