ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

The difference between your code and the example tutorial here is that the tutorial is using a plain function as the callback handler, where you are trying to use a class method. Therefore to call the callback method ROS needs to know the method to call and a pointer to an instance of the object.

Now there are two ways you can use a class method as a callback function:

1) Make the method static so that no object pointer is needed to call it. This may not be appropriate in your case.

2) Subscribe to the camera topic using a ptr to the object instance that you want to receive the callback AND a pointer to the method within that object that will actually handle the callback. Here is a code snippet of this:

// instance of the imtest object to handle image callbacks.
Imtest imtestInstance;

ros::NodeHandle nh;
image_transport::ImageTransport it(nh);
image_transport::Subscriber sub;

// Subscribe to the topic using instance pointer and method pointer.
sub=it.subscribe("/sensors/camera/top/image_raw",1, Imtest::callbackSubscriber, &imtestInstance);

Hope this helps.