示例#1
0
def simtime_check(ctx):
    if ctx.use_sim_time:
        master = roslib.scriptutil.get_master()
        try:
            code, msg, pubtopics = master.getPublishedTopics('/roswtf', '/')
        except:
            ctx.errors.append(WtfError("Cannot talk to ROS master"))
            raise WtfException("roswtf lost connection to the ROS Master at %s"%roslib.rosenv.get_master_uri())

        if code != 1:
            raise WtfException("cannot get published topics from master: %s"%msg)
        for topic, _ in pubtopics:
            if topic in ['/time', '/clock']:
                return
        return True
示例#2
0
def probe_all_services(ctx):
    master = rosgraph.Master('/roswtf')
    errors = []
    for service_name in ctx.services:
        try:
            service_uri = master.lookupService(service_name)
        except:
            ctx.errors.append(
                WtfError("cannot contact ROS Master at %s" %
                         rosgraph.rosenv.get_master_uri()))
            raise WtfException(
                "roswtf lost connection to the ROS Master at %s" %
                rosgraph.rosenv.get_master_uri())

        try:
            headers = rosservice.get_service_headers(service_name, service_uri)
            if not headers:
                errors.append("service [%s] did not return service headers" %
                              service_name)
        except rosgraph.network.ROSHandshakeException as e:
            errors.append("service [%s] appears to be malfunctioning" %
                          service_name)
        except Exception as e:
            errors.append("service [%s] appears to be malfunctioning: %s" %
                          (service_name, e))
    return errors
示例#3
0
def _compute_system_state(ctx):
    socket.setdefaulttimeout(3.0)
    master = rosgraph.Master('/roswtf')

    # store system state
    try:
        val = master.getSystemState()
    except rosgraph.MasterException:
        return
    ctx.system_state = val

    pubs, subs, srvs = val

    # compute list of topics and services
    topics = []
    for t, _ in itertools.chain(pubs, subs):
        topics.append(t)
    services = []
    service_providers = []
    for s, l in srvs:
        services.append(s)
        service_providers.extend(l)
    ctx.topics = topics
    ctx.services = services
    ctx.service_providers = service_providers

    # compute list of nodes
    nodes = []
    for s in val:
        for t, l in s:
            nodes.extend(l)
    ctx.nodes = list(set(nodes))  #uniq

    # - compute reverse mapping of URI->nodename
    count = 0
    start = time.time()
    for n in ctx.nodes:
        count += 1
        try:
            val = master.lookupNode(n)
        except socket.error:
            ctx.errors.append(
                WtfError("cannot contact ROS Master at %s" %
                         rosgraph.rosenv.get_master_uri()))
            raise WtfException(
                "roswtf lost connection to the ROS Master at %s" %
                rosgraph.rosenv.get_master_uri())
        ctx.uri_node_map[val] = n
    end = time.time()
    # - time thresholds currently very arbitrary
    if count:
        if ((end - start) / count) > 1.:
            ctx.warnings.append(
                WtfError(
                    "Communication with master is very slow (>1s average)"))
        elif (end - start) / count > .5:
            ctx.warnings.append(
                WtfWarning(
                    "Communication with master is very slow (>0.5s average)"))
示例#4
0
def wtf_check_graph(ctx, names=None):
    master_uri = ctx.ros_master_uri
    #TODO: master rules
    # - check for stale master state

    # TODO: get the type for each topic from each publisher and see if they match up

    master = rosgraph.Master('/roswtf')
    try:
        master.getPid()
    except rospkg.MasterException:
        warning_rule(
            (True, "Cannot communicate with master, ignoring online checks"),
            True, ctx)
        return

    # fill in ctx info so we only have to compute once
    print("analyzing graph...")
    _compute_online_context(ctx)
    print("... done analyzing graph")

    if names:
        check_topics = [t for t in names if t in ctx.topics]
        check_services = [t for t in names if t in ctx.services]
        check_nodes = [t for t in names if t in ctx.nodes]
        unknown = [
            t for t in names
            if t not in check_topics + check_services + check_nodes
        ]
        if unknown:
            raise WtfException(
                "The following names were not found in the list of nodes, topics, or services:\n%s"
                % (''.join([" * %s\n" % t for t in unknown])))

        for t in check_topics:
            for r in topic_warnings:
                warning_rule(r, r[0](ctx, t), ctx)
            for r in topic_errors:
                error_rule(r, r[0](ctx, t), ctx)
        for s in check_services:
            for r in service_warnings:
                warning_rule(r, r[0](ctx, s), ctx)
            for r in service_errors:
                error_rule(r, r[0](ctx, s), ctx)
        for n in check_nodes:
            for r in node_warnings:
                warning_rule(r, r[0](ctx, n), ctx)
            for r in node_errors:
                error_rule(r, r[0](ctx, n), ctx)

    print("running graph rules...")
    for r in graph_warnings:
        warning_rule(r, r[0](ctx), ctx)
    for r in graph_errors:
        error_rule(r, r[0](ctx), ctx)
    print("... done running graph rules")
示例#5
0
def simtime_check(ctx):
    if ctx.use_sim_time:
        master = roslib.scriptutil.get_master()
        code, msg, pubtopics = master.getPublishedTopics('/roswtf', '/')
        if code != 1:
            raise WtfException("cannot get published topics from master: %s"%msg)
        for topic, _ in pubtopics:
            if topic in ['/time', '/clock']:
                return
        return True
示例#6
0
def simtime_check(ctx):
    if ctx.use_sim_time:
        master = rosgraph.Master('/roswtf')
        try:
            pubtopics = master.getPublishedTopics('/')
        except rosgraph.MasterException:
            ctx.errors.append(WtfError("Cannot talk to ROS master"))
            raise WtfException(
                "roswtf lost connection to the ROS Master at %s" %
                rosgraph.rosenv.get_master_uri())

        for topic, _ in pubtopics:
            if topic in ['/time', '/clock']:
                return
        return True
示例#7
0
def probe_all_services(ctx):
    master = roslib.scriptutil.get_master()
    errors = []
    for service_name in ctx.services:
        try:
            code, msg, service_uri = master.lookupService('/rosservice', service_name)
        except:
            ctx.errors.append(WtfError("cannot contact ROS Master at %s"%roslib.rosenv.get_master_uri()))
            raise WtfException("roswtf lost connection to the ROS Master at %s"%roslib.rosenv.get_master_uri())
        
        if code != 1:
            ctx.warnings.append(WtfWarning("Unable to lookup service [%s]"%service_name))
        else:
            try:
                headers = rosservice.get_service_headers(service_name, service_uri)
                if not headers:
                    errors.append("service [%s] did not return service headers"%service_name)
            except roslib.network.ROSHandshakeException, e:
                errors.append("service [%s] appears to be malfunctioning"%service_name)
            except Exception, e:
                errors.append("service [%s] appears to be malfunctioning: %s"%(service_name, e))