-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Fool-Stuck/feat/subscription_utils
feat: add no callback subscription wrapper class
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
48 changes: 48 additions & 0 deletions
48
src/wheel_stuck_utils/include/wheel_stuck_utils/ros/no_callback_subscription.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#ifndef WHEEL_STUCK_UTILS__ROS__NO_CALLBACK_SUBSCRIPTION_HPP_ | ||
#define WHEEL_STUCK_UTILS__ROS__NO_CALLBACK_SUBSCRIPTION_HPP_ | ||
|
||
#include <rclcpp/rclcpp.hpp> | ||
|
||
namespace wheel_stuck_utils | ||
{ | ||
|
||
template <typename TMessage> | ||
class NoCallbackSubscription | ||
{ | ||
private: | ||
typename rclcpp::Subscription<TMessage>::SharedPtr subscription_; | ||
|
||
public: | ||
using SharedPtr = std::shared_ptr<NoCallbackSubscription<TMessage>>; | ||
static SharedPtr create_subscription( | ||
rclcpp::Node * node, const std::string & topic_name, const rclcpp::QoS & qos = rclcpp::QoS{1}) | ||
{ | ||
return std::make_shared<NoCallbackSubscription<TMessage>>(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<TMessage>( | ||
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<TMessage>(); | ||
rclcpp::MessageInfo message_info; | ||
const bool is_received = subscription_->take(*data, message_info); | ||
return is_received ? data : nullptr; | ||
} | ||
}; | ||
|
||
} // namespace wheel_stuck_utils | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>wheel_stuck_utils</name> | ||
<version>0.1.0</version> | ||
<description>The wheel_stuck_utils package</description> | ||
<maintainer email="[email protected]">Akiro Harada</maintainer> | ||
|
||
<license>Apache 2</license> | ||
|
||
<buildtool_depend>ament_cmake_auto</buildtool_depend> | ||
|
||
<depend>rclcpp</depend> | ||
|
||
<test_depend>ament_lint_auto</test_depend> | ||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |