【发布时间】:2017-08-26 20:13:13
【问题描述】:
我正在尝试为所有主题使用相同的回调订阅 ROS 中的不同主题(每个弹出的车辆一个主题)。这个想法是boost::bind 将主题名称作为附加参数传递,因此我知道我应该在回调中访问哪个车辆。
问题在于,尽管我已经针对该主题提出了多个问题,但似乎没有一个解决方案有效。
基本上,我有以下类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),在回调函数参数中(以及在subscribe<acl_msgs::ViconState::ConstPtr>等中)带有和不带有...::ConstPtr的ROS消息。所以我只是在这里处理部分解决方案及其排列......
有什么线索吗?
【问题讨论】:
-
抱歉,为什么首先使用 bind 而不是 lambda?
标签: c++ c++11 boost ros reference-wrapper