Ejemplo n.º 1
0
    def __init__(self, namespace, name):
        self.name = name
        self.namespace = namespace

        # Mi prendo il system associato e se questo non esiste ne creo uno nuovo
        self.system = sm.getSystemForNamespace(namespace)

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

        self.parameters = []
        self.dependencies = []
Ejemplo n.º 2
0
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)