Example #1
0
    def __init__(self, process):
        self.process = process
        self.name = tfs.getName(process)
        self.type = tfs.getType(process)
        self.namespace = tfs.getNamespace(process)

        self.remap = []
        self.topic_ports = {}
def startGeneration():
    XMLTags.initialize()

    # Parameters

    # Input
    ocarina_ros_path = global_filepath.xml_folder_path
    xml_filename = global_filepath.xml_filename

    # Setup

    # Salvo il momento della generazione automatica, in modo da poterlo segnare nel file
    today = datetime.datetime.now()
    generated_on = today.strftime("%d/%m/%Y %H:%M:%S")
    print("Avvio generazione: {}".format(generated_on))

    # Read XML

    # Leggo il file XML generato dal backend ever_xml
    tree = etree.parse(os.path.join(ocarina_ros_path, xml_filename))

    # Ottengo la root del system preso in considerazione
    system_root = tree.getroot()

    # Siccome itererò su tutti i vari system disponbili, inzio ad aggiungere
    # la mia system root, dopo mano a mano aggiungerò anche tutti gli altri system su
    # cui fare code-generation
    systems = [{'system': system_root, 'parent': None}]

    while len(systems) > 0:
        s = systems.pop(0)

        generateSystemCode(s['system'], s['parent'])

        # Mi cerco eventuali system dentro ad altri system. Questo serve nel caso in cui un
        # system sia usato come subcomponents di un altro system. La cosa è ricorsiva, poiché
        # di volta in volta la system_root diventa il system considerato.
        # La prima visita si fa comunque alla system root, dopo si passa a visitare ricorsivamente
        # tutti i vari system
        sub_systems = s['system'].findall("./" +
                                          XMLTags.tags['TAG_SUBCOMPONENTS'] +
                                          "/" +
                                          XMLTags.tags['TAG_SUBCOMPONENT'] +
                                          "/" + XMLTags.tags['TAG_SYSTEM'] +
                                          "/" + "[" +
                                          XMLTags.tags['TAG_CATEGORY'] +
                                          "='system']")

        # Io so chi è il genitore dei nodi, mi basta chiedere il system con quel certo
        # namespace al systems manager
        system_parent = sm.getSystemForNamespace(tfs.getNamespace(s['system']))

        for sub_sys in sub_systems:
            systems.append({'system': sub_sys, 'parent': system_parent})

    sm.generateAllSystems()
Example #3
0
    def __init__(self, system_root, namespace=None):

        # Caso di system veri e propri che contengono process
        if system_root is not None:
            self.system_root = system_root
            self.namespace = tfs.getNamespace(system_root)
            # Log dell'inizio della generazione del system
            log.info("System {}".format(tfs.getType(system_root)))

        # Caso di system che sono composti da data e basta e quindi
        # non hanno una vera e propria system root
        else:
            self.system_root = None
            self.namespace = namespace
            log.info("Data system {}".format(self.namespace))

        # Creo i file CMakeLists e PackageXML
        self.cmake_list = CMakeLists(self)
        self.package_xml = PackageXML(self)

        # Variabile che conterrà il launch file
        self.launch_file = None

        # Resetto la struttura di cartelle (eliminando anche tutti i file) solamente alla prima generazione
        # del namespace, in tutte le altre i file non vengono eliminati
        self.system_folder = folderTree.createSystemFolderTree(self.namespace,
                                                               delete=(not sm.isSystemAlreadyReset(self.namespace)))
        sm.addResetSystem(self.namespace)

        # Contiene tutti i nodi da generare
        self.nodes = []

        # Contiene tutti i messaggi da generare
        self.messages = []

        # Contiene tutti i servizi da generare
        self.services = []
def generateSystemCode(system_root, system_parent):
    # Generando il system si generano anche i file CMakeLists e PackageXML
    # Viene generata tutto l'albero delle cartelle e viene resettato se necessario
    namespace = tfs.getNamespace(system_root)

    system = sm.getSystemForNamespace(namespace)
    if system is None:
        system = System(system_root)
        sm.addSystem(system)

    # Se il system non ha un launch file associato e serve crearlo, allora lo creo
    # Il launch file a questo punto è vuoto
    if system.launch_file is None:
        system.createLaunchFile()

        # Se ho un genitore, ovvero un system che mi ha incluso,
        # lo avviso che dovrà includermi
        if system_parent:
            if system_parent.launch_file:
                system_parent.launch_file.addSubSystem(system.launch_file)

    # Ricerco tutti i processi all'interno del system
    processes = system_root.findall("./" + XMLTags.tags['TAG_SUBCOMPONENTS'] +
                                    "/" + XMLTags.tags['TAG_SUBCOMPONENT'] +
                                    "/" + "[" + XMLTags.tags['TAG_CATEGORY'] +
                                    "='process']" + "[" +
                                    XMLTags.tags['TAG_NAMESPACE'] + "='" +
                                    system.namespace + "']")

    # Scorro ogni processo. Per ogni processo controllo i subcomponent: in base alle varie tipologie
    # di subcomponent avvio la generazione di diversi nodi ROS
    for process in processes:
        threads = process.findall("./" + XMLTags.tags['TAG_SUBCOMPONENTS'] +
                                  "/" + XMLTags.tags['TAG_SUBCOMPONENT'] +
                                  "/" + "[" + XMLTags.tags['TAG_CATEGORY'] +
                                  "='thread']")

        # Cerco il main thread, che formerà la base per tutti gli altri thread.
        main_thread = process.find("./" + XMLTags.tags['TAG_SUBCOMPONENTS'] +
                                   "/" + XMLTags.tags['TAG_SUBCOMPONENT'] +
                                   "/" + "[" + XMLTags.tags['TAG_CATEGORY'] +
                                   "='thread']" + "/" + "[" +
                                   XMLTags.tags['TAG_NAME'] +
                                   "='main_thread']" + "/" + "[" +
                                   XMLTags.tags['TAG_NAMESPACE'] + "='ros']")
        if main_thread:
            thread_type = (tfs.getType(main_thread)).lower()

            p = AADLProcess(process, system_root, system)
            renameExistingNodeClass(p, system.system_folder)

            gen_main_thread = createNewThread(
                system_root, process, main_thread,
                getPythonClassFromAADLThreadType(thread_type), p)
            p.threads.append(gen_main_thread)

            for thread in threads:
                # name        = (tfs.getName(thread)).lower()
                thread_type = (tfs.getType(thread)).lower()
                namespace = (tfs.getNamespace(thread)).lower()

                if (namespace == "ros" or namespace == "global_state_machine"
                    ) and not isMainThread(thread_type):
                    new_thread = createNewThread(
                        system_root, process, thread,
                        getPythonClassFromAADLThreadType(thread_type), p)
                    if new_thread:
                        p.threads.append(new_thread)

            p.addTransformationFrameComponent()
            system.addNode(p)