def getRobots(refresh=False, withJson=True):
    ## \brief Get robots managed by firos
    # \param Refresh the robot list
    # \param Merge the robots with the configurtation JSON
    try:
        robots = copy.deepcopy(RosConfigurator.systemTopics(refresh))
        if withJson:
            robots_json = getRobotsByJson()
            for robot_name in robots_json:
                robot_name = str(robot_name)
                if robot_name not in robots:
                    robots[robot_name] = {"topics": {}}
                for topic_name in robots_json[robot_name]["topics"]:
                    topic = robots_json[robot_name]["topics"][topic_name]

                    robots[robot_name]["topics"][str(topic_name)] = {
                        "msg":
                        str(topic["msg"])
                        if type(topic["msg"]) is str else topic["msg"],
                        "type":
                        str(topic["type"])
                    }
        return robots

    except Exception as e:
        traceback.print_exc()
        Log("ERROR", e)
        return {}
Esempio n. 2
0
def onConnect(request, action):
    ## \brief Launch robot search and connection
    # \param client request
    # \param action
    Log("INFO", "Connecting robots")
    loadMsgHandlers(RosConfigurator.systemTopics(True))
    request.send_response(200)
    request.end_headers()
    request.wfile.write("")
Esempio n. 3
0
def getRobots(refresh=False):
    ''' This retrieves the current configuration from FIROS.
        Here we load the `robots.json` and the 'whitelist.json'

        In case the `whitelist.json` is Empty: We do get the current robots 
        from ROS and are adding them as subscribers (by default). In a small
        ROS-World this usually is no problem. But in an environment with many 
        robots we might send a lot of data. 
    '''
    try:
        # Retrieves the whitelist.json. If it does not exists, it returns all topics.
        topics_regex = copy.deepcopy(RosConfigurator.systemTopics(refresh))

        # Retrieves the robots.json.
        topics_json = getTopicsByJson()
        if len(topics_json) == 0:
            Log(
                "ERROR",
                "The file 'topics.json' is either empty or does not exist!\n\nExiting"
            )
            sys.exit(1)

        # check if structure is as needed
        for key in topics_json.keys():
            if len(topics_json[key]) != 2:
                Log(
                    "ERROR",
                    "The topic: '{}', does not have a list of length 2 (topics.json)! \n\nExiting"
                    .format(key))
                sys.exit(1)

            if not key.startswith("/"):
                Log(
                    "ERROR",
                    "The topic: '{}', does not start with '/'  (topics.json)! \n\nExiting"
                    .format(key))
                sys.exit(1)

            if topics_json[key][1] not in ["publisher", "subscriber"]:
                Log(
                    "ERROR",
                    "The topic: '{}', does not specify publisher or subscriber (topics.json)! \n\nExiting"
                    .format(key))
                sys.exit(1)

        # Merge both dictionaties:
        # Here topics_json overrides entries in topics_regex:
        topics_regex.update(topics_json)
        topics = topics_regex

        return topics

    except Exception as e:
        traceback.print_exc()
        Log("ERROR", e)
        return {}
Esempio n. 4
0
def onConnect(request, action):
    ''' This resets firos into its original state

        TODO DL reset, instead of connect?
        TODO DL Add real connect for only one Robot?
    '''
    Log("INFO", "Connecting topics")
    loadMsgHandlers(RosConfigurator.systemTopics(True))

    # Return Success
    end_request(request, None, 200, "")
Esempio n. 5
0
def getRobots(refresh=False):
    ''' This retrieves the current configuration from FIROS.
        Here we load the `robots.json` and the 'whitelist.json'

        In case the `whitelist.json` is Empty: We do get the current robots 
        from ROS and are adding them as subscribers (by default). In a small
        ROS-World this usually is no problem. But in an environment with many 
        robots we might send a lot of data. 
    '''
    try:
        # Retrieves the whitelist.json. If it does not exists, it returns all topics.
        robots = copy.deepcopy(RosConfigurator.systemTopics(refresh))

        # Retrieves the robots.json.
        robots_json = getRobotsByJson()
        if len(robots_json) == 0:
            Log(
                "ERROR",
                "The file 'robots.json' is either empty or does not exist!\n\nExiting"
            )
            sys.exit(1)

        # Merge robots.json into whitelist.json (overwrite if neccessary)
        for robot_name in robots_json:
            robot_name = str(robot_name)
            if robot_name not in robots:
                robots[robot_name] = {"topics": {}}
            for topic_name in robots_json[robot_name]["topics"]:
                topic = robots_json[robot_name]["topics"][topic_name]

                # Overwrite or add!
                robots[robot_name]["topics"][str(topic_name)] = {
                    "msg": str(topic["msg"]),
                    "type": str(topic["type"])
                }

        return robots

    except Exception as e:
        traceback.print_exc()
        Log("ERROR", e)
        return {}
def _robotConnection(data):
    ## \brief Handle robot connection
    # \param robot data (Not neccessary)
    robot_name = data.data
    Log("INFO", "Connected robot: " + robot_name)
    loadMsgHandlers(RosConfigurator.systemTopics(True))