From 2810a357b5f14a6aba49c7515b235b27d85e92de Mon Sep 17 00:00:00 2001 From: ipa-nhg Date: Mon, 13 May 2024 13:17:02 +0200 Subject: [PATCH] Fix RosSystem launch file generator issues --- .../generator/GeneratorHelpers.xtend | 26 ++++++++++++++++--- .../generator/LaunchFileCompiler_ROS2.xtend | 24 +++++++++++------ .../generator/PlantUMLCompiler.xtend | 4 +-- .../rossystem/generator/READMECompiler.xtend | 12 ++++----- 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/GeneratorHelpers.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/GeneratorHelpers.xtend index 6e5fcef5..04721360 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/GeneratorHelpers.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/GeneratorHelpers.xtend @@ -28,18 +28,36 @@ class GeneratorHelpers { String Pkg RosNode node String[] FromFileInfo + Boolean os_import def void init_pkg(){ PackageSet=false } + + def boolean YamlFileGenerated(System rossystem) { + os_import=false + for (component: getRos2Nodes(rossystem)){ + for(param:component.rosparameters){ + if(param.eContents.get(0).eClass.name.contains("ParameterStruct")){ + os_import=true + } + } + if(component.rosparameters.length>5){ + os_import=true + } + } + return os_import + } - def getNodes (System rossystem) { + def getRos2Nodes (System rossystem) { val nodeList = new ArrayList if (!rossystem.components.nullOrEmpty){ for (component: rossystem.components) { if (component.class.toString.contains("RosNode")){ - nodeList.add(component as RosNode) + if((component as RosNode).from.eContainer.eContainer.class.toString.contains("Ament")){ + nodeList.add(component as RosNode) + } } }} return nodeList @@ -57,7 +75,7 @@ class GeneratorHelpers { def ArrayList getAllRepos(System system) { RepoList = new ArrayList() - for (node : getNodes(system)){ + for (node : getRos2Nodes(system)){ if (!((node.from.eContainer.eContainer as Package).fromGitRepo.nullOrEmpty)) { val repo=(node.from.eContainer.eContainer as Package).fromGitRepo if (repo.contains(":")){ @@ -80,7 +98,7 @@ class GeneratorHelpers { def getPkgsDependencies (System rossystem){ PkgsList = new ArrayList() if (rossystem.fromFile.isNullOrEmpty) { - for (component: getNodes(rossystem)){ + for (component: getRos2Nodes(rossystem)){ init_pkg() node = component as RosNode Pkg = node.compile_pkg.toString() diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS2.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS2.xtend index ce9683a4..3303a0bb 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS2.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS2.xtend @@ -30,6 +30,7 @@ class LaunchFileCompiler_ROS2 { def compile_toROS2launch(System system) ''' +«IF YamlFileGenerated(system)»import os«ENDIF» from launch import LaunchDescription from launch_ros.actions import Node «IF !getSubsystems(system).empty»from ament_index_python.packages import get_package_share_directory«ENDIF» @@ -40,7 +41,7 @@ from launch.substitutions import LaunchConfiguration, PythonExpression, PathJoin def generate_launch_description(): ld = LaunchDescription() - «FOR component:getNodes(system)»«IF generate_yaml(component)» + «FOR component:getRos2Nodes(system)»«IF generate_yaml(component)» «component.name»_config = os.path.join( get_package_share_directory('«system.getName().toLowerCase»'), 'config', @@ -56,7 +57,7 @@ def generate_launch_description(): «ENDIF» «ENDFOR» - «FOR component:getNodes(system)» + «FOR component:getRos2Nodes(system)» «(component as RosNode).name» = Node( package="«((component as RosNode).from.eContainer.eContainer as AmentPackageImpl).name»",«IF !component.namespace.nullOrEmpty» namespace="«component.namespace»",«ENDIF» @@ -64,10 +65,9 @@ def generate_launch_description(): prefix = 'xterm -e', output='screen', name="«(component as RosNode).name»"«compile_remappings_str(component as RosNode, system.connections)»«IF !component.rosparameters.nullOrEmpty», - «IF generate_yaml(component)» - parameters = [«component.name»_config] - «ELSE»parameters=[{«FOR param:component.rosparameters» - "«param.from.name»": LaunchConfiguration("«param.name»"),«ENDFOR»}]«ENDIF»«ENDIF» +«IF generate_yaml(component)» parameters = [«component.name»_config] +«ELSE» parameters=[{«FOR param:component.rosparameters» + "«param.from.name»": LaunchConfiguration("«param.name»"),«ENDFOR»}]«ENDIF»«ENDIF» ) «ENDFOR» «FOR subsystem:getSubsystems(system)» @@ -82,7 +82,7 @@ def generate_launch_description(): «ENDIF» «ENDFOR» - «FOR component:getNodes(system)» + «FOR component:getRos2Nodes(system)» ld.add_action(«(component as RosNode).name») «ENDFOR»«FOR subsystem:getSubsystems(system)» ld.add_action(include_«subsystem.name») @@ -156,7 +156,15 @@ def generate_launch_description(): var to_action = new Object var rename = "" - + + for (interface : node.rosinterfaces){ + var origin = interface.reference.eCrossReferences.toString + var origin_name = origin.substring(origin.indexOf("name: ") + 6, origin.lastIndexOf(")]")) + if (interface.name !== origin_name){ + remap_str += "\t(\"" + origin_name + "\", \"" + interface.name + "\"),\n"; + } + } + for (connection : connections){ var rosconnection = connection as RosSystemConnectionImpl if (rosconnection.from.reference.eClass.toString.contains("RosPublisherReference")){ diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/PlantUMLCompiler.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/PlantUMLCompiler.xtend index 8562d882..e2a4157a 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/PlantUMLCompiler.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/PlantUMLCompiler.xtend @@ -17,12 +17,12 @@ class PlantUMLCompiler{ /'SUBSYSTEMS'/ «FOR subsystem:system.subsystems» component «subsystem.name» { -«FOR component:getNodes(subsystem)» +«FOR component:getRos2Nodes(subsystem)» «compile_ports(component)» «ENDFOR» } «ENDFOR» -«FOR component:getNodes(system)» +«FOR component:getRos2Nodes(system)» «compile_ports(component)» «ENDFOR» «FOR connection:system.connections» «get_connection_port((connection as RosSystemConnectionImpl).from)» --> «get_connection_port((connection as RosSystemConnectionImpl).to)» diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/READMECompiler.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/READMECompiler.xtend index 6fcb214c..ffcd401f 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/READMECompiler.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/READMECompiler.xtend @@ -22,19 +22,19 @@ This package has be created automatically using the [RosTooling](https://github. It holds the launch file to run the following nodes: -«FOR node:getNodes(system)» +«FOR node:getRos2Nodes(system)» - «(node as RosNode).name» «ENDFOR» «FOR subsystem:system.subsystems» -«FOR node:getNodes(subsystem)» +«FOR node:getRos2Nodes(subsystem)» - «(node as RosNode).name» «ENDFOR» «ENDFOR» «IF(!IsInterfacesEmpty(system))»The listed nodes offer the following connections: -«FOR node:getNodes(system)»«FOR port:(node as RosNode).rosinterfaces» +«FOR node:getRos2Nodes(system)»«FOR port:(node as RosNode).rosinterfaces» «getPortInfo(port)» -«ENDFOR»«ENDFOR»«FOR subsystem:system.subsystems»«FOR node:getNodes(subsystem)»«FOR port:(node as RosNode).rosinterfaces» +«ENDFOR»«ENDFOR»«FOR subsystem:system.subsystems»«FOR node:getRos2Nodes(subsystem)»«FOR port:(node as RosNode).rosinterfaces» «getPortInfo(port)» «ENDFOR»«ENDFOR»«ENDFOR»«ENDIF» @@ -106,13 +106,13 @@ ros2 launch «system.fromFile.split("/",2).get(0)» «system.fromFile.substring( ''' def IsInterfacesEmpty(System system){ - for(node: getNodes(system)){ + for(node: getRos2Nodes(system)){ if (!(node as RosNode).rosinterfaces.empty){ return false } } for (subsystem: system.subsystems){ - for(node: getNodes(subsystem)){ + for(node: getRos2Nodes(subsystem)){ if (!(node as RosNode).rosinterfaces.empty){ return false }