Example #1
0
 def __init__(self, model, name, parent):
     ServiceItem.__init__(self, model, name, parent)
     try:
         self.args = rosservice.get_service_args(self.fullname())
     except rosservice.ROSServiceIOException:
         self.args = "Error communication with service."
     self.last_args = ""
Example #2
0
def wait_service_ready(service_name, url):
    remote_service_type = ""
    while remote_service_type == "":
        remote_service_type = get_remote_service_info(service_name, url)
        if (remote_service_type == ""):
            rospy.loginfo(
                "Failed to get the remote type of service %s. Retrying...",
                service_name)
        time.sleep(1)

    local_service_type = None
    while local_service_type == None:
        local_service_type = get_service_type(service_name)
        if (local_service_type == None):
            rospy.loginfo(
                "Failed to get the local type of service %s. Retrying...",
                service_name)
        time.sleep(1)

    if remote_service_type != local_service_type:
        return None, None

    local_service_args = None
    while local_service_args == None:
        local_service_args = get_service_args(service_name)
        if (local_service_args == None):
            rospy.loginfo(
                "Failed to get the arguments list of service %s. Retrying...",
                service_name)
        time.sleep(1)

    service_args = local_service_args.split()

    return local_service_type, service_args
Example #3
0
def response(req):
    sentinel = False
    x =  req._connection_header

    currentService = str(x['service'])  + "_prime"
    client = str(x['callerid'])
    srv = subprocess.Popen("rosservice type " +currentService + " | rossrv show", shell=True, stdout=subprocess.PIPE).stdout.read()
    serviceArguments = []
    serviceArgumentsValues = []
    serviceReturns = []
    serviceReturnsValues = []

    for line in srv.split('\n'):
        if line == '---':
            sentinel = True
            continue
        if sentinel == True and line != '':
            if '/' in line.split(' ')[0]:
                serviceExpeptions.append(currentService)
                continue
            serviceReturns.append(line.split(' ')[-1])
        else:
            if line != '':
                serviceArguments.append(line.split(' ')[-1])

    hasNoArguments =  True
    if str(rosservice.get_service_args(currentService)) != "":
        hasNoArguments = False
        for x in serviceArguments:
            exec ('serviceArgumentsValues.append(req.'+ str(x) +')')

    Response = rospy.ServiceProxy(currentService, rosservice.get_service_class_by_name(currentService))

    toChange = ['.', ':', ' ']
    time = str(datetime.now())
    time = time.translate(None, '-'.join(toChange))


    if hasNoArguments == False:
        exec generateReturn(serviceArgumentsValues)
        for x in serviceReturns:
            if re.match("^[A-Za-z0-9_-]*$", x) and x != '':
                if currentService in serviceExpeptions:
                    serviceReturnsValues.append(currentService)
                    break
                exec('serviceReturnsValues.append(toReturn.'+ str(x) +')')
    else:
        toReturn = Response()
        for x in serviceReturns:
            if re.match("^[A-Za-z0-9_-]*$", x) and x != '':
                if currentService in serviceExpeptions:
                    serviceReturnsValues.append(currentService)
                    break
                exec('serviceReturnsValues.append(toReturn.'+ str(x) +')')

    report = str(generateReportSrviceCalls(currentService,serviceArguments,serviceArgumentsValues,serviceReturns,serviceReturnsValues,client))
    currentReported.append(report)
    return toReturn
Example #4
0
def response(req):
    sentinel = False
    x =  req._connection_header

    currentService = str(x['service'])  + "_prime"
    client = str(x['callerid'])
    srv = subprocess.Popen("rosservice type " +currentService + " | rossrv show", shell=True, stdout=subprocess.PIPE).stdout.read()
    serviceArguments = []
    serviceArgumentsValues = []
    serviceReturns = []
    serviceReturnsValues = []

    for line in srv.split('\n'):
        if line == '---':
            sentinel = True
            continue
        if sentinel == True and line != '':
            if '/' in line.split(' ')[0]:
                serviceExpeptions.append(currentService)
                continue
            serviceReturns.append(line.split(' ')[-1])
        else:
            if line != '':
                serviceArguments.append(line.split(' ')[-1])

    hasNoArguments =  True
    if str(rosservice.get_service_args(currentService)) != "":
        hasNoArguments = False
        for x in serviceArguments:
            exec ('serviceArgumentsValues.append(req.'+ str(x) +')')

    Response = rospy.ServiceProxy(currentService, rosservice.get_service_class_by_name(currentService))

    toChange = ['.', ':', ' ']
    time = str(datetime.now())
    time = time.translate(None, '-'.join(toChange))


    if hasNoArguments == False:
        exec generateReturn(serviceArgumentsValues)
        for x in serviceReturns:
            if re.match("^[A-Za-z0-9_-]*$", x) and x != '':
                if currentService in serviceExpeptions:
                    serviceReturnsValues.append(currentService)
                    break
                exec('serviceReturnsValues.append(toReturn.'+ str(x) +')')
    else:
        toReturn = Response()
        for x in serviceReturns:
            if re.match("^[A-Za-z0-9_-]*$", x) and x != '':
                if currentService in serviceExpeptions:
                    serviceReturnsValues.append(currentService)
                    break
                exec('serviceReturnsValues.append(toReturn.'+ str(x) +')')

    report = str(generateReportSrviceCalls(currentService,serviceArguments,serviceArgumentsValues,serviceReturns,serviceReturnsValues,client))
    currentReported.append(report)
    return toReturn
Example #5
0
def get_service_info(service_name):
    """
    GET /api/<version>/service/<service_name>

    GET information about a ROS service.
    """
    service_name = "/" + service_name
    service_type = rosservice.get_service_type(service_name)
    if not service_type:
        return error("No such service exists")
    return jsonify({
        "request_type": service_type,
        "node": rosservice.get_service_node(service_name),
        "args": rosservice.get_service_args(service_name).split(" ")
    })
Example #6
0
def get_service_info(service_name):
    """
    GET /api/<version>/service/<service_name>

    GET information about a ROS service.
    """
    service_name = "/" + service_name
    service_type = rosservice.get_service_type(service_name)
    if not service_type:
        return error("No such service exists")
    return jsonify({
        "request_type": service_type,
        "node": rosservice.get_service_node(service_name),
        "args": rosservice.get_service_args(service_name).split(" ")
    })
Example #7
0
#! /usr/bin/env python

import rosservice

servList = rosservice.get_service_list()
maestorServs = []
serviceArgs = dict()

for serv in servList:
    if "/get_loggers" not in serv and "/set_logger_level" not in serv:
        maestorServs.append(serv)


for serv in maestorServs:
    serviceArgs[serv] = rosservice.get_service_args(serv)

f = open("/opt/ros/fuerte/stacks/maestor/console/maestorapi.py", "w")

# Begin writing the console dynamically. WOO

f.write("#! /usr/bin/env python\n")
f.write("import rlcompleter\n")
f.write("import readline\n")
f.write("import rosservice\n\n")
f.write('readline.parse_and_bind("tab: complete")\n\n')
f.write("def ls():\n")
f.write("    return " + str(maestorServs) + "\n\n")


for serv in serviceArgs:
    f.write("def " + serv.replace("/", "") + " (" + serviceArgs[serv].replace(" ", ", ") + "):\n")
Example #8
0
def arch():
    try:
        rospy.init_node('handler', anonymous=True)

        currentServices = []
        loggerCount = 0
        last_topics = []
        last_nodes = []
        last_publish = {}
        last_publish1 = {}
        currentTopics = []

        loggerCount = 0

        global currentReported
        global serviceExpeptions
        global noServiceIntermediator
        global oldnoServiceIntermediator

        service_dict = {}
        old_service_dict = {}
        length = 0
        updated = False
        oldReported = list()

        while not rospy.is_shutdown():
            new_topics = rospy.get_published_topics()
            new_nodes = rosnode.get_node_names()
            new_publish = {}
            new_publish1 = {}

            inc_topics = [
                item for item in new_topics if item not in last_topics
            ]
            inc_nodes = [item for item in new_nodes if item not in last_nodes]
            inc_service_dict = {}
            inc_publish = {}
            inc_publish1 = {}
            inc_service_dict = {}
            inc_reported = {}

            for topic, typ in new_topics:
                info = rostopic.get_info_text(topic)
                subscribers = parse_info_sub(info)
                publishers = parse_info_pub(info)
                new_publish[topic] = set(subscribers)
                new_publish1[topic] = set(publishers)

                if (topic not in last_publish.keys()
                    ) or set(subscribers) != last_publish[topic]:
                    inc_publish[topic] = set(subscribers)

                if (topic not in last_publish1.keys()
                    ) or set(publishers) != last_publish1[topic]:
                    inc_publish1[topic] = set(publishers)

            try:
                for newService, Provider in get_current_services():
                    if not newService in currentServices:
                        currentServices.append(newService)
                        newServiceHandler(newService)
                        service_dict[newService] = [
                            rosservice.get_service_type(newService),
                            rosservice.get_service_args(newService)
                        ]
                        if (newService not in old_service_dict.keys()
                            ) or service_dict[newService] != old_service_dict[
                                newService]:
                            inc_service_dict[newService] = [
                                rosservice.get_service_type(newService),
                                rosservice.get_service_args(newService)
                            ]
            except Exception as e:
                print e
                pass

            if old_service_dict != service_dict:
                old_service_dict = dict(service_dict)
                updated = True

            inc_reported = [
                item for item in currentReported if item not in oldReported
            ]
            oldReported = list(currentReported)

            if len(inc_reported) != 0:
                updated = True

            if noServiceIntermediator != oldnoServiceIntermediator:
                oldnoServiceIntermediator = list(noServiceIntermediator)
                print
                print
                print 'Services calls not being reported for these services: ' + str(
                    noServiceIntermediator)

            if inc_topics or inc_nodes or inc_publish or inc_publish1 != inc_service_dict or inc_reported:
                y = {}

                y["topics"] = send_topics(inc_topics)
                y["nodes"] = send_nodes(inc_nodes)
                y["pub"] = sendPub(inc_publish)
                y["sub"] = sendSub(inc_publish1)
                y["service"] = inc_service_dict
                y["calls"] = inc_reported

                last_nodes = list(new_nodes)
                last_topics = list(new_topics)
                last_publish = dict(new_publish)
                last_publish1 = dict(new_publish1)
                updated = False

                requests.get(URL, data=json.dumps(y))

    except Exception as e:
        print e
        pass
Example #9
0
def arch(filters):
    try:
        rospy.init_node('acme_data_collector')
        filters.ignore_node.append('acme_data_collector') # Add this node to the set of things to ignore

        currentServices = []
        loggerCount = 0
        last_topics = []
        last_nodes = []
        last_publish = {}
        last_publish1 = {}
        currentTopics = []

        loggerCount = 0

        global currentReported
        global serviceExpeptions
        global noServiceIntermediator
        global oldnoServiceIntermediator

        # append list to add / to every node
        filters.ignore_node = map((lambda x : '/' + x), filters.ignore_node)


        service_dict = {}
        old_service_dict = {}
        length = 0
        updated = False
        oldReported = list()
        shortcircuit = False

        rate = 1.0/float(filters.rate) #The Hz for the rate
        r = rospy.Rate(rate)

        while not rospy.is_shutdown() and not shortcircuit:
            shortcircuit = filters.once
            pubs, subs, srvs = get_current_state(filters.ignore_node, filters.ignore_service, filters.ignore_topic)
            pubs = [pub[0] for pub in pubs]
            subs = [sub[0] for sub in subs]
            new_topics = [topic for topic in rospy.get_published_topics() if topic[0] in pubs or topic[0] in subs]
            new_nodes = rosnode.get_node_names()
            new_publish = {}
            new_publish1 = {}

            inc_topics = [item for item in new_topics if item not in last_topics and item not in filters.ignore_topic]
            inc_nodes = [item for item in new_nodes if item not in last_nodes and item not in filters.ignore_node]
            inc_service_dict = {}
            inc_publish = {}
            inc_publish1 = {}
            inc_service_dict = {}
            inc_reported = {}

            for topic, typ in new_topics:
                info = rostopic.get_info_text(topic)
                subscribers = parse_info_sub(info, filters.ignore_topic, filters.ignore_node)
                publishers = parse_info_pub(info, filters.ignore_topic, filters.ignore_node)
                new_publish[topic] = set(subscribers)
                new_publish1[topic] = set(publishers)

                if (topic not in last_publish.keys()) or set(subscribers) != last_publish[topic]:
                    inc_publish[topic] = set(subscribers)

                if (topic not in last_publish1.keys()) or set(publishers) != last_publish1[topic]:
                    inc_publish1[topic] = set(publishers)


            try:
                for newService, Provider in srvs:
                    if not newService in currentServices and not newService in filters.ignore_service:
                        currentServices.append(newService)
                        newServiceHandler(newService)
                        service_dict[newService] = [rosservice.get_service_type(newService), rosservice.get_service_args(newService)]
                        if (newService not in old_service_dict.keys()) or service_dict[newService] != old_service_dict[newService]:
                            inc_service_dict[newService] = [rosservice.get_service_type(newService), rosservice.get_service_args(newService)]
            except Exception as e:
                print e
                pass


            if old_service_dict != service_dict:
                old_service_dict = dict(service_dict)
                updated = True

            inc_reported = [item for item in currentReported if item not in oldReported]
            oldReported = list(currentReported)

            if len(inc_reported) !=  0:
                updated = True

            if noServiceIntermediator != oldnoServiceIntermediator:
                oldnoServiceIntermediator = list(noServiceIntermediator)
                print
                print
                print 'Services calls not being reported for these services: ' + str(noServiceIntermediator)

            if inc_topics or inc_nodes or inc_publish or  inc_publish1 != inc_service_dict or inc_reported:
                y = {}

                y["topics"] = send_topics(inc_topics)
                y["nodes"] = send_nodes(inc_nodes)
                y["pub"] = sendPub(inc_publish)
                y["sub"] = sendSub(inc_publish1)
                y["service"] = inc_service_dict
                y["calls"] = inc_reported


                last_nodes = list(new_nodes)
                last_topics = list(new_topics)
                last_publish = dict(new_publish)
                last_publish1 = dict(new_publish1)
                updated = False
                if filters.file is not None:
                    output = open(filters.file, 'wb')
                    output.write(json.dumps(y, indent=4))
                    output.close()
                else:
                    requests.get(URL, data=json.dumps(y))
                r.sleep()

    except Exception as e:
        print e
        pass
Example #10
0
 def args(self):
     if self._args is None:
         self._args = rosservice.get_service_args(self._name)
     return self._args
Example #11
0
def arch():
    try:
        rospy.init_node('handler', anonymous=True)

        currentServices = []
        loggerCount = 0
        last_topics = []
        last_nodes = []
        last_publish = {}
        last_publish1 = {}
        currentTopics = []

        loggerCount = 0

        global currentReported
        global serviceExpeptions
        global noServiceIntermediator
        global oldnoServiceIntermediator


        service_dict = {}
        old_service_dict = {}
        length = 0
        updated = False
        oldReported = list()

        while not rospy.is_shutdown():
            new_topics = rospy.get_published_topics()
            new_nodes = rosnode.get_node_names()
            new_publish = {}
            new_publish1 = {}

            inc_topics = [item for item in new_topics if item not in last_topics]
            inc_nodes = [item for item in new_nodes if item not in last_nodes]
            inc_service_dict = {}
            inc_publish = {}
            inc_publish1 = {}
            inc_service_dict = {}
            inc_reported = {}

            for topic, typ in new_topics:
                info = rostopic.get_info_text(topic)
                subscribers = parse_info_sub(info)
                publishers = parse_info_pub(info)
                new_publish[topic] = set(subscribers)
                new_publish1[topic] = set(publishers)

                if (topic not in last_publish.keys()) or set(subscribers) != last_publish[topic]:
                    inc_publish[topic] = set(subscribers)

                if (topic not in last_publish1.keys()) or set(publishers) != last_publish1[topic]:
                    inc_publish1[topic] = set(publishers)


            try:
                for newService, Provider in get_current_services():
                    if not newService in currentServices:
                        currentServices.append(newService)
                        newServiceHandler(newService)
                        service_dict[newService] = [rosservice.get_service_type(newService), rosservice.get_service_args(newService)]
                        if (newService not in old_service_dict.keys()) or service_dict[newService] != old_service_dict[newService]:
                            inc_service_dict[newService] = [rosservice.get_service_type(newService), rosservice.get_service_args(newService)]
            except Exception as e:
                print e
                pass


            if old_service_dict != service_dict:
                old_service_dict = dict(service_dict)
                updated = True

            inc_reported = [item for item in currentReported if item not in oldReported]
            oldReported = list(currentReported)

            if len(inc_reported) !=  0:
                updated = True

            if noServiceIntermediator != oldnoServiceIntermediator:
                oldnoServiceIntermediator = list(noServiceIntermediator)
                print
                print
                print 'Services calls not being reported for these services: ' + str(noServiceIntermediator)

            if inc_topics or inc_nodes or inc_publish or  inc_publish1 != inc_service_dict or inc_reported:
                y = {}

                y["topics"] = send_topics(inc_topics)
                y["nodes"] = send_nodes(inc_nodes)
                y["pub"] = sendPub(inc_publish)
                y["sub"] = sendSub(inc_publish1)
                y["service"] = inc_service_dict
                y["calls"] = inc_reported


                last_nodes = list(new_nodes)
                last_topics = list(new_topics)
                last_publish = dict(new_publish)
                last_publish1 = dict(new_publish1)
                updated = False

                requests.get(URL, data=json.dumps(y))

    except Exception as e:
        print e
        pass