Ask Your Question
0

Image_transport using member function as callback function

asked 2019-09-11 16:01:36 -0500

updated 2019-09-12 09:40:51 -0500

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-09-12 09:08:14 -0500

updated 2019-09-12 09:10:37 -0500

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.

edit flag offensive delete link more

Comments

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

ConstantinB gravatar imageConstantinB ( 2019-09-12 09:42:04 -0500 )edit

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

Felix Endres gravatar imageFelix Endres ( 2019-09-13 04:46:00 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-09-11 16:01:36 -0500

Seen: 13 times

Last updated: Sep 12