From 6bbc6b7d7161fb2d5af082497bea8e5a7140bec1 Mon Sep 17 00:00:00 2001 From: Autumn60 Date: Fri, 28 Jun 2024 21:22:09 +0900 Subject: [PATCH 1/3] create NoCallSubscription wrapper class Signed-off-by: Autumn60 --- src/wheel_stuck_utils/CMakeLists.txt | 26 ++++++++++ .../ros/no_callback_subscription.hpp | 49 +++++++++++++++++++ src/wheel_stuck_utils/package.xml | 20 ++++++++ 3 files changed, 95 insertions(+) create mode 100644 src/wheel_stuck_utils/CMakeLists.txt create mode 100644 src/wheel_stuck_utils/include/wheel_stuck_utils/ros/no_callback_subscription.hpp create mode 100644 src/wheel_stuck_utils/package.xml diff --git a/src/wheel_stuck_utils/CMakeLists.txt b/src/wheel_stuck_utils/CMakeLists.txt new file mode 100644 index 0000000..728e713 --- /dev/null +++ b/src/wheel_stuck_utils/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.5) +project(wheel_stuck_utils) + +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_EXTENSIONS OFF) +endif() + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +find_package(ament_cmake_auto REQUIRED) +ament_auto_find_build_dependencies() + +ament_auto_add_library(autoware_universe_utils SHARED + src/hoge.cpp +) + +if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + ament_lint_auto_find_test_dependencies() +endif() + +ament_auto_package() \ No newline at end of file diff --git a/src/wheel_stuck_utils/include/wheel_stuck_utils/ros/no_callback_subscription.hpp b/src/wheel_stuck_utils/include/wheel_stuck_utils/ros/no_callback_subscription.hpp new file mode 100644 index 0000000..1bab50d --- /dev/null +++ b/src/wheel_stuck_utils/include/wheel_stuck_utils/ros/no_callback_subscription.hpp @@ -0,0 +1,49 @@ +#ifndef WHEEL_STUCK_UTILS__ROS__NO_CALLBACK_SUBSCRIPTION_HPP_ +#define WHEEL_STUCK_UTILS__ROS__NO_CALLBACK_SUBSCRIPTION_HPP_ + +#include + +namespace wheel_stuck_utils { + +template +class NoCallbackSubscription { + private: + typename rclcpp::Subscription::SharedPtr subscription_; + + public: + using SharedPtr = std::shared_ptr>; + static SharedPtr create_subscription(rclcpp::Node* node, + const std::string& topic_name, + const rclcpp::QoS& qos = rclcpp::QoS{ + 1}) { + return std::make_shared>(node, topic_name, + qos); + } + + explicit NoCallbackSubscription(rclcpp::Node* node, + const std::string& topic_name, + const rclcpp::QoS& qos = rclcpp::QoS{1}) { + auto noexec_callback_group = node->create_callback_group( + rclcpp::CallbackGroupType::MutuallyExclusive, false); + auto noexec_subscription_options = rclcpp::SubscriptionOptions(); + noexec_subscription_options.callback_group = noexec_callback_group; + + subscription_ = node->create_subscription( + topic_name, qos, + [node]([[maybe_unused]] const typename TMessage::ConstSharedPtr msg) { + assert(false); + }, + noexec_subscription_options); + } + + typename TMessage::ConstSharedPtr getData() { + auto data = std::make_shared(); + rclcpp::MessageInfo message_info; + const bool is_received = subscription_->take(*data, message_info); + return is_received ? data : nullptr; + } +}; + +} // namespace wheel_stuck_utils + +#endif \ No newline at end of file diff --git a/src/wheel_stuck_utils/package.xml b/src/wheel_stuck_utils/package.xml new file mode 100644 index 0000000..09976be --- /dev/null +++ b/src/wheel_stuck_utils/package.xml @@ -0,0 +1,20 @@ + + + + wheel_stuck_utils + 0.1.0 + The wheel_stuck_utils package + Akiro Harada + + Apache 2 + + ament_cmake_auto + + rclcpp + + ament_lint_auto + + + ament_cmake + + \ No newline at end of file From 24f4d0b58a4f5a04cb43396980e093cbaea2893f Mon Sep 17 00:00:00 2001 From: Autumn60 Date: Fri, 28 Jun 2024 21:35:58 +0900 Subject: [PATCH 2/3] comment out unnecessary line in CMakeLists Signed-off-by: Autumn60 --- src/wheel_stuck_utils/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wheel_stuck_utils/CMakeLists.txt b/src/wheel_stuck_utils/CMakeLists.txt index 728e713..c7adc3b 100644 --- a/src/wheel_stuck_utils/CMakeLists.txt +++ b/src/wheel_stuck_utils/CMakeLists.txt @@ -14,9 +14,9 @@ endif() find_package(ament_cmake_auto REQUIRED) ament_auto_find_build_dependencies() -ament_auto_add_library(autoware_universe_utils SHARED - src/hoge.cpp -) +# ament_auto_add_library(autoware_universe_utils SHARED +# src/source.cpp +# ) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) From 8e717db98c8327f63c13bd51af7430225d99ea70 Mon Sep 17 00:00:00 2001 From: Autumn60 Date: Sat, 29 Jun 2024 14:23:34 +0900 Subject: [PATCH 3/3] format file with clang-format Signed-off-by: Autumn60 --- .../ros/no_callback_subscription.hpp | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/wheel_stuck_utils/include/wheel_stuck_utils/ros/no_callback_subscription.hpp b/src/wheel_stuck_utils/include/wheel_stuck_utils/ros/no_callback_subscription.hpp index 1bab50d..6616586 100644 --- a/src/wheel_stuck_utils/include/wheel_stuck_utils/ros/no_callback_subscription.hpp +++ b/src/wheel_stuck_utils/include/wheel_stuck_utils/ros/no_callback_subscription.hpp @@ -3,40 +3,39 @@ #include -namespace wheel_stuck_utils { +namespace wheel_stuck_utils +{ template -class NoCallbackSubscription { - private: +class NoCallbackSubscription +{ +private: typename rclcpp::Subscription::SharedPtr subscription_; - public: +public: using SharedPtr = std::shared_ptr>; - static SharedPtr create_subscription(rclcpp::Node* node, - const std::string& topic_name, - const rclcpp::QoS& qos = rclcpp::QoS{ - 1}) { - return std::make_shared>(node, topic_name, - qos); + static SharedPtr create_subscription( + rclcpp::Node * node, const std::string & topic_name, const rclcpp::QoS & qos = rclcpp::QoS{1}) + { + return std::make_shared>(node, topic_name, qos); } - explicit NoCallbackSubscription(rclcpp::Node* node, - const std::string& topic_name, - const rclcpp::QoS& qos = rclcpp::QoS{1}) { - auto noexec_callback_group = node->create_callback_group( - rclcpp::CallbackGroupType::MutuallyExclusive, false); + explicit NoCallbackSubscription( + rclcpp::Node * node, const std::string & topic_name, const rclcpp::QoS & qos = rclcpp::QoS{1}) + { + auto noexec_callback_group = + node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive, false); auto noexec_subscription_options = rclcpp::SubscriptionOptions(); noexec_subscription_options.callback_group = noexec_callback_group; subscription_ = node->create_subscription( - topic_name, qos, - [node]([[maybe_unused]] const typename TMessage::ConstSharedPtr msg) { - assert(false); - }, - noexec_subscription_options); + topic_name, qos, + [node]([[maybe_unused]] const typename TMessage::ConstSharedPtr msg) { assert(false); }, + noexec_subscription_options); } - typename TMessage::ConstSharedPtr getData() { + typename TMessage::ConstSharedPtr getData() + { auto data = std::make_shared(); rclcpp::MessageInfo message_info; const bool is_received = subscription_->take(*data, message_info);