Error trying to subscribe, synchronize and publish topics

asked 2015-03-24 13:33:37 -0600

aba92 gravatar image

I've been trying to synchronize topics of two cameras using the code below:

class SubscribeAndPublish
{
public:

  SubscribeAndPublish()
  {
    pub1_ = nh_.advertise<sensor_msgs::CameraInfo>("/published_topic1", 1);

    typedef sync_policies::ApproximateTime<sensor_msgs::CameraInfo, sensor_msgs::CameraInfo> MySyncPolicy;
    typedef message_filters::Synchronizer<MySyncPolicy> Synchronizer;
    boost::shared_ptr<Synchronizer> sync_;

    image1_sub.subscribe(nh_, "vizzy/left/image_raw", 1);
    image2_sub.subscribe(nh_, "vizzy/right/image_raw", 1);

    sync_.reset(new Synchronizer(MySyncPolicy(10), image1_sub, image2_sub));
    sync_->registerCallback(&SubscribeAndPublish::callback, _1, _2);

  }

Here I create the function that subscribes and fires the callback function to publish the message. But I'm getting the following errors in last line of above code: (I just posted part of the error message, because of it's extension!)

    /usr/include/boost/bind/bind.hpp: In instantiation of ‘boost::_bi::result_traits<boost::_bi::unspecified, void (SubscribeAndPublish::*)(const boost::shared_ptr<const sensor_msgs::CameraInfo_<std::allocator<void> > >&, const boost::shared_ptr<const sensor_msgs::CameraInfo_<std::allocator<void> > >&)>’:
/usr/include/boost/bind/bind_template.hpp:15:48:   instantiated from ‘boost::_bi::bind_t<boost::_bi::unspecified, void (SubscribeAndPublish::*)(const boost::shared_ptr<const sensor_msgs::CameraInfo_<std::allocator<void> > >&, const boost::shared_ptr<const sensor_msgs::CameraInfo_<std::allocator<void> > >&), boost::_bi::list2<boost::arg<1>, boost::arg<2> > >’
/home/aba/catkin_ws/src/viso2/viso2_ros/src/topic_sync.cpp:36:77:   instantiated from here
/usr/include/boost/bind/bind.hpp:69:37: error: ‘void (SubscribeAndPublish::*)(const boost::shared_ptr<const sensor_msgs::CameraInfo_<std::allocator<void> > >&, const boost::shared_ptr<const sensor_msgs::CameraInfo_<std::allocator<void> > >&)’ is not a class, struct, or union type

I lost many hours trying to solve that and if someone could help me I would be very grateful people. If useful I post here the remaing code:

void callback(const CameraInfoConstPtr& image1, const CameraInfoConstPtr& image2)
    {   
        pub1_.publish(image1);
    }

private:
  ros::NodeHandle nh_;
  ros::Publisher pub1_;
  message_filters::Subscriber<CameraInfo> image1_sub;
  message_filters::Subscriber<CameraInfo> image2_sub;

};//End of class SubscribeAndPublish

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

  SubscribeAndPublish SAPObject;

  ros::spin();

  return 0;
}
edit retag flag offensive close merge delete

Comments

Did you ever figure it out? I'm having the same bug.

sbloch gravatar image sbloch  ( 2016-07-18 14:28:08 -0600 )edit