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

Subscribe to two PointCloud2 messages using message_filters

asked 2020-09-10 18:12:39 -0500

Martian gravatar image

updated 2020-09-11 02:25:51 -0500

I was trying to synchronize between two PointCloud2 messages, following these tutorials. But I was not able to compile the following piece of code:

#include <message_filters/subscriber.h>
#include <message_filters/time_synchronizer.h>
#include "sensor_msgs/PointCloud2.h"


void callback(const sensor_msgs::PointCloud2& pc1, const sensor_msgs::PointCloud2& pc2)
{
  // Solve all of perception here...
}

int main(int argc, char** argv)
{
  ros::init(argc, argv, "point_clouds_node");

  ros::NodeHandle nHandle;

  message_filters::Subscriber<sensor_msgs::PointCloud2> pc_sub_1(nHandle, "sensors/scan_1", 1);
  message_filters::Subscriber<sensor_msgs::PointCloud2> pc_sub_2(nHandle, "sensors/scan_2", 1);
  message_filters::TimeSynchronizer<sensor_msgs::PointCloud2, sensor_msgs::PointCloud2> sync(pc_sub_1, pc_sub_2, 10);
  sync.registerCallback(boost::bind(&callback, _1, _2));

  ros::spin();

  return 0;
}

How can I achieve such a thing? Thanks

Update: Here's the error msg:

In file included from /usr/include/boost/bind.hpp:22,
                 from /opt/ros/melodic/include/ros/publisher.h:35,
                 from /opt/ros/melodic/include/ros/node_handle.h:32,
                 from /opt/ros/melodic/include/ros/ros.h:45,
                 from /opt/ros/melodic/include/message_filters/subscriber.h:38,
                 from /home/user/catkin_ws/src/my_pkg/src/mySubscriber.cpp:1:
/usr/include/boost/bind/bind.hpp: In instantiation of ‘void boost::_bi::list2<A1, A2>::operator()(boost::_bi::type<void>, F&, A&, int) [with F = void (*)(const sensor_msgs::PointCloud2_<std::allocator<void> >&, const sensor_msgs::PointCloud2_<std::allocator<void> >&); A = boost::_bi::rrlist9<const boost::shared_ptr<const sensor_msgs::PointCloud2_<std::allocator<void> > >&, const boost::shared_ptr<const sensor_msgs::PointCloud2_<std::allocator<void> > >&, const boost::shared_ptr<const message_filters::NullType>&, const boost::shared_ptr<const message_filters::NullType>&, const boost::shared_ptr<const message_filters::NullType>&, const boost::shared_ptr<const message_filters::NullType>&, const boost::shared_ptr<const message_filters::NullType>&, const boost::shared_ptr<const message_filters::NullType>&, const boost::shared_ptr<const message_filters::NullType>&>; A1 = boost::arg<1>; A2 = boost::arg<2>]’:
/usr/include/boost/bind/bind.hpp:1402:50:   required from ‘boost::_bi::bind_t<R, F, L>::result_type boost::_bi::bind_t<R, F, L>::operator()(A1&&, A2&&, A3&&, A4&&, A5&&, A6&&, A7&&, A8&&, A9&&) [with A1 = const boost::shared_ptr<const sensor_msgs::PointCloud2_<std::allocator<void> > >&; A2 = const boost::shared_ptr<const sensor_msgs::PointCloud2_<std::allocator<void> > >&; A3 = const boost::shared_ptr<const message_filters::NullType>&; A4 = const boost::shared_ptr<const message_filters::NullType>&; A5 = const boost::shared_ptr<const message_filters::NullType>&; A6 = const boost::shared_ptr<const message_filters::NullType>&; A7 = const boost::shared_ptr<const message_filters::NullType>&; A8 = const boost::shared_ptr<const message_filters::NullType>&; A9 = const boost::shared_ptr<const message_filters::NullType>&; R = void; F = void (*)(const sensor_msgs::PointCloud2_<std::allocator<void> >&, const sensor_msgs::PointCloud2_<std::allocator<void> >&); L = boost::_bi::list2<boost::arg<1>, boost::arg<2> >; boost::_bi::bind_t<R, F, L>::result_type = void]’
/usr/include/boost/bind/bind.hpp:833:35:   required from ‘void boost::_bi::list9<A1, A2, A3, A4, A5, A6, A7, A8, A9>::operator()(boost::_bi::type<void>, F&, A&, int) [with F = boost::_bi::bind_t<void, void (*)(const sensor_msgs::PointCloud2_<std::allocator<void> >&, const sensor_msgs::PointCloud2_<std::allocator<void> >&), boost::_bi::list2<boost::arg<1>, boost::arg<2> > >; A = boost::_bi::rrlist9<const boost::shared_ptr<const sensor_msgs::PointCloud2_<std::allocator<void> > >&, const boost::shared_ptr<const sensor_msgs::PointCloud2_<std::allocator<void> > >&, const boost::shared_ptr<const message_filters::NullType>&, const boost::shared_ptr<const message_filters::NullType>&, const boost::shared_ptr<const message_filters::NullType>&, const boost::shared_ptr<const message_filters::NullType>&, const boost::shared_ptr<const message_filters::NullType>&, const boost::shared_ptr<const message_filters::NullType>&, const boost::shared_ptr<const message_filters::NullType>&>; A1 = boost::arg<1>; A2 = boost::arg<2>; A3 ...
(more)
edit retag flag offensive close merge delete

Comments

One change I would make is Changing callback's input arguments to sensor_msgs::PointCloud2ConstPtr&. My understanding is that the callbacks should only accept ConstPtr& types.

JackB gravatar image JackB  ( 2020-09-10 22:58:07 -0500 )edit

please post error or console output

Fetullah Atas gravatar image Fetullah Atas  ( 2020-09-11 01:23:28 -0500 )edit

@atas Sorry for the insufficiency, I just added the complete error message as asked for.

Martian gravatar image Martian  ( 2020-09-11 02:29:06 -0500 )edit

@JackB I actually thought of that too, as in the tutorials, but unfortunately still with same error msg!!

Martian gravatar image Martian  ( 2020-09-11 02:29:48 -0500 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2020-09-11 03:05:12 -0500

gvdhoorn gravatar image

updated 2020-09-11 03:05:24 -0500

References != pointers.

const sensor_msgs::PointCloud2_<..>& != boost::shared_ptr<const sensor_msgs::PointCloud2_<..> >.

edit flag offensive delete link more

Comments

@gvdhoorn Thank you so much, that actually worked. Silly me didn't read the error msg appropriately!!

Martian gravatar image Martian  ( 2020-09-11 03:14:23 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2020-09-10 18:12:39 -0500

Seen: 291 times

Last updated: Sep 11 '20