0
$\begingroup$

Rosanswers logo

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 !


Originally posted by chrissunny94 on ROS Answers with karma: 142 on 2023-07-03

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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

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


Originally posted by Gaurav Gupta with karma: 276 on 2023-07-03

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Mike Scheutzow on 2023-07-03:
@chrissunny94: the problem is that your code has incompatible types for the queue and the callback argument.

Comment by chrissunny94 on 2023-07-04:
@Gaurav Gupta (small world!), thanks a lot . saw your answer just now . .

Comment by chrissunny94 on 2023-07-04:
@Mike Scheutzow , yup looks like my code has a lot of incompatible types , sorting it now . Will post my finding soond .

Comment by chrissunny94 on 2023-07-05:
@Gaurav Gupta ,yup making it into shared_ptr , seems to have solved the problem . Someone in office also suggested the same solution .

Comment by Gaurav Gupta on 2023-07-05:
Yup! Glad it is all sorted now :)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.