我试图订阅ROS中的不同主题(每个弹出的汽车都使用一个),使用相同的回调函数。这个想法是boost::bind
将通过主题名称作为额外的参数,所以我知道我应该在回调中访问哪个车辆。ROS订阅回调 - 对成员函数使用boost :: bind
问题是,即使我已经经历了关于该主题的多个问题,但没有任何解决方案似乎可行。
基本上,我有一个包含std::map<std::string, VOAgent*> agents_
有一个成员函数下面的类VOBase
如下:
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以来应该都是相同的),有和没有...::ConstPtr
的ROS在回调函数的参数消息(以及subscribe<acl_msgs::ViconState::ConstPtr>
等,所以我只是有部分解决方案,在这里他们的排列杂耍......
任何线索?
对不起,为什么使用绑定,而不是摆在首位拉姆达? –