ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Problem with image_transport callback

asked 2017-01-17 09:57:16 -0600

Abind gravatar image

I have the next scenario,

class controller :
            controller(ros::NodeHandle node);
            // The callbacks are implemented correctly
            void imageCallback(const sensor_msgs::ImageConstPtr& msg);
            void navdataCallback(const ardrone_autonomy::Navdata& data);
            void foo(){
                // Do Something
                std::thread foo_thread(&controller::foo2, this);
            void foo2(){
                // Do Something
                while (something){
                    // Do Something
            //Other Stuff

and the main program is

int main(int argc, char **argv)
  ros::init(argc,argv, "main");
  ros::NodeHandle n;
  controller control(n);
  image_transport::ImageTransport it(n);
  image_transport::Subscriber sub   = it.subscribe("ardrone/image_raw", 1, &controller::imageCallback, &control);
  ros::Subscriber navdata           = n.subscribe("ardrone/navdata", 1000, &controller::navdataCallback, &control);
  return 0;

the problem is when I process data in foo2() the navdata messages arrives fine, but stop reciving image data until the end of the thread.

How can I resolve this? Is my approach correct? May be the ros::spinOnce is not placed correctly?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-01-19 19:38:13 -0600

Abind gravatar image

I will answer my own question, is not a good idea use ros::spin in diferents threads, you need to use multi thread spining.

So, in order to solve this I just put all the callbacks in a different thread, so I just need to use ros::spin in just one thread and problem solved :)

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools



Asked: 2017-01-17 09:57:16 -0600

Seen: 342 times

Last updated: Jan 19 '17