Skip to content

Commit

Permalink
Merge pull request #1059 from garaemon/check-run-id
Browse files Browse the repository at this point in the history
[jsk_topic_tools] check /run_id param to know roscore is restarted or…
  • Loading branch information
garaemon committed Aug 3, 2015
2 parents 657eca0 + 574d594 commit 619f48f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions jsk_topic_tools/src/jsk_topic_tools/master_util.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import rospy
import re
import os

previous_run_id = None

def isMasterAlive():
"""
return True if master alive and return False if
master is not alive
"""
global previous_run_id
try:
# first check the host is available
master = rospy.get_master()
master_host = re.search('http://([a-zA-Z0-9\-_]*):', master.getUri()[2]).groups(1)[0]
response = os.system("ping -W 10 -c 1 " + master_host + " > /dev/null")
if response != 0:
print "master machine looks down"
return False
master.getSystemState()
run_id = rospy.get_param("/run_id")

if not previous_run_id:
previous_run_id = run_id
if run_id != previous_run_id:
print "run_id is not same"
previous_run_id = run_id
return False
return True
except Exception, e:
return False

0 comments on commit 619f48f

Please sign in to comment.