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 cc29e96f..90f0a1c9 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 @@ -361,7 +361,12 @@ class GeneratorHelpers { package_impl = node.eContainer.eContainer as AmentPackageImpl; return package_impl; } - + def static String removeLeadingSlash(String input) { + if (input !== null && input.startsWith("/")) { + return input.substring(1) + } + return input + } //Launch files generators // def check_ns(ComponentInterface component){ // if (component.hasNS){ 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 359ce657..b5f949d6 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 @@ -41,7 +41,7 @@ from launch.substitutions import LaunchConfiguration, PythonExpression, PathJoin def generate_launch_description(): ld = LaunchDescription() - + # *** PARAMETERS *** «FOR component:getRos2Nodes(system)»«IF generate_yaml(component)» «component.name»_config = os.path.join( @@ -61,11 +61,11 @@ def generate_launch_description(): # *** ROS 2 nodes *** «FOR component:getRos2Nodes(system)» - «(component as RosNode).name» = Node( + «IF !component.namespace.nullOrEmpty»«GeneratorHelpers.removeLeadingSlash(component.namespace)»_«(component as RosNode).name» = Node(«ELSE» + «(component as RosNode).name» = Node(«ENDIF» package="«((component as RosNode).from.eContainer.eContainer as AmentPackageImpl).name»",«IF !component.namespace.nullOrEmpty» namespace="«component.namespace»",«ENDIF» executable="«((component as RosNode).from.eContainer as Artifact).name»", - 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», @@ -88,7 +88,11 @@ def generate_launch_description(): # *** Add actions *** «FOR component:getRos2Nodes(system)» + «IF !component.namespace.nullOrEmpty» + ld.add_action(«GeneratorHelpers.removeLeadingSlash(component.namespace)»_«(component as RosNode).name») + «ELSE» ld.add_action(«(component as RosNode).name») + «ENDIF» «ENDFOR»«FOR subsystem:getSubsystems(system)» ld.add_action(include_«subsystem.name») «ENDFOR» @@ -96,6 +100,8 @@ def generate_launch_description(): return ld ''' + + // def void compile_list_of_ROS2components(RosSystem system, ComponentStack stack) { // components_tmp_.clear; // Ros2components.clear; @@ -150,7 +156,7 @@ def generate_launch_description(): var rename = "" - + for (connection : connections){ var rosconnection = connection as RosSystemConnectionImpl if (rosconnection.from.reference.eClass.toString.contains("RosPublisherReference")){ @@ -236,14 +242,14 @@ def generate_launch_description(): } } - + for (interface : node.rosinterfaces){ if (!remapped_interfaces.contains(interface)){ 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 (rosPublisher : interfaces.toList) { 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 ffcd401f..a1d5b499 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 @@ -10,6 +10,7 @@ import system.impl.RosServiceClientReferenceImpl import system.impl.RosServiceServerReferenceImpl import system.impl.RosSubscriberReferenceImpl import com.google.inject.Inject +import system.RosParameter class READMECompiler { @@ -23,11 +24,13 @@ This package has be created automatically using the [RosTooling](https://github. It holds the launch file to run the following nodes: «FOR node:getRos2Nodes(system)» -- «(node as RosNode).name» +«IF !node.namespace.nullOrEmpty»- «GeneratorHelpers.removeLeadingSlash(node.namespace)»_«(node as RosNode).name»«ELSE» +- «(node as RosNode).name»«ENDIF» «ENDFOR» «FOR subsystem:system.subsystems» «FOR node:getRos2Nodes(subsystem)» -- «(node as RosNode).name» +«IF !node.namespace.nullOrEmpty»- «GeneratorHelpers.removeLeadingSlash(node.namespace)»_«(node as RosNode).name»«ELSE» +- «(node as RosNode).name»«ENDIF» «ENDFOR» «ENDFOR» @@ -43,7 +46,7 @@ It holds the launch file to run the following nodes: ### Using release «IF system.fromFile.nullOrEmpty» -This package can be copied to a valid ROS 2 workspace. To be sure that all the related dependencies are intalles the command **rosdep install** can be used. +This package can be copied to a valid ROS 2 workspace. To be sure that all the related dependencies are installed and the command **rosdep install** can be used. Then the workspace must be compiled using the common ROS 2 build command: ``` @@ -85,7 +88,7 @@ source install/setup.bash To execute the launch file, the following command can be called: ``` -ros2 launch «system.name» «system.name».launch.py «FOR param:system.parameter»«param.name»:=«get_param_value(param.value,param.name)» «ENDFOR» +ros2 launch «system.name» «system.name».launch.py «FOR param:system.parameter»«(param as RosParameter).name»:=«get_param_value((param as RosParameter).value,(param as RosParameter).name)» «ENDFOR» ``` The generated launch files requires the xterm package, it can be installed by: @@ -98,13 +101,13 @@ sudo apt install xterm To launch this system there is already an existing package that contains the launch file. It can be started by: ``` -ros2 launch «system.fromFile.split("/",2).get(0)» «system.fromFile.substring(system.fromFile.lastIndexOf('/') + 1)» «FOR param:system.parameter»«param.name»:=«get_param_value(param.value,param.name)» «ENDFOR» +ros2 launch «system.fromFile.split("/",2).get(0)» «system.fromFile.substring(system.fromFile.lastIndexOf('/') + 1)» «FOR param:system.parameter»«(param as RosParameter).name»:=«get_param_value((param as RosParameter).value,(param as RosParameter).name)» «ENDFOR» ``` «ENDIF» ''' - + def IsInterfacesEmpty(System system){ for(node: getRos2Nodes(system)){ if (!(node as RosNode).rosinterfaces.empty){ @@ -118,10 +121,10 @@ ros2 launch «system.fromFile.split("/",2).get(0)» «system.fromFile.substring( } } } - + return true } - + def getPortInfo(RosInterface port ){ if(port.reference.eClass.toString.contains("RosPublisherReference") && (port.reference as RosPublisherReferenceImpl).basicGetFrom.message !== null){ return "- Publisher: "+ port.name+" ["+(port.reference as RosPublisherReferenceImpl).basicGetFrom.message.fullname+"]" @@ -144,5 +147,3 @@ ros2 launch «system.fromFile.split("/",2).get(0)» «system.fromFile.substring( } } - - diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/RosSystemGenerator.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/RosSystemGenerator.xtend index 2e016c7b..e854b3e0 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/RosSystemGenerator.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/RosSystemGenerator.xtend @@ -48,10 +48,19 @@ class RosSystemGenerator extends AbstractGenerator { if(component.eClass.name == "RosNode"){ if(!(component as RosNode).rosparameters.nullOrEmpty){ yaml_gen=true - fsa.generateFile( + if ((component as RosNode).namespace !== null){ + fsa.generateFile( + system.getName().toLowerCase+"/config/"+(component as RosNode).namespace+"_"+(component as RosNode).getName()+".yaml", + compile_toROS2yaml(component as RosNode).toString().replace("\t"," ") + ) + } + else{ + fsa.generateFile( system.getName().toLowerCase+"/config/"+(component as RosNode).getName()+".yaml", compile_toROS2yaml(component as RosNode).toString().replace("\t"," ") ) + } + }} } fsa.generateFile( @@ -89,4 +98,3 @@ class RosSystemGenerator extends AbstractGenerator { } } - diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/YamlFileCompiler_ROS2.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/YamlFileCompiler_ROS2.xtend index 0e23d95a..90082cfe 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/YamlFileCompiler_ROS2.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/YamlFileCompiler_ROS2.xtend @@ -2,18 +2,19 @@ package de.fraunhofer.ipa.rossystem.generator import com.google.inject.Inject import system.RosNode +import system.RosParameter class YamlFileCompiler_ROS2 { - + @Inject extension GeneratorHelpers def compile_toROS2yaml(RosNode component)''' «component.name»: ros__parameters: «FOR param:component.rosparameters» - «param.name»: «get_param_value(param.value,param.name)» + «param.from.name»: «get_param_value(param.value,param.name)» «ENDFOR» - + ''' - + }