use newer 'message_filters::Subscriber' constructor API

This commit is contained in:
Christian Rauch
2026-07-24 10:53:27 +02:00
parent e018369304
commit 75636938cc
3 changed files with 25 additions and 3 deletions
+4
View File
@@ -53,6 +53,10 @@ endforeach()
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
find_package(OpenSSL REQUIRED) find_package(OpenSSL REQUIRED)
if(message_filters_VERSION VERSION_GREATER_EQUAL 5.0)
add_compile_definitions(message_filters_QoS)
endif()
if(USE_RK_HW_DECODER) if(USE_RK_HW_DECODER)
pkg_search_module(RK_MPP REQUIRED rockchip_mpp) pkg_search_module(RK_MPP REQUIRED rockchip_mpp)
if(NOT RK_MPP_FOUND) if(NOT RK_MPP_FOUND)
+7 -1
View File
@@ -79,13 +79,19 @@ class ImageSyncNode : public rclcpp::Node {
rclcpp::QoS qos{rclcpp::KeepLast(queue_size_)}; rclcpp::QoS qos{rclcpp::KeepLast(queue_size_)};
qos.reliable(); qos.reliable();
#ifdef message_filters_QoS
const rclcpp::QoS qos_prof = qos;
#else
const rmw_qos_profile_t qos_prof = qos.get_rmw_qos_profile();
#endif
if (sync_topics_.size() == 1) { if (sync_topics_.size() == 1) {
single_sub_ = this->create_subscription<Image>( single_sub_ = this->create_subscription<Image>(
sync_topics_.front(), qos, sync_topics_.front(), qos,
[this](const ImageConstPtr msg) { this->handle_synced_images({msg}); }); [this](const ImageConstPtr msg) { this->handle_synced_images({msg}); });
} else { } else {
for (size_t i = 0; i < sync_topics_.size(); ++i) { for (size_t i = 0; i < sync_topics_.size(); ++i) {
subscribers_[i].subscribe(this, sync_topics_[i], qos.get_rmw_qos_profile()); subscribers_[i].subscribe(this, sync_topics_[i], qos_prof);
} }
create_synchronizer(); create_synchronizer();
} }
+14 -2
View File
@@ -30,9 +30,21 @@ D2CViewer::D2CViewer(rclcpp::Node* const node, rmw_qos_profile_t rgb_qos,
rmw_qos_profile_t depth_qos, bool use_intra_process) rmw_qos_profile_t depth_qos, bool use_intra_process)
: node_(node), logger_(rclcpp::get_logger("d2c_viewer")), is_active_(true) { : node_(node), logger_(rclcpp::get_logger("d2c_viewer")), is_active_(true) {
rgb_sub_ = std::make_shared<message_filters::Subscriber<sensor_msgs::msg::Image>>( rgb_sub_ = std::make_shared<message_filters::Subscriber<sensor_msgs::msg::Image>>(
node_, "color/image_raw", rgb_qos); node_, "color/image_raw",
#ifdef message_filters_QoS
rclcpp::QoS{rclcpp::QoSInitialization::from_rmw(rgb_qos), rgb_qos}
#else
rgb_qos
#endif
);
depth_sub_ = std::make_shared<message_filters::Subscriber<sensor_msgs::msg::Image>>( depth_sub_ = std::make_shared<message_filters::Subscriber<sensor_msgs::msg::Image>>(
node_, "depth/image_raw", depth_qos); node_, "depth/image_raw",
#ifdef message_filters_QoS
rclcpp::QoS{rclcpp::QoSInitialization::from_rmw(depth_qos), depth_qos}
#else
depth_qos
#endif
);
sync_ = std::make_shared<message_filters::Synchronizer<MySyncPolicy>>(MySyncPolicy(10), *rgb_sub_, sync_ = std::make_shared<message_filters::Synchronizer<MySyncPolicy>>(MySyncPolicy(10), *rgb_sub_,
*depth_sub_); *depth_sub_);
sync_->setMaxIntervalDuration(rclcpp::Duration::from_seconds(1.0)); // 1s sync_->setMaxIntervalDuration(rclcpp::Duration::from_seconds(1.0)); // 1s