Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 import time
00019 import rospy
00020 import rosnode
00021
00022
00023 def rosnode_ping_all(verbose=False):
00024 """
00025 Ping all running nodes
00026 @return [str], [str]: pinged nodes, un-pingable nodes
00027 @raise ROSNodeIOException: if unable to communicate with master
00028 """
00029 master = rosnode.rosgraph.Master(rosnode.ID)
00030 try:
00031 state = master.getSystemState()
00032 except rosnode.socket.error:
00033 raise rosnode.ROSNodeIOException("Unable to communicate with master!")
00034
00035 nodes = []
00036 for s in state:
00037 for t, l in s:
00038 nodes.extend(l)
00039 nodes = list(set(nodes))
00040 if verbose:
00041 print("Will ping the following nodes: \n"+''.join([" * %s\n"%n for n in nodes]))
00042 pinged = {}
00043 unpinged = []
00044 for node in nodes:
00045 start = time.time()
00046 status = rosnode.rosnode_ping(node, max_count=1, verbose=verbose)
00047 end = time.time()
00048 dur = (end-start)*1000.
00049 if status:
00050 pinged.update({node:dur})
00051 else:
00052 unpinged.append(node)
00053
00054 return pinged, unpinged
00055
00056 def rosnode_cleanup():
00057 """
00058 This is a semi-hidden routine for cleaning up stale node
00059 registration information on the ROS Master. The intent is to
00060 remove this method once Master TTLs are properly implemented.
00061 """
00062 pinged, unpinged = rosnode_ping_all()
00063 if unpinged:
00064 master = rosnode.rosgraph.Master(rosnode.ID)
00065 rosnode.cleanup_master_blacklist(master, unpinged)
00066
00067 return pinged, unpinged