How to cleanly reset a ros application involving a number of subscribers and publishers

asked 2020-08-17 08:38:54 -0500

azerila gravatar image

updated 2020-08-17 08:42:09 -0500

I have a ros application that involves a number of iteration where at each iteration the application is reset. At each reset a number of subscribers and publishers are made again. However, I have noticed that the previous subscribers still exist and would invoke the same callback function for as many iterations that have been proceeded. This is not what I want and want to rather have a similar setup at each iteration where the callback function is called only once per a published message.

I have solved this by unregistering the previous subscribers at every reset.

However, now I am suspicious about the following cases:

1_Could there be a similar scenario about my publishers? for example since my publishers are latched, I wonder if at every reset when I make the same publishers again, equal to the number of iterations these publishers submit their last message to the subscriber.(is there also also a way to unregister or kill the publishers?

2_On another hand, from computational point of view, even after unregistering the subscribers at every reset and making new subscribers, I wonder if the threads of the previous subscribers still exist and may slow down the application after a couple of million iterations.(similar wonder also about publisher).

Is there a way to cleanly reset such ros application's subscribers and publishes at every iteration without having remaining traces that may slow down or interrupt further iterations?

edit retag flag offensive close merge delete