From 761a8cb923986cbec30857e1c3d58b7c6d1597d2 Mon Sep 17 00:00:00 2001 From: homalozoa Date: Thu, 24 Oct 2024 20:35:13 +0800 Subject: [PATCH] fix: porting to new rclcpp service template API Signed-off-by: homalozoa --- ch4/service/ch4_service_cpp/CMakeLists.txt | 5 +++++ ch4/service/ch4_service_cpp/src/single_node.cpp | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/ch4/service/ch4_service_cpp/CMakeLists.txt b/ch4/service/ch4_service_cpp/CMakeLists.txt index 17cd88e..ef142d4 100644 --- a/ch4/service/ch4_service_cpp/CMakeLists.txt +++ b/ch4/service/ch4_service_cpp/CMakeLists.txt @@ -9,6 +9,11 @@ endif() find_package(ament_cmake REQUIRED) find_package(rclcpp REQUIRED) +set(ROS_DISTRO $ENV{ROS_DISTRO}) +if(${ROS_DISTRO} STREQUAL "rolling") + add_compile_definitions(NEW_SERVICE_TEMPLATE) +endif() + set(executable_selfservice self_exec) set(executable_selfnode self_node) diff --git a/ch4/service/ch4_service_cpp/src/single_node.cpp b/ch4/service/ch4_service_cpp/src/single_node.cpp index e6ee41d..9ab8c4c 100644 --- a/ch4/service/ch4_service_cpp/src/single_node.cpp +++ b/ch4/service/ch4_service_cpp/src/single_node.cpp @@ -45,7 +45,11 @@ class SingleNode : public rclcpp::Node server_ = this->create_service( "get_para", std::bind(&SingleNode::service_callback, this, std::placeholders::_1, std::placeholders::_2), + #ifdef NEW_SERVICE_TEMPLATE + rclcpp::ServiceQoS(), + #else rmw_qos_profile_services_default, + #endif cb_group_); }