在類裏面實現ros的subscribe或message_filter的回調遇到的坑

坑1:沒有在ros的subscribe的輸入參數裏寫上這個類對應的指針,也就是this關鍵詞。

Segmentator{
public:
  void run(){
    pub = nh2.advertise<sensor_msgs::PointCloud2>("/cloud_without_floor", 1000);
    sub = nh.subscribe("/camera/stream/1/cloud", 1000, &Segmentator::chatterCallback);}

private:

  void chatterCallback(const sensor_msgs::PointCloud2ConstPtr &msg){...}

 

報錯:error: no matching function for call to 'ros::NodeHandle::subscribe(const char [23], int, void (Segmentator::*)(const PointCloud2ConstPtr&))'
     sub = nh.subscribe("/camera/stream/1/cloud", 1000, &Segmentator::chatterCallback);
 

辦法:sub = nh.subscribe("/camera/stream/1/cloud", 1000, &Segmentator::chatterCallback);} ->

sub = nh.subscribe("/camera/stream/1/cloud", 1000, &Segmentator::chatterCallback, this);}

坑2:使用ros的message_filter sycnchronizer時,callback的形參沒用message的ConstPtr

message_filters::Synchronizer<MySyncPolicy> sync(static_cast<const MySyncPolicy &>(my_policy), noise_subs, cloud_subs);

sync.registerCallback(boost::bind(&Segmentator::callback, this, _1, _2));

 void callback(const sensor_msgs::ImagePtr &noise_msg, const sensor_msgs::PointCloud2ConstPtr &cloud_msg){}

遇到問題:

/usr/include/boost/bind/bind.hpp:392: error: no match for call to '(boost::_mfi::mf2<void, Segmentator, const boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > >&, const boost::shared_ptr<const sensor_msgs::PointCloud2_<std::allocator<void> > >&>) (Segmentator*&, const boost::shared_ptr<const sensor_msgs::Image_<std::allocator<void> > >&, const boost::shared_ptr<const sensor_msgs::PointCloud2_<std::allocator<void> > >&)'
         unwrapper<F>::unwrap(f, 0)(a[base_type::a1_], a[base_type::a2_], a[base_type::a3_]);
                                   ^

辦法:

 void callback(const sensor_msgs::ImagePtr &noise_msg, const sensor_msgs::PointCloud2ConstPtr &cloud_msg){}->

 void callback(const sensor_msgs::ImageConstPtr &noise_msg, const sensor_msgs::PointCloud2ConstPtr &cloud_msg){}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章