ROS:订阅函数无法识别我的回调方法

问题描述 投票:0回答:1

我收到此错误“错误:没有调用

‘ros::NodeHandle::subscribe(const char [24], int, <unresolved overloaded function type>)’
的匹配函数”

这是我的 BangBangControlUnit 类中的回调函数

// on message reciept: 'current_maintained_temp'
    void current_maintained_temp_callback(const std_msgs::Int32::ConstPtr& msg){
      temp_to_maintain = msg->data;      
    }

这就是我在主要功能中使用订阅的方式

// subscribe to 'current_maintained_temp'
  ros::Subscriber current_maintained_temp_sub = n.subscribe("current_maintained_temp", 1000, control.current_maintained_temp_callback);

有人可以告诉我我做错了什么吗?

c++ ros publish-subscribe
1个回答
7
投票

使用类方法作为回调创建订阅者的正确签名如下:

ros::Subscriber sub = nh.subscribe("my_topic", 1, &Foo::callback, &foo_object);

所以在你的情况下你应该使用:

current_maintained_temp_sub = n.subscribe("current_maintained_temp", 1000, &BangBangControlUnit::current_maintained_temp_callback, &control);

您可以在此处阅读有关 C++ 发布者和订阅者的更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.