使用ROS2创建发布者
在创建发布者的时候,出现,如下问题,经过修改cmakeList发现并不是cmake版本问题。 ··· /usr/include/c++/9/bits/alloc_traits.h:399:13: error: forming pointer to reference type ‘const std::shared_ptr<const sensor_msgs::msg::LaserScan_<std::allocator > >&’ 399 | using pointer = Tp*; | ^~~~~~~ /usr/include/c++/9/bits/alloc_traits.h:402:13: error: forming pointer to reference type ‘const std::shared_ptr<const sensor_msgs::msg::LaserScan<std::allocator > >&’ 402 | using const_pointer = const Tp*; | ^~~~~~~~~~~~~ In file included from /usr/include/c++/9/memory:80, from /home/robot/localization_and_mapping/src/cartographer_ros/cartographer_ros/./cartographer_ros/relocation_node_main.h:21, from /home/robot/localization_and_mapping/src/cartographer_ros/cartographer_ros/cartographer_ros/relocation_node_main.cc:17: /usr/include/c++/9/bits/unique_ptr.h: In instantiation of ‘struct std::default_delete<const std::shared_ptr<const sensor_msgs::msg::LaserScan<std::allocator > >&>’: /opt/ros/foxy/include/rclcpp/message_memory_strategy.hpp:119:18: required from ‘class rclcpp::message_memory_strategy::MessageMemoryStrategy<const std::shared_ptr<const sensor_msgs::msg::LaserScan_<std::allocator > >&, std::allocator >’ /opt/ros/foxy/include/rclcpp/node_impl.hpp:91:1: required by substitution of ‘template<class MessageT, class CallbackT, class AllocatorT, class CallbackMessageT, class SubscriptionT, class MessageMemoryStrategyT> std::shared_ptr rclcpp::Node::create_subscription(const string&, const rclcpp::QoS&, CallbackT&&, const rclcpp::SubscriptionOptionsWithAllocator&, typename MessageMemoryStrategyT::SharedPtr) [with MessageT = sensor_msgs::msg::LaserScan_<std::allocator >; CallbackT = std::Bind<void (cartographer_ros::RelocationActionServer::(cartographer_ros::RelocationActionServer, std::Placeholder<1>))(const std::shared_ptr<const sensor_msgs::msg::LaserScan<std::allocator > >&)>; AllocatorT = std::allocator; CallbackMessageT = const std::shared_ptr<const sensor_msgs::msg::LaserScan<std::allocator > >&; SubscriptionT = rclcpp::Subscription<const std::shared_ptr<const sensor_msgs::msg::LaserScan_<std::allocator > >&, std::allocator, rclcpp::message_memory_strategy::MessageMemoryStrategy<const std::shared_ptr<const sensor_msgs::msg::LaserScan_<std::allocator > >&, std::allocator > >; MessageMemoryStrategyT = rclcpp::message_memory_strategy::MessageMemoryStrategy<const std::shared_ptr<const sensor_msgs::msg::LaserScan_<std::allocator > >&, std::allocator >]’ /home/robot/localization_and_mapping/src/cartographer_ros/cartographer_ros/./cartographer_ros/relocation_node_main.h:122:162: required from here /usr/include/c++/9/bits/unique_ptr.h:71:9: error: forming pointer to reference type ‘const std::shared_ptr<const sensor_msgs::msg::LaserScan_<std::allocator > >&’ 71 | default_delete(const default_delete<Up>&) noexcept { } | ^~~~~~~~~~~~~~ /usr/include/c++/9/bits/unique_ptr.h:75:7: error: forming pointer to reference type ‘const std::shared_ptr<const sensor_msgs::msg::LaserScan<std::allocator > >&’ 75 | operator()(_Tp* __ptr) const | ^~~~~~~~ ···
原因是callback函数中的参数不得是引用的形式。需要去除&。 如下,将内容修改:
void ScanCallback(const sensor_msgs::msg::LaserScan::ConstSharedPtr &scan);
到:
void ScanCallback(const sensor_msgs::msg::LaserScan::ConstSharedPtr scan);
|