How to check if network connection or remote ROS Master is down?
I am running ROS (Kinetic on Ubuntu 16.04) on two machines (desktop pc and Jackal pc) and the Jackal pc is set as the ROS Master. The both machines are connected over a wireless network.
I am writing a python node which is supposed to run on my machine and in case of being disconnected from the wifi to perform some action. To keep it simple for now, this action can be just a ROS warning. So my question is:
What is the best way in ROS to check/detect in the node code if the connection is down (i.e. my machine has disconnected from the network)?
When the connection goes down, the nodes that are run on my machine (in sourced terminals) are waiting for the master which is on the Jackal to be reconnected so that the publishers can continue to publish the messages. In this case when the connection is down if I run rostopic list
in a sourced terminal there is no output at all. The same goes for any rosrun/roslaunch
commands.
I am sure that there is also a way to check if there is a connection to the ROS Master but I could not find a working solution. I can always write my own timeout method but I would like to know if an proper way to do this already exists.
If this definitely isn't a 'proper' method but you could use a system call to
ifconfig <NIC_name>
to find out if your wi-fi connection is down very quickly.An alternative to checking (but something that might actually be better): a multimaster setup.