diff --git a/src/wheel_stuck_utils/CMakeLists.txt b/src/wheel_stuck_utils/CMakeLists.txt new file mode 100644 index 0000000..c7adc3b --- /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/source.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..6616586 --- /dev/null +++ b/src/wheel_stuck_utils/include/wheel_stuck_utils/ros/no_callback_subscription.hpp @@ -0,0 +1,48 @@ +#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