ROS 订阅回调 - 使用 boost::绑定成员函数
ROS subscribe callback - using boost::bind with member functions
我正在尝试在 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>
中)有和没有 ROS 消息的...::ConstPtr
, 等。所以我只是在这里玩弄部分解决方案及其排列......
有什么线索吗?
我还没有研究你显示的代码的细节(很难弄清楚未显示的信息并推断出需要什么)。
但是,上次我帮助某人进行 ROS 订阅和类型推断时,很明显处理程序应该对消息进行shared_ptr。这可能有助于您开始查看解决方案:
- 使用 boost::bind 进行订阅回调时出错
相关文章:
- ROS 订阅回调 - 使用 boost::绑定成员函数
- 为什么我们需要 & in 绑定成员函数?
- 如何修改 std::generate 的绑定成员函数的结果
- 如何正确绑定成员函数与 boost::bind
- C2276 '&':对绑定成员函数表达式的非法操作
- 使用带有 boost::optional" 参数与 boost::spirit 绑定成员函数
- C 快速绑定成员功能的方法
- 模板类重载std::绑定成员函数
- 是否可以检测绑定成员函数引用的对象是否被删除或销毁
- 以可变参数方式绑定成员函数
- 传递绑定成员函数
- '&' :对绑定成员函数表达式的非法操作
- 绑定C++成员变量:getter/setter 或原始指针
- 使用boost绑定成员函数
- 具有静态绑定成员函数指针的可变模板的多个专业化
- "&":对绑定成员函数表达式的非法操作。从关键点矢量 OpenCV 获取容量
- 绑定成员函数的地址
- Boost.绑定成员函数并将其发布到io_service
- "!"绑定成员函数表达式的非法操作
- 绑定成员函数