Ask Your Question

How to check if network connection or remote ROS Master is down?

asked 2018-08-21 09:43:35 -0500

pavel92 gravatar image

updated 2018-08-21 09:47:29 -0500

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.

edit retag flag offensive close merge delete


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.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-08-21 11:32:17 -0500 )edit

An alternative to checking (but something that might actually be better): a multimaster setup.

gvdhoorn gravatar image gvdhoorn  ( 2018-08-22 02:20:14 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-08-22 02:17:31 -0500

Reamees gravatar image

updated 2018-08-22 02:22:50 -0500

Seems like ros::master::check () would be one way to go.


techno74 asking and answering a similar question.

A similar function for python is mentioned in the previous question.


edit flag offensive delete link more



I tried the rosgraph.is_master_online() and it works without a problem when there is a network connection. The problem still occurs when the network goes down as the node is in limbo state. In this case rosgraph blocks the node and fails to check for the master

pavel92 gravatar image pavel92  ( 2018-08-22 03:14:39 -0500 )edit

having same issue as pavel92, every method which somehow relies on rosgraph, somehow blocks. it s as though resorption until reconnecting

Ariel_GLR gravatar image Ariel_GLR  ( 2019-04-11 03:24:26 -0500 )edit

I'm also facing this issue. I've raised a PR with rosgraph here adding an optional timeout parameter to rosgraph.is_master_online(). In the meantime, the following solution seems to be sufficient, despite feeling a little hacky

import socket
aa-tom gravatar image aa-tom  ( 2021-10-20 16:59:50 -0500 )edit

@aa-tom: might be nicer to do:

old_def_timeout = socket.getdefaulttimeout()

that would future-proof it a little more (if it ever changes).

gvdhoorn gravatar image gvdhoorn  ( 2021-10-21 02:32:41 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-08-21 09:43:35 -0500

Seen: 2,002 times

Last updated: Aug 22 '18