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

ROS1 ROS2 porting help ?

asked 2023-07-03 04:45:23 -0500

updated 2023-07-05 00:06:27 -0500

i have a std::queue defined like this

std::queue<sensor_msgs::PointCloud2ConstPtr> pointCloudBuf;

I wanted to understand how to define this in ROS2 , i tried the following but

std::queue<sensor_msgs::msg::PointCloud2::ConstPtr> pointCloudBuf;

When trying to push to the queue

void velodyneHandler(const sensor_msgs::msg::PointCloud2::SharedPtr laserCloudMsg)
{
    mutex_lock.lock();
    pointCloudBuf.push(*laserCloudMsg);
    mutex_lock.unlock();

}

i am getting the following error

no matching function for call to ‘std::queue<std::shared_ptr<const sensor_msgs::msg::PointCloud2_<std::allocator<void> > > >::push(std::__shared_ptr_access<sensor_msgs::msg::PointCloud2_<std::allocator<void> >, __gnu_cxx::_S_atomic, false, false>::element_type&)’
   61 |     pointCloudBuf.push(*laserCloudMsg);
      |     ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~

UPDATE

std::queue<sensor_msgs::msg::PointCloud2::SharedPtr> pointCloudBuf;

This seem to have solved my compilation issues , dont know if it will break something else down the line .

Anyhow , thankyou ROS community !

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2023-07-03 06:04:13 -0500

Try changing your declaration to the following. You've declared for ConstPtr but using for SharedPtr.

std::queue<sensor_msgs::msg::PointCloud2::SharedPtr> pointCloudBuf;

edit flag offensive delete link more

Comments

@chrissunny94: the problem is that your code has incompatible types for the queue and the callback argument.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2023-07-03 08:23:07 -0500 )edit

@Gaurav Gupta (small world!), thanks a lot . saw your answer just now . .

chrissunny94 gravatar image chrissunny94  ( 2023-07-04 23:50:13 -0500 )edit

@Mike Scheutzow , yup looks like my code has a lot of incompatible types , sorting it now . Will post my finding soond .

chrissunny94 gravatar image chrissunny94  ( 2023-07-04 23:51:06 -0500 )edit

@Gaurav Gupta ,yup making it into shared_ptr , seems to have solved the problem . Someone in office also suggested the same solution .

chrissunny94 gravatar image chrissunny94  ( 2023-07-05 00:04:53 -0500 )edit

Yup! Glad it is all sorted now :)

Gaurav Gupta gravatar image Gaurav Gupta  ( 2023-07-05 15:43:50 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2023-07-03 04:45:23 -0500

Seen: 92 times

Last updated: Jul 05 '23