Ask Your Question

Approximate Time policy compiles for two topics of same type, but fails for topics of different types

asked 2016-01-26 00:36:28 -0500

SaiHV gravatar image

updated 2016-01-26 01:01:29 -0500

Hello, I am trying to synchronize the callbacks for two topics, one of them, a geometry_msgs::PoseStamped message that acts as a signal for image capture from another computer (just using PoseStamped as a test case for now because it comes with a timestamp, will write own message type later on), and then the actual image topic of type sensor_msgs::Image. This is the code snippet that's doing the approximate time synchronization.

void callback(const geometry_msgs::PoseStamped& signal, const sensor_msgs::ImageConstPtr& rightimage)
   ROS_INFO("Reached callback");
   cv_bridge::CvImagePtr imgPtr;
   std::stringstream imgPath;

   //More code
typedef sync_policies::ApproximateTime<geometry_msgs::PoseStamped, sensor_msgs::Image> ApproxSyncPol;

Subscriber<geometry_msgs::PoseStamped> signal_sub(nh, "/signal", 1);;
Subscriber<sensor_msgs::Image> image_sub(nh, "camera/image_mono", 1);

Synchronizer<ApproxSyncPol> syncPol(ApproxSyncPol(10), signal_sub, image_sub);

syncPol.registerCallback(boost::bind(&callback, _1, _2));

This code fails to compile with a lot of errors, mostly relating to boost and the Approximate Time sync_policies statement. An excerpt:

 /opt/ros/indigo/include/message_filters/signal9.h:273:23:   required from ‘message_filters::Connection message_filters::Signal9<M0, M1, M2, M3, M4, M5, M6, M7, M8>::addCallback(C&) [with C = const boost::_bi::bind_t<void, void (*)(const geometry_msgs::PoseStamped_<std::allocator<void> >&, const boost::shared_ptr<const sensor_msgs::Image_<std::allocator<void> > >&), boost::_bi::list2<boost::arg<1>, boost::arg<2> > >; M0 = geometry_msgs::PoseStamped_<std::allocator<void> >; M1 = sensor_msgs::Image_<std::allocator<void> >; M2 = message_filters::NullType; M3 = message_filters::NullType; M4 = message_filters::NullType; M5 = message_filters::NullType; M6 = message_filters::NullType; M7 = message_filters::NullType; M8 = message_filters::NullType]’

 /opt/ros/indigo/include/message_filters/synchronizer.h:310:40:   required from ‘message_filters::Connection message_filters::Synchronizer<Policy>::registerCallback(const C&) [with C = boost::_bi::bind_t<void, void (*)(const geometry_msgs::PoseStamped_<std::allocator<void> >&, const boost::shared_ptr<const sensor_msgs::Image_<std::allocator<void> > >&), boost::_bi::list2<boost::arg<1>, boost::arg<2> > >; Policy = message_filters::sync_policies::ApproximateTime<geometry_msgs::PoseStamped_<std::allocator<void> >, sensor_msgs::Image_<std::allocator<void> > >]’

  /usr/include/boost/bind/bind.hpp:313:34: error: invalid initialization of reference of type ‘const geometry_msgs::PoseStamped_<std::allocator<void> >&’ from expression of type ‘const boost::shared_ptr<const geometry_msgs::PoseStamped_<std::allocator<void> > >’
       unwrapper<F>::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_]);

But this same structure works perfectly, if both topics are sensor_msgs::Image. I am not getting what I'm doing wrong here, because geometry_msgs::PoseStamped is a message that does contain a timestamp.

edit retag flag offensive close merge delete


This looks like a mismatch between the arguments for your callback and the arguments that the synchronizer is expecting to pass to the callback. Can you edit your question to include the callback function signature?

ahendrix gravatar image ahendrix  ( 2016-01-26 00:56:03 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2016-01-26 01:07:15 -0500

ahendrix gravatar image

This error message is trying to tell you that it expects your callback to take a boost::shared_ptr (or the ConstPtr message subtype) for the first argument; not a reference to a object.

Try this instead:

void callback(const geometry_msgs::PoseStampedConstPtr& signal, const sensor_msgs::ImageConstPtr& rightimage)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-01-26 00:36:28 -0500

Seen: 538 times

Last updated: Jan 26 '16