簡體   English   中英

ROS訂閱回調-使用boost :: bind與成員函數

[英]ROS subscribe callback - using boost::bind with member functions

我正在嘗試使用所有對象的相同回調來訂閱ROS中的不同主題(彈出的每輛車一個主題)。 這個想法是boost::bind將主題名稱作為附加參數傳遞,因此我知道我應該在回調中訪問哪輛車。

問題是,即使我在該主題上經歷了多個問題,但這些解決方案似乎都無效。

基本上,我有以下VOBase類, VOBase包含一個std::map<std::string, VOAgent*> agents_ ,其成員函數如下:

void VOBase::callback_agentState(const custom_msgs::VState::ConstPtr& vStateMsg,
        std::string topic) {
    // [...] regex to find agent name from topic string
    std::string agent_name = match.str();
    // [...] Check if agent name exists, else throw exception

    // Process message
    agents_[agent_name]->pos_ = vStateMsg->pose.position;  // etc.
}

我通過此訂閱致電:

void VOBase::callback_agentList(const custom_msgs::VehicleList& vehListMsg) {
    // [...] New agent/vehicle found: process vehListMsg and get agent_name string

    // Subscribe to VState
    topic_name = agent_name + "/state_estimate";
    subscribers_[topic_name] = nodeHandlePtr->subscribe<custom_msgs::VState>(topic_name, 1,
        std::bind(&VOBase::callback_agentState, this, _1, topic_name));
}

但是,我得到了所有候選人的template argument deduction/substitution failed ,並且出現以下錯誤:

mismatched types ‘std::reference_wrapper<_Tp>’ and ‘VO::VOBase*’
                    typename add_cv<_Functor>::type&>::type>()(

我已經測試了許多的解決方案,在那里,例如使用std::ref(this)獲得std::reference_wrapper<_Tp>而不是一個VO::VOBase* (參考並不雖然生存: use of deleted function ),使用boost::bind而不是std::bind (但自C ++ 11起應該完全相同),在回調函數參數中為ROS消息使用...::ConstPtr和不使用...::ConstPtr以及在subscribe<acl_msgs::ViconState::ConstPtr>等中,所以我只是在這里處理部分解決方案及其排列...

有什么線索嗎?

我還沒有研究您顯示的代碼的細節(很難弄清未顯示的信息並推斷出需要什么)。

但是,上次我幫助具有ROS訂閱和類型推斷功能的人時,處理程序顯然應該對消息使用shared_ptr。 這可以幫助您開始查看解決方案:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM