ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to pass boost::shared_ptr in create_subscription (ROS2)

asked 2019-01-01 06:54:21 -0600

Gabbar gravatar image

updated 2019-01-03 03:11:28 -0600

gvdhoorn gravatar image

Hi,

I stuck at one point that. node->create_subscription is taking template argument only standard but my library is the old type (like structure in the namespace). So, I need to pass boost::shared_ptr in node->create_subscription.

I have used code as below.

rclcpp::Subscription<pcl::PCLPointCloud2>::SharedPtr sub_;
sub_ = node->create_subscription<pcl::PCLPointCloud2>(cloud_topic_, callback);

In that PCL library is depending boost and all other ROS2 type code is depending on std::shared_ptr.

Please help me to resolve the scenario.


Edit: @Dirk Thomas

I have implemented 2nd suggestion but it gives me the following errors while linking. Please find the below structure (PCL) which I am passing in create_subscription.

http://docs.pointclouds.org/1.7.0/_p_...

Here Format of ROS2 and PCL library structure is too different. Maybe that's why it is not compatible with ROS2. Please guide if any other solution. Can I create the same structure (from PCL) as like other structure (namespace) in ROS2 ?

In function `rclcpp::create_subscription_factory<pcl::PCLPointCloud2, PointCloudToPCD::PointCloudToPCD()::{lambda(std::shared_ptr<pcl::PCLPointCloud2 const>)#1}&, std::allocator<void>, pcl::PCLPointCloud2, rclcpp::Subscription<pcl::PCLPointCloud2, PointCloudToPCD::PointCloudToPCD()::{lambda(std::shared_ptr<pcl::PCLPointCloud2 const>)#1}&> >(PointCloudToPCD::PointCloudToPCD()::{lambda(std::shared_ptr<pcl::PCLPointCloud2 const>)#1}&, rclcpp::message_memory_strategy::MessageMemoryStrategy<pcl::PCLPointCloud2, std::allocator<void> >::SharedPtr, std::shared_ptr<pcl::PCLPointCloud2>)::{lambda(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rcl_subscription_options_t&)#1}::operator()(rclcpp::node_interfaces::NodeBaseInterface, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, rcl_subscription_options_t) const':

(.text._ZZN6rclcpp27create_subscription_factoryIN3pcl14PCLPointCloud2ERZN15PointCloudToPCDC4EvEUlSt10shared_ptrIKS2_EE_SaIvES2_NS_12SubscriptionIS2_S9_EEEENS_19SubscriptionFactoryEOT0_NS_23message_memory_strategy21MessageMemoryStrategyIT2_T1_E9SharedPtrES4_ISI_EENKUlPNS_15node_interfaces17NodeBaseInterfaceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEER26rcl_subscription_options_tE_clESO_SW_SY_[_ZZN6rclcpp27create_subscription_factoryIN3pcl14PCLPointCloud2ERZN15PointCloudToPCDC4EvEUlSt10shared_ptrIKS2_EE_SaIvES2_NS_12SubscriptionIS2_S9_EEEENS_19SubscriptionFactoryEOT0_NS_23message_memory_strategy21MessageMemoryStrategyIT2_T1_E9SharedPtrES4_ISI_EENKUlPNS_15node_interfaces17NodeBaseInterfaceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEER26rcl_subscription_options_tE_clESO_SW_SY_]+0xa6): undefined reference to `rosidl_message_type_support_t const* rosidl_typesupport_cpp::get_message_type_support_handle<pcl::PCLPointCloud2>()'

collect2: error: ld returned 1 exit status
edit retag flag offensive close merge delete

Comments

I'm not sure where the boost::shared_ptr is coming in here. Do you have a longer example that shows the use of it?

mjcarroll gravatar image mjcarroll  ( 2019-01-02 09:27:18 -0600 )edit

The new issue appears to be that you are passing a pcl::PCLPointCloud2 which is not a supported message type, you should be using sensors_msgs::msg::PointCloud2. In ROS1, you could additionally use pcl_ros to provide the mapping automatically I believe, but that is not present here.

mjcarroll gravatar image mjcarroll  ( 2019-01-03 08:15:20 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-01-02 12:16:16 -0600

Dirk Thomas gravatar image

I need to pass boost::shared_ptr in node->create_subscription.

The ROS 2 API is designed with modern C++ in mind and doesn't use boost for features which are part of the C++ standard. So you won't be able to pass a boost::shared_ptr as is.

The following might be options for you:

  • Update your library to use std::shared_ptr instead of boost::shared_ptr.
  • If that is not an option consider to introduce a typedef in your library to either use boost or std and then use the later when interfacing with ROS 2.
  • If neither of the above is an option you will need to fall back to convert to/from raw pointers instead.
edit flag offensive delete link more

Comments

These seem like interesting suggestions, too: https://stackoverflow.com/questions/6...

ahendrix gravatar image ahendrix  ( 2019-01-02 15:33:41 -0600 )edit

Hi @Dirk Thomas

Please see my edited comment and help me for the same.

Gabbar gravatar image Gabbar  ( 2019-01-07 02:56:00 -0600 )edit

You can only pass actual message instances to the publish/subscribe API in ROS 2. A native pcl type won't work.

Dirk Thomas gravatar image Dirk Thomas  ( 2019-01-07 12:14:09 -0600 )edit

@Dirk Thomas

pcl_ros and PCL use pcl_msgs for message instances but there is no PointCloud/PointCloud2 msg file in pcl_msgs. So, can we create msg file of PointCloud in pcl_msgs as like sensor_msg?

Gabbar gravatar image Gabbar  ( 2019-01-17 06:38:55 -0600 )edit

I am not sure I understand the question but if there is existing API using a data type which is not generated from a message definition you can't create a message definition which will magically be compatible with this separate type.

Dirk Thomas gravatar image Dirk Thomas  ( 2019-01-18 12:57:34 -0600 )edit

The topic is being discussed in https://discourse.ros.org/t/ros2-pcl-...

Dirk Thomas gravatar image Dirk Thomas  ( 2019-01-18 12:57:47 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2019-01-01 06:54:21 -0600

Seen: 2,874 times

Last updated: Jan 07 '19