Robotics StackExchange | Archived questions

Image_transport using member function as callback function

Hello!

I am trying to set up an image transport subscriber which should use a member function as callback method.

I have tried the following standard approach:

class A{
public:
    void camCallback1(const sensor_msgs::ImageConstPtr &msg) {
        // do something
    }  

int main(int argc, char **argv) {

    ros::init(argc, argv, "test_node");
    ros::NodeHandle nh;
    A a;
    image_transport::ImageTransport it(nh);

    image_transport::Subscriber subCam1 = it.subscribe("/raspi_cam1/image_raw", 2,
            &A::camCallback1,
            &a);
    ros::spin()
}

like here

This is the only of many methods i have tried that would compile for me. However the callback is never thrown.

I hope can somebody help me out here since I can not find anything regarding this particular problem in the image_transport documentation

Asked by ConstantinB on 2019-09-11 16:01:36 UTC

Comments

Answers

I guess your node exits immediately?

You need to call ros::spin() at the end of the main function to enter the loop that checks for new ros messages and calls the callback method. See the subscriber tutorial for more information.

Asked by Felix Endres on 2019-09-12 09:08:14 UTC

Comments

Sorry, I didn't include this in the code example. I did call it in my actual project

Asked by ConstantinB on 2019-09-12 09:42:04 UTC

The principle is fine, as far as I can tell. The problem is likely in your actual code

Asked by Felix Endres on 2019-09-13 04:46:00 UTC