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

PAUSE/STOP the ros subscriber(callback function) and restart it?

asked 2013-05-30 12:24:13 -0600

anthonyli gravatar image

updated 2013-05-30 12:27:09 -0600

According to the tutorial of cv_bridge(here is two lines of code in the tutorial, 1.4 An example ROS node),

(line 24)image_sub_ = it_.subscribe("in", 1, &ImageConverter::imageCb, this);

(line 61)ros::spin();

Base on this code, the ros::spin() will call the callback function and then always stay in the callback function! So if I want to pause the callback function or subscriber for a while, and then restart it, what should I do ?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2013-05-30 13:18:00 -0600

tfoote gravatar image

updated 2013-05-30 13:18:30 -0600

That's not how spin works. See the roscpp spinning documentation

If you want to stop receiving data you should unsubscribe and resubscribe to start the flow again. See the subscriber overview

edit flag offensive delete link more

Comments

Thank you ! I try to find the answer in the link of subscriber overview you given. But it seems nothing related to unsubscribe and resubscribe. Then I try like this, the code show in later answer. it will shutdown the subscriber, but I don't know why it doesn't resubscribe.

anthonyli gravatar image anthonyli  ( 2013-05-30 22:51:12 -0600 )edit
1

Also, for a temporary pause that needs to happen fairly quickly, you can send a message to your node causing it to start ignoring the original topic until told to resume operation.

joq gravatar image joq  ( 2013-05-31 05:45:38 -0600 )edit
1

To unsubscribe shutdown the subscriber or destruct it. And to resubscribe create a new subscriber.

tfoote gravatar image tfoote  ( 2013-05-31 07:37:21 -0600 )edit

Thank you!

anthonyli gravatar image anthonyli  ( 2013-06-01 05:39:52 -0600 )edit
1

answered 2013-05-30 22:56:48 -0600

anthonyli gravatar image

updated 2013-05-31 00:33:48 -0600

image_transport::Subscriber image_sub_;

while(1) { image_sub_=it_.subscribe("/ardrone/image_raw", 1,imageCallback); ros::spin(); ...... }

and in the end of imageCallback function I add this code, "image_sub_.shutdown()"

The final result seems, the subscriber will shutdown, but never resubscribe.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-05-30 12:24:13 -0600

Seen: 16,371 times

Last updated: May 31 '13