Orca Ninja
Orca Ninja

Reputation: 833

ROS: subscribe function does not recognize my callback method

I am receiving this error "error: no matching function for call to ‘ros::NodeHandle::subscribe(const char [24], int, <unresolved overloaded function type>)’"

This is my call back function in my class BangBangControlUnit

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

and this is how I am using subscribe in my main function

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

Can someone tell me what I did wrong?

Upvotes: 2

Views: 8667

Answers (1)

Miguel Prada
Miguel Prada

Reputation: 96

The proper signature for creating a subscriber with a class method as callback is as follows:

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

So in your case you should use:

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

You can read more about publishers and subscribers in C++ here.

Upvotes: 7

Related Questions