How to pass boost::shared_ptr in create_subscription (ROS2)
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
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?The new issue appears to be that you are passing a
pcl::PCLPointCloud2
which is not a supported message type, you should be usingsensors_msgs::msg::PointCloud2
. In ROS1, you could additionally usepcl_ros
to provide the mapping automatically I believe, but that is not present here.