Subscribe to two PointCloud2 messages using message_filters
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 ...
One change I would make is Changing callback's input arguments to
sensor_msgs::PointCloud2ConstPtr&
. My understanding is that the callbacks should only acceptConstPtr&
types.please post error or console output
@atas Sorry for the insufficiency, I just added the complete error message as asked for.
@JackB I actually thought of that too, as in the tutorials, but unfortunately still with same error msg!!