How to handle disconnection/reconnection to the ROS master
I have written a ROS node, just publishing to a topic, using roscpp that runs on a separate machine to the ROS master. It is based on the simple publisher/subscriber tutorials. If the ROS master gets restarted my node no-longer appears when I query the new master with rosnode list. It needs to be able to detect that the ROS master has gone down and re-advertise it's topics when it comes back up. I haven't managed to get this to work without killing and restarting my entire process.
I can detect that the connection to the ROS master has dropped by periodically checking ros::master::check () (would love a better way). When it returns true again after the master comes back up, none of the following work:
1) Call .advertise() on the old NodeHandle and get a new publisher. I thought this would work but it doesn't seem to.
2) Create a new NodeHandle and re-advertise on that.
3) Re-run ros::init
4) Call ros::shutdown and then call ros::init core dumps.
Also: I'm assuming ros::master::check () returns false if the connection is interrupted as well as if the master is restarted, do I need to handle that case differently or will re-advertising on the same master be OK?
Ever find a solution to this?