我收到这个错误"错误:没有匹配函数调用 ‘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的方式

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

谁能告诉我我做错了什么?

有帮助吗?

解决方案

使用类方法作为回调创建订阅服务器的正确签名如下所示:

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++中阅读有关发布者和订阅者的更多信息 这里.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top