Exemple #1
0
    def get_pid_of_node(self, node,
                        master=rosnode.rosgraph.Master(rosnode.ID)):
        try:
            # check if pid is already known
            if node.pid:
                return

            hostname, node_api = get_hostname_of_nodes(node_name=node.name,
                                                       master=master)

            # only take nodes, which are running on this machine
            if hostname != self.own_hostname:
                return

            # read out pid of node
            code, msg, pid = rosnode.ServerProxy(node_api).getPid(rosnode.ID)
            if code != 1:
                raise rosnode.ROSNodeException("remote call failed: '" +
                                               node.name + "'")

            node.hostname = hostname
            node.pid = pid
            node.error = NodeInfo.NO_ERROR

        except rosnode.ROSNodeException as error:
            rospy.logwarn(str(error))
        except rosnode.ROSNodeIOException as error:
            rospy.logerr(str(error))
        except IOError as error:
            if node.state == NodeData.OFFLINE:
                rospy.logwarn("Connection refused '" + str(node.name) +
                              "'; maybe its not running any more")
            else:
                rospy.logerr(str(error))
Exemple #2
0
def get_hostname_of_nodes(node_name,
                          master=rosnode.rosgraph.Master(rosnode.ID)):
    # check if master is available
    node_api = rosnode.get_api_uri(master, node_name, skip_cache=True)
    # check if node can be found
    if not node_api:
        raise rosnode.ROSNodeException("cannot find node '" + str(node_name) +
                                       "'; maybe its not running any more")

    return rosnode.urlparse.urlparse(node_api).hostname, node_api
Exemple #3
0
def _succeed(args):
    code, msg, val = args
    if code != 1:
        raise rosnode.ROSNodeException("remote call failed: %s" % msg)
    return val