[ros-users] How to publish a message before shutdown

Sean Matthews sean.d.matthews at gmail.com
Tue Mar 8 23:57:42 UTC 2011


Hello ros-users,

I am trying to publish a final message before a shutdown caused by a
ctrl-c signal. I haven't been able to successfully push out the
message, as it seems that ROS breaks connections with the node as soon
as a shutdown is triggered. So far, I've tried:

1. Monitoring ros::ok(). This doesn't work at all. By the time
ros::ok() is false, all subscriptions to the publication have been
cut.
2. Monitoring ros::isShuttingDown(). When this condition passes,
myPublisher.getNumSubscribers() returns > 0, but the subscribers do
not get the published message.
3. Hacking roscpp/init.cpp to have a bool shutdownRequested() function
that taps into the ros::g_shutdown_requested variable. As far as I can
tell, this is the first boolean flag that is aware of an impending
shutdown. When the shutdownRequested() condition passes,
myPublisher.getNumSubscribers() returns > 0 for the longest time out
of all three options. However, my subscriber still doesn't get the
message.

Anyone?

Thanks,
Sean



More information about the ros-users mailing list