ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
12

Best way to check if ROS is running

asked 2011-07-06 11:59:32 -0500

baalexander gravatar image

I am writing a script, which relies on ROS currently running. I would like to check if ROS is currently running on the script's machine. What's the best way to do this?

A couple ways I am considering are pinging Master URI and checking the processes. However, I'm asking to see if there's a better way. Perhaps an environment variable is set.

edit retag flag offensive close merge delete

7 Answers

Sort by ยป oldest newest most voted
8

answered 2011-07-06 15:49:18 -0500

Nash gravatar image

updated 2011-07-06 16:07:52 -0500

If you want to do it in a script, run a regex over the output of "rostopic list" for "/rosout." If its not in the output then the roscore is not running.

edit flag offensive delete link more

Comments

3
Thanks @Nash. `rostopic list ` does print out an error if roscore is not running, which I can use to check if ROS is running. However, it seems a bit hackish still.
baalexander gravatar image baalexander  ( 2011-07-07 14:27:16 -0500 )edit
1

@Nash thx this works with rostopic python API. My example can be seen here.

130s gravatar image 130s  ( 2013-05-05 11:25:55 -0500 )edit
11

answered 2015-08-11 03:44:43 -0500

updated 2015-08-11 03:45:12 -0500

In C++ you can check for the master being online, returns true if up, false if not.

#include <ros/master.h>
...
ros::master::check();
edit flag offensive delete link more
6

answered 2015-08-10 18:47:59 -0500

130s gravatar image

Found this sample in rostopic. This looks more essential API-wise.

try:
    rosgraph.Master('/rostopic').getPid()
except socket.error:
    raise ROSTopicIOException("Unable to communicate with master!")
edit flag offensive delete link more

Comments

Could this be also used to check if a node is running by specifying the /rostopic ?

MarviB16 gravatar image MarviB16  ( 2019-06-11 06:31:45 -0500 )edit
3

answered 2018-06-26 15:38:39 -0500

murali1842 gravatar image

updated 2018-11-28 19:15:51 -0500

jayess gravatar image

Gives out a boolean if the master uri is online or not

import rosgraph
if rosgraph.is_master_online(): # Checks the master uri and results boolean (True or False)
    print 'ROS MASTER is Online'
else:
    print 'ROS MASTER is Offline'
edit flag offensive delete link more

Comments

Can you please provide an explanation to go along with your code? Code with an explanation is much more valuable than code alone.

jayess gravatar image jayess  ( 2018-11-27 19:01:33 -0500 )edit
2

answered 2011-07-06 20:16:27 -0500

Ugo gravatar image

You could also use part of this answer: the following line checks periodically if ros is started.

until rostopic list ; do sleep 1; done
edit flag offensive delete link more
2

answered 2018-08-26 16:30:07 -0500

gonzalocasas gravatar image

If you start your script with roslaunch files, the best option might be what ruffsl suggested on this github issue and simply add --wait (e.g. roslaunch --wait robot_plan robot_plan.launch) to it.

edit flag offensive delete link more
0

answered 2015-08-10 19:31:33 -0500

nnnnnnils gravatar image

Why, "better"? I assume if your script requires ROS to be running, it needs certain ROS services to be available? Why not check if those services are available? I imagine that would better suit your script's question of 'do I have everything I need to run right now?'

edit flag offensive delete link more

Comments

how to check that programmatically

james P M gravatar image james P M  ( 2021-10-12 01:15:00 -0500 )edit

Question Tools

Stats

Asked: 2011-07-06 11:59:32 -0500

Seen: 21,147 times

Last updated: Nov 28 '18