From 5ca685d96a07423ec955821bf822cfa7373ce9a2 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Mon, 9 Jul 2018 15:01:03 -0700 Subject: [PATCH] most changes from https://github.com/ros/ros_comm/pull/1301 --- CMakeLists.txt | 36 +++++++++-------- include/message_filters/connection.h | 4 +- include/message_filters/macros.h | 2 - include/message_filters/signal1.h | 18 ++++----- include/message_filters/simple_filter.h | 21 +++++----- include/message_filters/subscriber.h | 52 ++++++++++++++----------- package.xml | 17 +++----- 7 files changed, 76 insertions(+), 74 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5694ac57..85383e36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,33 +1,37 @@ -cmake_minimum_required(VERSION 2.8.3) +cmake_minimum_required(VERSION 3.5) project(message_filters) if(NOT WIN32) set_directory_properties(PROPERTIES COMPILE_OPTIONS "-Wall;-Wextra") endif() -find_package(catkin REQUIRED COMPONENTS roscpp rosconsole) -catkin_package( - INCLUDE_DIRS include - LIBRARIES message_filters - CATKIN_DEPENDS roscpp rosconsole -) -catkin_python_setup() +find_package(ament_cmake REQUIRED) +find_package(rclcpp REQUIRED) -find_package(Boost REQUIRED COMPONENTS signals thread) +set(Boost_USE_STATIC_LIBS ON) +find_package(Boost REQUIRED) -include_directories(include ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) -link_directories(${catkin_LIBRARY_DIRS}) +include_directories(include + ${rclcpp_INCLUDE_DIRS} + ${Boost_INCLUDE_DIRS} +) add_library(${PROJECT_NAME} src/connection.cpp) -target_link_libraries(${PROJECT_NAME} ${catkin_LIBRARIES} ${Boost_LIBRARIES}) +target_link_libraries(${PROJECT_NAME} + ${rclcpp_LIBRARIES} +) + +ament_export_include_directories(include) +ament_export_libraries(${PROJECT_NAME}) +ament_package() install(TARGETS ${PROJECT_NAME} - ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}) + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin) install(DIRECTORY include/${PROJECT_NAME}/ - DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} + DESTINATION include/${PROJECT_NAME} FILES_MATCHING PATTERN "*.h") if(CATKIN_ENABLE_TESTING) diff --git a/include/message_filters/connection.h b/include/message_filters/connection.h index 8b840f52..3929d48a 100644 --- a/include/message_filters/connection.h +++ b/include/message_filters/connection.h @@ -48,8 +48,8 @@ namespace message_filters class MESSAGE_FILTERS_DECL Connection { public: - typedef boost::function VoidDisconnectFunction; - typedef boost::function WithConnectionDisconnectFunction; + typedef std::function VoidDisconnectFunction; + typedef std::function WithConnectionDisconnectFunction; Connection() {} Connection(const VoidDisconnectFunction& func); Connection(const WithConnectionDisconnectFunction& func, boost::signals2::connection conn); diff --git a/include/message_filters/macros.h b/include/message_filters/macros.h index 6853a2b0..7ac75383 100644 --- a/include/message_filters/macros.h +++ b/include/message_filters/macros.h @@ -28,8 +28,6 @@ #ifndef MESSAGE_FILTERS_MACROS_H_ #define MESSAGE_FILTERS_MACROS_H_ -#include // for the DECL's - // Import/export for windows dll's and visibility for gcc shared libraries. #ifdef ROS_BUILD_SHARED_LIBS // ros is being built around shared libraries diff --git a/include/message_filters/signal1.h b/include/message_filters/signal1.h index 75c3fe9f..8ccb1388 100644 --- a/include/message_filters/signal1.h +++ b/include/message_filters/signal1.h @@ -38,8 +38,8 @@ #include #include "connection.h" + #include -#include #include #include @@ -54,26 +54,24 @@ class CallbackHelper1 virtual void call(const ros::MessageEvent& event, bool nonconst_need_copy) = 0; - typedef boost::shared_ptr > Ptr; + typedef std::shared_ptr > Ptr; }; template class CallbackHelper1T : public CallbackHelper1 { public: - typedef ros::ParameterAdapter

Adapter; - typedef boost::function Callback; - typedef typename Adapter::Event Event; + typedef std::function& msg)> Callback; CallbackHelper1T(const Callback& cb) - : callback_(cb) + : callback_(cb) { } virtual void call(const ros::MessageEvent& event, bool nonconst_force_copy) { - Event my_event(event, nonconst_force_copy || event.nonConstWillCopy()); - callback_(Adapter::getParameter(my_event)); + // TODO: validate + callback_(event.getMessage()); } private: @@ -83,12 +81,12 @@ class CallbackHelper1T : public CallbackHelper1 template class Signal1 { - typedef boost::shared_ptr > CallbackHelper1Ptr; + typedef std::shared_ptr > CallbackHelper1Ptr; typedef std::vector V_CallbackHelper1; public: template - CallbackHelper1Ptr addCallback(const boost::function& callback) + CallbackHelper1Ptr addCallback(const std::function& callback) { CallbackHelper1T* helper = new CallbackHelper1T(callback); diff --git a/include/message_filters/simple_filter.h b/include/message_filters/simple_filter.h index 2201211f..44b2499f 100644 --- a/include/message_filters/simple_filter.h +++ b/include/message_filters/simple_filter.h @@ -40,7 +40,6 @@ #include "connection.h" #include "signal1.h" #include -#include #include @@ -60,10 +59,10 @@ template class SimpleFilter : public boost::noncopyable { public: - typedef boost::shared_ptr MConstPtr; - typedef boost::function Callback; + typedef std::shared_ptr MConstPtr; + typedef std::function Callback; typedef ros::MessageEvent EventType; - typedef boost::function EventCallback; + typedef std::function EventCallback; /** * \brief Register a callback to be called when this filter has passed @@ -73,7 +72,7 @@ class SimpleFilter : public boost::noncopyable Connection registerCallback(const C& callback) { typename CallbackHelper1::Ptr helper = signal_.addCallback(Callback(callback)); - return Connection(boost::bind(&Signal::removeCallback, &signal_, helper)); + return Connection(std::bind(&Signal::removeCallback, &signal_, helper)); } /** @@ -81,9 +80,9 @@ class SimpleFilter : public boost::noncopyable * \param callback The callback to call */ template - Connection registerCallback(const boost::function& callback) + Connection registerCallback(const std::function& callback) { - return Connection(boost::bind(&Signal::removeCallback, &signal_, signal_.addCallback(callback))); + return Connection(std::bind(&Signal::removeCallback, &signal_, signal_.addCallback(callback))); } /** @@ -93,8 +92,8 @@ class SimpleFilter : public boost::noncopyable template Connection registerCallback(void(*callback)(P)) { - typename CallbackHelper1::Ptr helper = signal_.template addCallback

(boost::bind(callback, _1)); - return Connection(boost::bind(&Signal::removeCallback, &signal_, helper)); + typename CallbackHelper1::Ptr helper = signal_.template addCallback

(std::bind(callback, std::placeholders::_1)); + return Connection(std::bind(&Signal::removeCallback, &signal_, helper)); } /** @@ -104,8 +103,8 @@ class SimpleFilter : public boost::noncopyable template Connection registerCallback(void(T::*callback)(P), T* t) { - typename CallbackHelper1::Ptr helper = signal_.template addCallback

(boost::bind(callback, t, _1)); - return Connection(boost::bind(&Signal::removeCallback, &signal_, helper)); + typename CallbackHelper1::Ptr helper = signal_.template addCallback

(std::bind(callback, t, std::placeholders::_1)); + return Connection(std::bind(&Signal::removeCallback, &signal_, helper)); } /** diff --git a/include/message_filters/subscriber.h b/include/message_filters/subscriber.h index b69a3dac..2b201181 100644 --- a/include/message_filters/subscriber.h +++ b/include/message_filters/subscriber.h @@ -35,7 +35,10 @@ #ifndef MESSAGE_FILTERS_SUBSCRIBER_H #define MESSAGE_FILTERS_SUBSCRIBER_H -#include +#include + +#include +#include #include @@ -60,7 +63,7 @@ class SubscriberBase * \param transport_hints The transport hints to pass along * \param callback_queue The callback queue to pass along */ - virtual void subscribe(ros::NodeHandle& nh, const std::string& topic, uint32_t queue_size, const ros::TransportHints& transport_hints = ros::TransportHints(), ros::CallbackQueueInterface* callback_queue = 0) = 0; + virtual void subscribe(rclcpp::Node::SharedPtr& nh, const std::string& topic, uint32_t queue_size) = 0; /** * \brief Re-subscribe to a topic. Only works if this subscriber has previously been subscribed to a topic. */ @@ -70,7 +73,7 @@ class SubscriberBase */ virtual void unsubscribe() = 0; }; -typedef boost::shared_ptr SubscriberBasePtr; +typedef std::shared_ptr SubscriberBasePtr; /** * \brief ROS subscription filter. @@ -79,7 +82,7 @@ typedef boost::shared_ptr SubscriberBasePtr; * filters which have connected to it. * * When this object is destroyed it will unsubscribe from the ROS subscription. - * + * * The Subscriber object is templated on the type of message being subscribed to. * * \section connections CONNECTIONS @@ -90,12 +93,13 @@ typedef boost::shared_ptr SubscriberBasePtr; \verbatim void callback(const boost::shared_ptr&); \endverbatim - */ + */ template class Subscriber : public SubscriberBase, public SimpleFilter { public: - typedef boost::shared_ptr MConstPtr; + typedef boost::shared_ptr BoostMConstPtr; + typedef std::shared_ptr MConstPtr; typedef ros::MessageEvent EventType; /** @@ -109,9 +113,9 @@ class Subscriber : public SubscriberBase, public SimpleFilter * \param transport_hints The transport hints to pass along * \param callback_queue The callback queue to pass along */ - Subscriber(ros::NodeHandle& nh, const std::string& topic, uint32_t queue_size, const ros::TransportHints& transport_hints = ros::TransportHints(), ros::CallbackQueueInterface* callback_queue = 0) + Subscriber(rclcpp::Node::SharedPtr& nh, const std::string& topic, uint32_t queue_size) { - subscribe(nh, topic, queue_size, transport_hints, callback_queue); + subscribe(nh, topic, queue_size); } /** @@ -137,16 +141,17 @@ class Subscriber : public SubscriberBase, public SimpleFilter * \param transport_hints The transport hints to pass along * \param callback_queue The callback queue to pass along */ - void subscribe(ros::NodeHandle& nh, const std::string& topic, uint32_t queue_size, const ros::TransportHints& transport_hints = ros::TransportHints(), ros::CallbackQueueInterface* callback_queue = 0) + void subscribe(rclcpp::Node::SharedPtr& nh, const std::string& topic, uint32_t queue_size) { unsubscribe(); if (!topic.empty()) { - ops_.template initByFullCallbackType(topic, queue_size, boost::bind(&Subscriber::cb, this, _1)); - ops_.callback_queue = callback_queue; - ops_.transport_hints = transport_hints; - sub_ = nh.subscribe(ops_); + topic_ = topic; + // TODO: why is this multi-line version needed? + auto stdFxn = std::bind(&Subscriber::cb, this, std::placeholders::_1); + std::function)> stdFxnPtr = stdFxn; + sub_ = nh->create_subscription(topic_, stdFxnPtr, rmw_qos_profile_default); nh_ = nh; } } @@ -158,9 +163,12 @@ class Subscriber : public SubscriberBase, public SimpleFilter { unsubscribe(); - if (!ops_.topic.empty()) + if (!topic_.empty()) { - sub_ = nh_.subscribe(ops_); + // TODO: why is this multi-line version needed? + auto stdFxn = std::bind(&Subscriber::cb, this, std::placeholders::_1); + std::function)> stdFxnPtr = stdFxn; + sub_ = nh_->create_subscription(topic_, stdFxnPtr, rmw_qos_profile_default); } } @@ -169,18 +177,18 @@ class Subscriber : public SubscriberBase, public SimpleFilter */ void unsubscribe() { - sub_.shutdown(); + // TODO: No idea how to do this in ROS2??? } std::string getTopic() const { - return ops_.topic; + return sub_->get_topic_name(); } /** * \brief Returns the internal ros::Subscriber object */ - const ros::Subscriber& getSubscriber() const { return sub_; } + const std::shared_ptr> getSubscriber() const { return sub_; } /** * \brief Does nothing. Provided so that Subscriber may be used in a message_filters::Chain @@ -201,14 +209,14 @@ class Subscriber : public SubscriberBase, public SimpleFilter private: - void cb(const EventType& e) + void cb(const MConstPtr& e) { this->signalMessage(e); } - ros::Subscriber sub_; - ros::SubscribeOptions ops_; - ros::NodeHandle nh_; + std::string topic_; + std::shared_ptr> sub_; + rclcpp::Node::SharedPtr nh_; }; } diff --git a/package.xml b/package.xml index 8473106b..5e8faab3 100644 --- a/package.xml +++ b/package.xml @@ -1,4 +1,5 @@ - + + message_filters 1.14.2 @@ -12,18 +13,12 @@ Josh Faust Vijay Pradeep - catkin + ament_cmake - boost - rosconsole - roscpp - rostest - rosunit - - rosconsole - roscpp + rclcpp + rclcpp - + ament_cmake