From d5b21ee203c2182630b86a53d7c32f634dd86caf Mon Sep 17 00:00:00 2001 From: ipa-nhg Date: Tue, 18 May 2021 14:41:31 +0200 Subject: [PATCH 01/11] Add first draft for the ROS2 launch files generator --- .../generator/CMakeListsCompiler.xtend | 26 +++- .../generator/GeneratorHelpers.xtend | 1 - ...er.xtend => LaunchFileCompiler_ROS1.xtend} | 4 +- .../generator/LaunchFileCompiler_ROS2.xtend | 141 ++++++++++++++++++ .../generator/PackageXmlCompiler.xtend | 38 ++++- .../generator/RosSystemGenerator.xtend | 35 ++++- .../rossystem/generator/SetupPyCompiler.xtend | 26 ++++ 7 files changed, 258 insertions(+), 13 deletions(-) rename plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/{LaunchFileCompiler.xtend => LaunchFileCompiler_ROS1.xtend} (99%) create mode 100644 plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS2.xtend create mode 100644 plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/SetupPyCompiler.xtend diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/CMakeListsCompiler.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/CMakeListsCompiler.xtend index f250e0825..578fa0ce7 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/CMakeListsCompiler.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/CMakeListsCompiler.xtend @@ -8,7 +8,7 @@ class CMakeListsCompiler { @Inject extension GeneratorHelpers - def compile_CMakeLists(RosSystem system) '''«init_pkg()» + def compile_CMakeLists_ROS1(RosSystem system) '''«init_pkg()» cmake_minimum_required(VERSION 2.8.3) project(«system.name.toLowerCase») @@ -22,4 +22,28 @@ install(DIRECTORY launch DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} )''' + def compile_CMakeLists_ROS2(RosSystem system) '''«init_pkg()» +cmake_minimum_required(VERSION 3.5) +project(«system.name.toLowerCase») + +# Default to C++14 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) +endif() + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-Wall -Wextra -Wpedantic) +endif() + +find_package(ament_cmake REQUIRED) + +### INSTALL ### +install(DIRECTORY launch + DESTINATION share/${PROJECT_NAME} +) + +ament_package() +''' + + } \ No newline at end of file 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 4e42a9177..d8d6de374 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 @@ -40,7 +40,6 @@ class GeneratorHelpers { def compile_pkg(ComponentInterface component) '''«IF !(component.fromRosNode===null) »«component.fromRosNode.getPackage_node»«ELSEIF !PackageSet && !component.rospublisher.empty»«FOR Rospublisher:component.rospublisher»«IF !PackageSet»«Rospublisher.publisher.getPackage_pub()»«ENDIF»«ENDFOR»«ELSEIF !PackageSet && !component.rossubscriber.empty»«FOR Rossubscriber:component.rossubscriber»«IF !PackageSet»«Rossubscriber.subscriber.getPackage_sub()»«ENDIF»«ENDFOR»«ELSEIF !PackageSet && !component.rosserviceserver.empty»«FOR Rosserviceserver:component.rosserviceserver»«IF !PackageSet»«Rosserviceserver.srvserver.getPackage_srvserv()»«ENDIF»«ENDFOR»«ELSEIF !PackageSet && !component.rosserviceclient.empty»«FOR Rosserviceclient:component.rosserviceclient»«IF !PackageSet»«Rosserviceclient.srvclient.getPackage_srvcli()»«ENDIF»«ENDFOR»«ELSEIF !PackageSet && !component.rosparameter.empty»«FOR Rosparameter:component.rosparameter»«IF !PackageSet»«Rosparameter.parameter.getPackage_rosparam()»«ENDIF»«ENDFOR»«ELSEIF !PackageSet && !component.rosactionserver.empty»«FOR RosActionSever:component.rosactionserver»«IF !PackageSet»«RosActionSever.actserver.getPackage_actserver()»«ENDIF»«ENDFOR»«ELSEIF !PackageSet && !component.rosactionclient.empty»«FOR RosActionClient:component.rosactionclient»«IF !PackageSet»«RosActionClient.actclient.getPackage_actclient()»«ENDIF»«ENDFOR»«ENDIF»''' - def getPackage_pub(Publisher publisher){ package_impl = publisher.eContainer.eContainer.eContainer.toString; diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS1.xtend similarity index 99% rename from plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler.xtend rename to plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS1.xtend index f621e359e..018a3526a 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS1.xtend @@ -8,7 +8,7 @@ import org.eclipse.emf.ecore.EObject import ros.ParameterValue import rossystem.RosSystem -class LaunchFileCompiler { +class LaunchFileCompiler_ROS1 { @Inject extension GeneratorHelpers @Inject extension ComponentInterfaceCompiler @@ -22,7 +22,7 @@ class LaunchFileCompiler { int i=0; int k=0; - def compile_tolaunch(RosSystem system) '''«init_comp()» + def compile_toROS1launch(RosSystem system) '''«init_comp()» «FOR ROSParameter:system.parameter» 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 new file mode 100644 index 000000000..6fbbe7d11 --- /dev/null +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS2.xtend @@ -0,0 +1,141 @@ +package de.fraunhofer.ipa.rossystem.generator + +import com.google.inject.Inject +import componentInterface.ComponentInterface +import java.util.ArrayList +import java.util.List +import org.eclipse.emf.ecore.EObject +import ros.ParameterValue +import rossystem.RosSystem + +class LaunchFileCompiler_ROS2 { + @Inject extension GeneratorHelpers + @Inject extension ComponentInterfaceCompiler + + List ListInterfaceDef + ParameterValue ParamValue + String str_output="" + String tab_tmp="" + List sizes_list = new ArrayList(); + List param_list = new ArrayList(); + + int i=0; + int k=0; + + def compile_toROS2launch(RosSystem system) '''«init_comp()» +from launch import LaunchDescription +from launch_ros.actions import Node + +def generate_launch_description(): + ld = LaunchDescription() + + «FOR component:system.rosComponent» + «component.name» = Node( + package="«component.compile_pkg»«init_pkg»", + executable="«component.compile_art»«init_comp()»" + ) + «ENDFOR» + + «FOR component:system.rosComponent» + ld.add_action(«component.name») + «ENDFOR» + + return ld + ''' + + def check_ns(ComponentInterface component){ + if (component.hasNS){ + return component.get_ns(); + }else { + return ""; + } + } + + def String compile_struct_param(List paramMembers,Boolean sub){ + if (!sub){ + sizes_list.add(paramMembers.size); + } + for (paramMember: paramMembers ){ + if (paramMember.eClass.name=='ParameterStruct'){ + for (SubParamMember:paramMember.eContents){ + tab_tmp=" ";//rosparam has to start with a first indentation as offset - fix + for(i=1;i0){ + sizes_list.add(k); + } + } + } + //FOR PRIMITIVES: STRING, INT, ... + } else { + str_output=str_output.substring(0, str_output.length() - 1); + str_output+=compile_param_value(convertParamValue(paramMember.eContents.get(0)))+"\n"; + } + } + if (!sub){ + k=sizes_list.get(sizes_list.size-1); + k--; + sizes_list.remove(sizes_list.size() - 1); + if (k>0){ + sizes_list.add(k); + } + } + } + if (sizes_list.isEmpty){ + return str_output.replace("null",""); + } + } + + def List InterfaceDef(String name, String type){ + ListInterfaceDef = new ArrayList() + ListInterfaceDef.add(name.replace("/","_")) + ListInterfaceDef.add(name) + ListInterfaceDef.add(type) + return ListInterfaceDef + } + + def boolean hasNS(ComponentInterface component){ + if(!component.nameSpace.nullOrEmpty){ + return true; + }else{ + return false + } + } + def String get_ns(ComponentInterface component){ + return component.nameSpace.replaceFirst("/",""); + } + + def getParamName (String paramdef){ + return paramdef.substring(paramdef.indexOf("name:")+6,paramdef.indexOf(")")) + } + + def convertParamValue (Object ParamMember){ + ParamValue=ParamMember as ParameterValue + return ParamValue + } +} diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/PackageXmlCompiler.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/PackageXmlCompiler.xtend index 7343e026e..e61389743 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/PackageXmlCompiler.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/PackageXmlCompiler.xtend @@ -8,7 +8,7 @@ class PackageXmlCompiler{ @Inject extension GeneratorHelpers - def compile_package_xml(RosSystem system) '''«init_pkg()» + def compile_package_xml_format2(RosSystem system) '''«init_pkg()» «system.name.toLowerCase» 0.0.1 @@ -31,4 +31,38 @@ class PackageXmlCompiler{ ''' - } \ No newline at end of file + def compile_package_xml_format3(RosSystem system) '''«init_pkg()» + + + + «system.name.toLowerCase» + 0.0.1 + This package provides launch file for operating «system.name» + Jane Doe + Jane Doe + Apache 2.0 + + ament_cmake + + ament_index_python + launch + «FOR pkg:system.getPkgsDependencies» + «pkg» + «ENDFOR» + + + + + ament_python + + + ''' + + + } 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 5c392b4b7..c12414e14 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 @@ -43,27 +43,48 @@ class RosSystemGenerator extends AbstractGenerator { @Inject extension PackageXmlCompiler @Inject extension CMakeListsCompiler @Inject extension ComponentInterfaceCompiler - @Inject extension LaunchFileCompiler + @Inject extension LaunchFileCompiler_ROS1 + @Inject extension LaunchFileCompiler_ROS2 + @Inject extension SetupPyCompile + //@Inject extension InstallScriptCompiler override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { + for (system : resource.allContents.toIterable.filter(RosSystem)){ + fsa.generateFile(system.getName()+".componentinterface",CustomOutputProvider::CM_CONFIGURATION,system.compile_toComponentInterface) + } +// for (system : resource.allContents.toIterable.filter(RosSystem)){ +// fsa.generateFile(system.getName()+"install.sh",system.compile_toIntallScript) +// } + + // ROS1 package + for (system : resource.allContents.toIterable.filter(RosSystem)){ + fsa.generateFile(system.getName().toLowerCase+"/launch/"+system.getName()+".launch",system.compile_toROS1launch.toString().replace("\t"," ")) + } for (system : resource.allContents.toIterable.filter(RosSystem)){ - fsa.generateFile(system.getName().toLowerCase+"/launch/"+system.getName()+".launch",system.compile_tolaunch.toString().replace("\t"," ")) + fsa.generateFile(system.getName().toLowerCase+"/package.xml",system.compile_package_xml_format2) } for (system : resource.allContents.toIterable.filter(RosSystem)){ - fsa.generateFile(system.getName().toLowerCase+"/package.xml",system.compile_package_xml) + fsa.generateFile(system.getName().toLowerCase+"/CMakeLists.txt",system.compile_CMakeLists_ROS1) } + + //ROS2 package for (system : resource.allContents.toIterable.filter(RosSystem)){ - fsa.generateFile(system.getName().toLowerCase+"/CMakeLists.txt",system.compile_CMakeLists) + fsa.generateFile(system.getName().toLowerCase+"_ros2/launch/"+system.getName()+".launch",system.compile_toROS2launch.toString().replace("\t"," ")) } for (system : resource.allContents.toIterable.filter(RosSystem)){ - fsa.generateFile(system.getName()+".componentinterface",CustomOutputProvider::CM_CONFIGURATION,system.compile_toComponentInterface) + fsa.generateFile(system.getName().toLowerCase+"_ros2/package.xml",system.compile_package_xml_format3) + } + for (system : resource.allContents.toIterable.filter(RosSystem)){ + fsa.generateFile(system.getName().toLowerCase+"_ros2/setup.py",system.compile_setup_py) } // for (system : resource.allContents.toIterable.filter(RosSystem)){ -// fsa.generateFile(system.getName()+"install.sh",system.compile_toIntallScript) +// fsa.generateFile(system.getName().toLowerCase+"_ros2/CMakeLists.txt",system.compile_CMakeLists_ROS2) // } - } + + } } + diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/SetupPyCompiler.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/SetupPyCompiler.xtend new file mode 100644 index 000000000..746c29f9f --- /dev/null +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/SetupPyCompiler.xtend @@ -0,0 +1,26 @@ +package de.fraunhofer.ipa.rossystem.generator + +import rossystem.RosSystem +import com.google.inject.Inject + +class SetupPyCompile{ + + @Inject extension GeneratorHelpers + + + def compile_setup_py(RosSystem system) '''«init_pkg()» +from setuptools import setup + +PACKAGE_NAME = '«system.name.toLowerCase»' + +setup( + name=PACKAGE_NAME, + version='0.0.1', + packages=[PACKAGE_NAME], + data_files=[ + ('share/' + PACKAGE_NAME + '/launch/*.launch.py') + ], + install_requires=['setuptools'], + zip_safe=True +)''' + } From 832ce08a25961a660d7de98d910ffe3f0ab227c7 Mon Sep 17 00:00:00 2001 From: ipa-nhg Date: Wed, 19 May 2021 10:53:11 +0200 Subject: [PATCH 02/11] update for the ros2 launch file generator the node initialization --- .../ipa/rossystem/generator/LaunchFileCompiler_ROS2.xtend | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 6fbbe7d11..ab49be2d9 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 @@ -32,7 +32,9 @@ def generate_launch_description(): «FOR component:system.rosComponent» «component.name» = Node( package="«component.compile_pkg»«init_pkg»", - executable="«component.compile_art»«init_comp()»" + executable="«component.compile_art»«init_comp()»", + name="«component.name»"«IF component.hasNS», + namespace="«component.get_ns»"«ENDIF» ) «ENDFOR» From 5e61612b78b29f3fb0c752cfadb2b3d4a4539791 Mon Sep 17 00:00:00 2001 From: ipa-nhg Date: Mon, 31 May 2021 16:29:22 +0200 Subject: [PATCH 03/11] Review and clean-up rossystem generators --- .../ComponentInterfaceCompiler.xtend | 103 +++++------------- .../generator/GeneratorHelpers.xtend | 43 ++++---- .../generator/LaunchFileCompiler_ROS1.xtend | 11 +- .../generator/LaunchFileCompiler_ROS2.xtend | 78 ------------- 4 files changed, 51 insertions(+), 184 deletions(-) diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/ComponentInterfaceCompiler.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/ComponentInterfaceCompiler.xtend index 1ddfe3469..033992208 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/ComponentInterfaceCompiler.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/ComponentInterfaceCompiler.xtend @@ -22,6 +22,9 @@ import rossystem.RosSystem import ros.ParameterValue import ros.impl.ParameterStructMemberImpl import ros.Node +import ros.impl.ArtifactImpl +import org.eclipse.emf.ecore.EObject +import ros.impl.NodeImpl class ComponentInterfaceCompiler { @Inject extension GeneratorHelpers @@ -51,10 +54,8 @@ class ComponentInterfaceCompiler { boolean ArtifactSet boolean PackageSet - String artifact_impl - Object artifact_name - String node_impl - String node_name + ArtifactImpl artifact_impl + NodeImpl node_impl String param_value String value_return @@ -102,7 +103,7 @@ ComponentInterface { name «system.name» RosPublishers{ «FOR pub:pubs» «val count_pub=count_pub--» - RosPublisher "«pub.name»" { RefPublisher "«pub.publisher.package_pub».«pub.publisher.artifact_pub».«pub.publisher.node_pub».«pub.publisher.name»"}«IF count_pub > 1 »,«ENDIF» + RosPublisher "«pub.name»" { RefPublisher "«pub.publisher.package_pub».«pub.publisher.getArtifact».«pub.publisher.getNode».«pub.publisher.name»"}«IF count_pub > 1 »,«ENDIF» «ENDFOR» } «ENDIF» @@ -110,7 +111,7 @@ RosPublishers{ RosSubscribers{ «FOR sub:subs» «val count_sub=count_sub--» - RosSubscriber "«sub.name»" { RefSubscriber "«sub.subscriber.package_sub».«sub.subscriber.artifact_sub».«sub.subscriber.node_sub».«sub.subscriber.name»"}«IF count_sub > 1 »,«ENDIF» + RosSubscriber "«sub.name»" { RefSubscriber "«sub.subscriber.package_sub».«sub.subscriber.getArtifact».«sub.subscriber.getNode».«sub.subscriber.name»"}«IF count_sub > 1 »,«ENDIF» «ENDFOR» } «ENDIF» @@ -118,7 +119,7 @@ RosSubscribers{ RosSrvServers{ «FOR svrs:svrs» «val count_srvs=count_srvs--» - RosServiceServer "«svrs.name»" { RefServer "«svrs.srvserver.package_srvserv».«svrs.srvserver.artifact_srvserv».«svrs.srvserver.node_srvserv».«svrs.srvserver.name»"}«IF count_srvs > 1 »,«ENDIF» + RosServiceServer "«svrs.name»" { RefServer "«svrs.srvserver.package_srvserv».«svrs.srvserver.getArtifact».«svrs.srvserver.getNode».«svrs.srvserver.name»"}«IF count_srvs > 1 »,«ENDIF» «ENDFOR» } «ENDIF» @@ -126,7 +127,7 @@ RosSrvServers{ RosSrvClients{ «FOR svrc:svrc» «val count_srvc=count_srvc--» - RosServiceClient "«svrc.name»" { RefClient "«svrc.srvclient.package_srvcli».«svrc.srvclient.artifact_srvcli».«svrc.srvclient.node_srvcli».«svrc.srvclient.name»"}«IF count_srvc > 1 »,«ENDIF» + RosServiceClient "«svrc.name»" { RefClient "«svrc.srvclient.package_srvcli».«svrc.srvclient.getArtifact».«svrc.srvclient.getNode».«svrc.srvclient.name»"}«IF count_srvc > 1 »,«ENDIF» «ENDFOR» } «ENDIF» @@ -134,7 +135,7 @@ RosSrvClients{ RosActionServers{ «FOR acts:acts» «val count_acts=count_acts--» - RosActionServer "«acts.name»" { RefServer "«acts.actserver.package_actserver».«acts.actserver.artifact_actserver».«acts.actserver.node_actserver».«acts.actserver.name»"}«IF count_acts > 1 »,«ENDIF» + RosActionServer "«acts.name»" { RefServer "«acts.actserver.package_actserver».«acts.actserver.getArtifact».«acts.actserver.getNode».«acts.actserver.name»"}«IF count_acts > 1 »,«ENDIF» «ENDFOR» } «ENDIF» @@ -142,7 +143,7 @@ RosActionServers{ RosActionClients{ «FOR actc:actc» «val count_actc=count_actc--» - RosActionClient "«actc.name»" { RefClient "«actc.actclient.package_actclient».«actc.actclient.artifact_actclient».«actc.actclient.node_actclient».«actc.actclient.name»"}«IF count_actc > 1 »,«ENDIF» + RosActionClient "«actc.name»" { RefClient "«actc.actclient.package_actclient».«actc.actclient.getArtifact».«actc.actclient.getNode».«actc.actclient.name»"}«IF count_actc > 1 »,«ENDIF» «ENDFOR» } «ENDIF» @@ -150,7 +151,7 @@ RosActionClients{ RosParameters{ «FOR param:rosparams» «val count_param=count_param--» - RosParameter "«compile_param_name(param.parameter,"")»" { RefParameter "«param.parameter.package_rosparam».«param.parameter.artifact_rosparam».«param.parameter.node_rosparam».«param.parameter.name»"«IF param.value!==null » value «compile_rosparam_value(param.value)»«ENDIF» }«IF count_param > 1»,«ENDIF» + RosParameter "«compile_param_name(param.parameter,"")»" { RefParameter "«param.parameter.package_rosparam».«param.parameter.getArtifact».«param.parameter.getNode».«param.parameter.name»"«IF param.value!==null » value «compile_rosparam_value(param.value)»«ENDIF» }«IF count_param > 1»,«ENDIF» «ENDFOR»«FOR param:system.parameter» «val count_param=count_param--» RosParameter "«param.name»" { RefParameter "«param.name»"«IF param.value!==null » value «compile_rosparam_value(param.value)»«ENDIF» }«IF count_param > 1»,«ENDIF» @@ -167,77 +168,25 @@ RosParameters{ } def compile_art(ComponentInterface component) -'''«IF ! (component.fromRosNode===null)»«component.fromRosNode.getArtifact_rosnode»«ELSEIF !ArtifactSet && !component.rospublisher.empty»«FOR Rospublisher:component.rospublisher»«IF !ArtifactSet»«Rospublisher.publisher.getArtifact_pub()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rossubscriber.empty»«FOR Rossubscriber:component.rossubscriber»«IF !ArtifactSet»«Rossubscriber.subscriber.getArtifact_sub()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosserviceserver.empty»«FOR Rosserviceserver:component.rosserviceserver»«IF !ArtifactSet»«Rosserviceserver.srvserver.getArtifact_srvserv()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosserviceclient.empty»«FOR Rosserviceclient:component.rosserviceclient»«IF !ArtifactSet»«Rosserviceclient.srvclient.getArtifact_srvcli()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosparameter.empty»«FOR RosParameter:component.rosparameter»«IF !ArtifactSet»«RosParameter.parameter.getArtifact_rosparam()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosactionserver.empty»«FOR Rosactionserver:component.rosactionserver»«IF !ArtifactSet»«Rosactionserver.actserver.getArtifact_actserver()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosactionclient.empty»«FOR Rosactionclient:component.rosactionclient»«IF !ArtifactSet»«Rosactionclient.actclient.getArtifact_actclient()»«ENDIF»«ENDFOR»«ENDIF»''' - def getArtifact_pub(Publisher publisher){ - artifact_impl = publisher.eContainer.eContainer.toString; - return artifact_impl.getArtifact; - } - def getArtifact_sub(Subscriber subscriber){ - artifact_impl = subscriber.eContainer.eContainer.toString; - return artifact_impl.getArtifact; - } - def getArtifact_srvserv(ServiceServer serviceserver){ - artifact_impl = serviceserver.eContainer.eContainer.toString; - return artifact_impl.getArtifact; - } - def getArtifact_srvcli(ServiceClient serviceclient){ - artifact_impl = serviceclient.eContainer.eContainer.toString; - return artifact_impl.getArtifact; - } - def getArtifact_actserver(ActionServer actionserver){ - artifact_impl = actionserver.eContainer.eContainer.toString; - return artifact_impl.getArtifact; - } - def getArtifact_actclient(ActionClient actionclient){ - artifact_impl = actionclient.eContainer.eContainer.toString; - return artifact_impl.getArtifact; - } - def getArtifact_rosparam(Parameter param){ - artifact_impl = param.eContainer.eContainer.toString; - return artifact_impl.getArtifact; - } - def getArtifact_rosnode(Node node){ - artifact_impl = node.eContainer.toString; - return artifact_impl.getArtifact; - } - def getArtifact(String artifact_impl){ - artifact_name = artifact_impl.substring(artifact_impl.indexOf("name")+6,artifact_impl.length-1) +'''«IF ! (component.fromRosNode===null)»«component.fromRosNode.getArtifactFromNode»«ELSEIF !ArtifactSet && !component.rospublisher.empty»«FOR Rospublisher:component.rospublisher»«IF !ArtifactSet»«Rospublisher.publisher.getArtifact()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rossubscriber.empty»«FOR Rossubscriber:component.rossubscriber»«IF !ArtifactSet»«Rossubscriber.subscriber.getArtifact()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosserviceserver.empty»«FOR Rosserviceserver:component.rosserviceserver»«IF !ArtifactSet»«Rosserviceserver.srvserver.getArtifact()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosserviceclient.empty»«FOR Rosserviceclient:component.rosserviceclient»«IF !ArtifactSet»«Rosserviceclient.srvclient.getArtifact()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosparameter.empty»«FOR RosParameter:component.rosparameter»«IF !ArtifactSet»«RosParameter.parameter.getArtifact()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosactionserver.empty»«FOR Rosactionserver:component.rosactionserver»«IF !ArtifactSet»«Rosactionserver.actserver.getArtifact()»«ENDIF»«ENDFOR»«ELSEIF !ArtifactSet && !component.rosactionclient.empty»«FOR Rosactionclient:component.rosactionclient»«IF !ArtifactSet»«Rosactionclient.actclient.getArtifact()»«ENDIF»«ENDFOR»«ENDIF»''' + + def getArtifact(EObject interfaz){ + artifact_impl = interfaz.eContainer.eContainer as ArtifactImpl; ArtifactSet=true; - return artifact_name; + return artifact_impl.name } - def getNode_pub(Publisher publisher){ - node_impl = publisher.eContainer.toString; - return node_impl.getNode; - } - def getNode_sub(Subscriber subscriber){ - node_impl = subscriber.eContainer.toString; - return node_impl.getNode; - } - def getNode_srvserv(ServiceServer serviceserver){ - node_impl = serviceserver.eContainer.toString; - return node_impl.getNode; - } - def getNode_srvcli(ServiceClient serviceclient){ - node_impl = serviceclient.eContainer.toString; - return node_impl.getNode; - } - def getNode_actserver(ActionServer actionserver){ - node_impl = actionserver.eContainer.toString; - return node_impl.getNode; - } - def getNode_actclient(ActionClient actionclient){ - node_impl = actionclient.eContainer.toString; - return node_impl.getNode; - } - def getNode_rosparam(Parameter param){ - node_impl = param.eContainer.toString; - return node_impl.getNode; + def getArtifactFromNode(Node node){ + artifact_impl = node.eContainer as ArtifactImpl; + ArtifactSet=true; + return artifact_impl.name } - def getNode(String node_impl){ - node_name = node_impl.substring(node_impl.indexOf("name")+6,node_impl.length-1) - return node_name; + + def getNode(EObject interfaz){ + node_impl = interfaz.eContainer as NodeImpl; + return node_impl.name; } + def prefix(String NS){ if(NS===""){ 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 d8d6de374..bb2c5a25f 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 @@ -12,14 +12,14 @@ import ros.Subscriber import rossystem.RosSystem import java.util.List import ros.Node +import ros.impl.PackageImpl class GeneratorHelpers { boolean PackageSet - String package_impl + PackageImpl package_impl List PkgsList - String package_name String Pkg def void init_pkg(){ @@ -42,41 +42,36 @@ class GeneratorHelpers { '''«IF !(component.fromRosNode===null) »«component.fromRosNode.getPackage_node»«ELSEIF !PackageSet && !component.rospublisher.empty»«FOR Rospublisher:component.rospublisher»«IF !PackageSet»«Rospublisher.publisher.getPackage_pub()»«ENDIF»«ENDFOR»«ELSEIF !PackageSet && !component.rossubscriber.empty»«FOR Rossubscriber:component.rossubscriber»«IF !PackageSet»«Rossubscriber.subscriber.getPackage_sub()»«ENDIF»«ENDFOR»«ELSEIF !PackageSet && !component.rosserviceserver.empty»«FOR Rosserviceserver:component.rosserviceserver»«IF !PackageSet»«Rosserviceserver.srvserver.getPackage_srvserv()»«ENDIF»«ENDFOR»«ELSEIF !PackageSet && !component.rosserviceclient.empty»«FOR Rosserviceclient:component.rosserviceclient»«IF !PackageSet»«Rosserviceclient.srvclient.getPackage_srvcli()»«ENDIF»«ENDFOR»«ELSEIF !PackageSet && !component.rosparameter.empty»«FOR Rosparameter:component.rosparameter»«IF !PackageSet»«Rosparameter.parameter.getPackage_rosparam()»«ENDIF»«ENDFOR»«ELSEIF !PackageSet && !component.rosactionserver.empty»«FOR RosActionSever:component.rosactionserver»«IF !PackageSet»«RosActionSever.actserver.getPackage_actserver()»«ENDIF»«ENDFOR»«ELSEIF !PackageSet && !component.rosactionclient.empty»«FOR RosActionClient:component.rosactionclient»«IF !PackageSet»«RosActionClient.actclient.getPackage_actclient()»«ENDIF»«ENDFOR»«ENDIF»''' def getPackage_pub(Publisher publisher){ - package_impl = publisher.eContainer.eContainer.eContainer.toString; - return package_impl.getPackage; + package_impl = publisher.eContainer.eContainer.eContainer as PackageImpl; + return package_impl.name; } def getPackage_sub(Subscriber subscriber){ - package_impl = subscriber.eContainer.eContainer.eContainer.toString; - return package_impl.getPackage; + package_impl = subscriber.eContainer.eContainer.eContainer as PackageImpl; + return package_impl.name; } def getPackage_srvserv(ServiceServer serviceserver){ - package_impl = serviceserver.eContainer.eContainer.eContainer.toString; - return package_impl.getPackage; + package_impl = serviceserver.eContainer.eContainer.eContainer as PackageImpl; + return package_impl.name; } def getPackage_srvcli(ServiceClient serviceclient){ - package_impl = serviceclient.eContainer.eContainer.eContainer.toString; - return package_impl.getPackage; + package_impl = serviceclient.eContainer.eContainer.eContainer as PackageImpl; + return package_impl.name; } def getPackage_actserver(ActionServer actionserver){ - package_impl = actionserver.eContainer.eContainer.eContainer.toString; - return package_impl.getPackage; + package_impl = actionserver.eContainer.eContainer.eContainer as PackageImpl; + return package_impl.name; } def getPackage_actclient(ActionClient actionclient){ - package_impl = actionclient.eContainer.eContainer.eContainer.toString; - return package_impl.getPackage; + package_impl = actionclient.eContainer.eContainer.eContainer as PackageImpl; + return package_impl.name; } def getPackage_rosparam (Parameter param){ - package_impl = param.eContainer.eContainer.eContainer.toString; - return package_impl.getPackage; + package_impl = param.eContainer.eContainer.eContainer as PackageImpl; + return package_impl.name; } def getPackage_node (Node node){ - package_impl = node.eContainer.eContainer.toString; - return package_impl.getPackage; + package_impl = node.eContainer.eContainer as PackageImpl; + return package_impl.name; } - def getPackage(String package_impl){ - package_name = package_impl.substring(package_impl.indexOf("name")+6,package_impl.length-1) - PackageSet=true; - return package_name; - } -} \ No newline at end of file +} diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS1.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS1.xtend index 018a3526a..a2ac6b5b0 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS1.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS1.xtend @@ -7,6 +7,7 @@ import java.util.List import org.eclipse.emf.ecore.EObject import ros.ParameterValue import rossystem.RosSystem +import ros.impl.ParameterStructMemberImpl class LaunchFileCompiler_ROS1 { @Inject extension GeneratorHelpers @@ -30,12 +31,12 @@ class LaunchFileCompiler_ROS1 { «IF ROSParameter.value!==null» «FOR ParamMember:ROSParameter.value.eContents» - «getParamName(ParamMember.eContents.get(0).toString)»:«compile_param_value(convertParamValue(ParamMember.eContents.get(0).eContents.get(0)))» + «getParamName(ParamMember.eContents.get(0))»:«compile_param_value(convertParamValue(ParamMember.eContents.get(0).eContents.get(0)))» «ENDFOR» «ELSE» «FOR ParamMember:ROSParameter.eContents.get(0).eContents» «IF !(ParamMember.eContents.get(0).eContents.empty)» - «getParamName(ParamMember.toString)»:«compile_param_value(convertParamValue(ParamMember.eContents.get(0).eContents.get(0)))» + «getParamName(ParamMember)»:«compile_param_value(convertParamValue(ParamMember.eContents.get(0).eContents.get(0)))» «ENDIF» «ENDFOR» «ENDIF» @@ -190,7 +191,7 @@ class LaunchFileCompiler_ROS1 { for(i=1;i ListInterfaceDef - ParameterValue ParamValue - String str_output="" - String tab_tmp="" - List sizes_list = new ArrayList(); - List param_list = new ArrayList(); - - int i=0; - int k=0; def compile_toROS2launch(RosSystem system) '''«init_comp()» from launch import LaunchDescription @@ -53,66 +43,6 @@ def generate_launch_description(): } } - def String compile_struct_param(List paramMembers,Boolean sub){ - if (!sub){ - sizes_list.add(paramMembers.size); - } - for (paramMember: paramMembers ){ - if (paramMember.eClass.name=='ParameterStruct'){ - for (SubParamMember:paramMember.eContents){ - tab_tmp=" ";//rosparam has to start with a first indentation as offset - fix - for(i=1;i0){ - sizes_list.add(k); - } - } - } - //FOR PRIMITIVES: STRING, INT, ... - } else { - str_output=str_output.substring(0, str_output.length() - 1); - str_output+=compile_param_value(convertParamValue(paramMember.eContents.get(0)))+"\n"; - } - } - if (!sub){ - k=sizes_list.get(sizes_list.size-1); - k--; - sizes_list.remove(sizes_list.size() - 1); - if (k>0){ - sizes_list.add(k); - } - } - } - if (sizes_list.isEmpty){ - return str_output.replace("null",""); - } - } - def List InterfaceDef(String name, String type){ ListInterfaceDef = new ArrayList() ListInterfaceDef.add(name.replace("/","_")) @@ -132,12 +62,4 @@ def generate_launch_description(): return component.nameSpace.replaceFirst("/",""); } - def getParamName (String paramdef){ - return paramdef.substring(paramdef.indexOf("name:")+6,paramdef.indexOf(")")) - } - - def convertParamValue (Object ParamMember){ - ParamValue=ParamMember as ParameterValue - return ParamValue - } } From 4177cbd8ae1c53fe81b849a964b1f5b707d5de1f Mon Sep 17 00:00:00 2001 From: Harsh Deshpande Date: Tue, 1 Jun 2021 16:14:26 +0200 Subject: [PATCH 04/11] Add parameters support for ros2 launch file generator --- .../generator/LaunchFileCompiler_ROS2.xtend | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) 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 85df9e8fb..7e0d29031 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 @@ -5,12 +5,23 @@ import componentInterface.ComponentInterface import java.util.ArrayList import java.util.List import rossystem.RosSystem +import org.eclipse.emf.common.util.EList +import componentInterface.RosParameter +import ros.ParameterValue +import ros.impl.ParameterStringImpl +import ros.impl.ParameterIntegerImpl +import ros.impl.ParameterDoubleImpl +import ros.impl.ParameterBooleanImpl +import ros.impl.ParameterSequenceImpl +import ros.impl.ParameterStructImpl +import ros.impl.ParameterStructMemberImpl class LaunchFileCompiler_ROS2 { @Inject extension GeneratorHelpers @Inject extension ComponentInterfaceCompiler List ListInterfaceDef + int param_count def compile_toROS2launch(RosSystem system) '''«init_comp()» from launch import LaunchDescription @@ -24,7 +35,11 @@ def generate_launch_description(): package="«component.compile_pkg»«init_pkg»", executable="«component.compile_art»«init_comp()»", name="«component.name»"«IF component.hasNS», - namespace="«component.get_ns»"«ENDIF» + namespace="«component.get_ns»"«ENDIF»«IF !component.rosparameter.empty», + parameters=[ + «component.rosparameter.compile_parameters_str» + ] + «ENDIF» ) «ENDFOR» @@ -62,4 +77,47 @@ def generate_launch_description(): return component.nameSpace.replaceFirst("/",""); } + def String compile_parameters_str(EList rosParameters) { + param_count = rosParameters.length; + var param_str = ""; + for (rosParameter : rosParameters) { + val param_count=param_count--; + param_str += "{ \"" + rosParameter.parameter.name + "\" : " + get_param_value(rosParameter.value); + param_str += (param_count > 1) ? "},\n" : "}\n"; + } + return param_str; + } + + def String get_param_value(ParameterValue value) { + var param_val = ""; + if (value instanceof ParameterStringImpl) { + param_val = "\"" + (value as ParameterStringImpl).getValue() + "\""; + } else if (value instanceof ParameterIntegerImpl) { + param_val = (value as ParameterIntegerImpl).getValue().toString; + } else if (value instanceof ParameterDoubleImpl) { + param_val = (value as ParameterDoubleImpl).getValue().toString; + } else if (value instanceof ParameterBooleanImpl) { + param_val = (value as ParameterBooleanImpl).isValue().toString; + } else if (value instanceof ParameterSequenceImpl) { + param_val += "["; + var elem_count = (value as ParameterSequenceImpl).eContents.length; + for (elem : (value as ParameterSequenceImpl).eContents) { + param_val += get_param_value(elem as ParameterValue); + elem_count--; + param_val += (elem_count > 0) ? ", " : ""; + } + param_val += "]"; + } else if (value instanceof ParameterStructImpl) { + var elem_count = (value as ParameterStructImpl).eContents.length; + param_val = "\n\t{ "; + for (elem : ((value as ParameterStructImpl).eContents)) { + var member = (elem as ParameterStructMemberImpl); + param_val += "\"" + member.getName() + "\" : " + get_param_value(member.getValue()); + elem_count--; + param_val += (elem_count > 0) ? ",\n" : ""; + } + param_val += " }"; + } + return param_val; + } } From caba25c1bce1061fa0efb586e80207cd1dbcd7c7 Mon Sep 17 00:00:00 2001 From: Harsh Deshpande Date: Wed, 2 Jun 2021 16:34:39 +0200 Subject: [PATCH 05/11] generate missing files for python package description in https://docs.ros.org/en/foxy/Guides/Developing-a-ROS-2-Package.html --- .../ipa/rossystem/generator/RosSystemGenerator.xtend | 8 +++++++- .../ipa/rossystem/generator/SetupPyCompiler.xtend | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) 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 c12414e14..ae6286cef 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 @@ -72,7 +72,7 @@ class RosSystemGenerator extends AbstractGenerator { //ROS2 package for (system : resource.allContents.toIterable.filter(RosSystem)){ - fsa.generateFile(system.getName().toLowerCase+"_ros2/launch/"+system.getName()+".launch",system.compile_toROS2launch.toString().replace("\t"," ")) + fsa.generateFile(system.getName().toLowerCase+"_ros2/launch/"+system.getName()+".launch.py",system.compile_toROS2launch.toString().replace("\t"," ")) } for (system : resource.allContents.toIterable.filter(RosSystem)){ fsa.generateFile(system.getName().toLowerCase+"_ros2/package.xml",system.compile_package_xml_format3) @@ -80,6 +80,12 @@ class RosSystemGenerator extends AbstractGenerator { for (system : resource.allContents.toIterable.filter(RosSystem)){ fsa.generateFile(system.getName().toLowerCase+"_ros2/setup.py",system.compile_setup_py) } + for (system : resource.allContents.toIterable.filter(RosSystem)){ + fsa.generateFile(system.getName().toLowerCase+"_ros2/resource/" + system.getName().toLowerCase, "") + } + for (system : resource.allContents.toIterable.filter(RosSystem)){ + fsa.generateFile(system.getName().toLowerCase+"_ros2/" + system.getName().toLowerCase + "/__init__.py", "") + } // for (system : resource.allContents.toIterable.filter(RosSystem)){ // fsa.generateFile(system.getName().toLowerCase+"_ros2/CMakeLists.txt",system.compile_CMakeLists_ROS2) // } diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/SetupPyCompiler.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/SetupPyCompiler.xtend index 746c29f9f..069581892 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/SetupPyCompiler.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/SetupPyCompiler.xtend @@ -9,6 +9,8 @@ class SetupPyCompile{ def compile_setup_py(RosSystem system) '''«init_pkg()» +import os +from glob import glob from setuptools import setup PACKAGE_NAME = '«system.name.toLowerCase»' @@ -18,7 +20,13 @@ setup( version='0.0.1', packages=[PACKAGE_NAME], data_files=[ - ('share/' + PACKAGE_NAME + '/launch/*.launch.py') + # Install marker file in the package index + ('share/ament_index/resource_index/packages', + ['resource/' + PACKAGE_NAME]), + # Include our package.xml file + (os.path.join('share', PACKAGE_NAME), ['package.xml']), + # Include all launch files. + (os.path.join('share', PACKAGE_NAME, 'launch'), glob(os.path.join('launch', '*.launch.py'))) ], install_requires=['setuptools'], zip_safe=True From 7380f1fb4007f58ad592f43f682856ac7daf13a5 Mon Sep 17 00:00:00 2001 From: Harsh Deshpande Date: Wed, 2 Jun 2021 18:22:44 +0200 Subject: [PATCH 06/11] fix structs not handled in launch files --- .../generator/LaunchFileCompiler_ROS2.xtend | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) 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 7e0d29031..0fb33ea8b 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 @@ -15,6 +15,7 @@ import ros.impl.ParameterBooleanImpl import ros.impl.ParameterSequenceImpl import ros.impl.ParameterStructImpl import ros.impl.ParameterStructMemberImpl +import ros.impl.ParameterStructTypeImpl class LaunchFileCompiler_ROS2 { @Inject extension GeneratorHelpers @@ -82,13 +83,31 @@ def generate_launch_description(): var param_str = ""; for (rosParameter : rosParameters) { val param_count=param_count--; - param_str += "{ \"" + rosParameter.parameter.name + "\" : " + get_param_value(rosParameter.value); - param_str += (param_count > 1) ? "},\n" : "}\n"; + if (rosParameter.parameter.type instanceof ParameterStructTypeImpl) { + param_str += compile_struct_str(rosParameter.value, rosParameter.parameter.name); + } else { + param_str += "{ \"" + rosParameter.parameter.name + "\" : " + get_param_value(rosParameter.value, rosParameter.parameter.name); + } + param_str += (param_count > 1) ? " },\n" : " }\n"; + } + return param_str; + } + + def String compile_struct_str(ParameterValue value, String name) { + var param_str = ""; + var elem_count = (value as ParameterSequenceImpl).eContents.length; + + for (elem : ((value as ParameterSequenceImpl).eContents)) { + var member = ((elem as ParameterStructImpl).eContents.get(0) as ParameterStructMemberImpl); + param_str += "{ \"" + name + "/" + member.getName() + "\" : " + get_param_value(member.getValue(), member.getName()); + elem_count--; + param_str += (elem_count > 0) ? " },\n" : ""; } + return param_str; } - def String get_param_value(ParameterValue value) { + def String get_param_value(ParameterValue value, String name) { var param_val = ""; if (value instanceof ParameterStringImpl) { param_val = "\"" + (value as ParameterStringImpl).getValue() + "\""; @@ -102,21 +121,11 @@ def generate_launch_description(): param_val += "["; var elem_count = (value as ParameterSequenceImpl).eContents.length; for (elem : (value as ParameterSequenceImpl).eContents) { - param_val += get_param_value(elem as ParameterValue); + param_val += get_param_value(elem as ParameterValue, name); elem_count--; param_val += (elem_count > 0) ? ", " : ""; } param_val += "]"; - } else if (value instanceof ParameterStructImpl) { - var elem_count = (value as ParameterStructImpl).eContents.length; - param_val = "\n\t{ "; - for (elem : ((value as ParameterStructImpl).eContents)) { - var member = (elem as ParameterStructMemberImpl); - param_val += "\"" + member.getName() + "\" : " + get_param_value(member.getValue()); - elem_count--; - param_val += (elem_count > 0) ? ",\n" : ""; - } - param_val += " }"; } return param_val; } From 8f1875e673f926a6e388f73fc4fd5e16e41efe8d Mon Sep 17 00:00:00 2001 From: Harsh Deshpande Date: Tue, 8 Jun 2021 13:47:05 +0200 Subject: [PATCH 07/11] compile remappings for node interfaces --- .../generator/LaunchFileCompiler_ROS1.xtend | 269 ++++++++++++------ .../generator/LaunchFileCompiler_ROS2.xtend | 65 ++++- 2 files changed, 239 insertions(+), 95 deletions(-) diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS1.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS1.xtend index a2ac6b5b0..3170d7c6a 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS1.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS1.xtend @@ -8,6 +8,16 @@ import org.eclipse.emf.ecore.EObject import ros.ParameterValue import rossystem.RosSystem import ros.impl.ParameterStructMemberImpl +import componentInterface.RosPublisher +import org.eclipse.emf.common.util.EList +import rossystem.TopicConnection +import componentInterface.RosSubscriber +import componentInterface.RosServiceServer +import rossystem.ServiceConnection +import componentInterface.RosServiceClient +import componentInterface.RosActionClient +import rossystem.ActionConnection +import componentInterface.RosActionServer class LaunchFileCompiler_ROS1 { @Inject extension GeneratorHelpers @@ -22,7 +32,7 @@ class LaunchFileCompiler_ROS1 { int i=0; int k=0; - + def compile_toROS1launch(RosSystem system) '''«init_comp()» @@ -47,112 +57,58 @@ class LaunchFileCompiler_ROS1 { «ENDIF» «ENDFOR» - «FOR component:system.rosComponent» - «FOR rosPublisher:component.rospublisher» - «IF component.hasNS»«IF !rosPublisher.name.equals(compile_topic_name(rosPublisher.publisher,component.get_ns()))» - - «ENDIF»«ENDIF» - «ENDFOR» - «FOR rosSubscriber:component.rossubscriber» - «IF component.hasNS»«IF !rosSubscriber.name.equals(compile_topic_name(rosSubscriber.subscriber,component.get_ns()))» - - «ENDIF»«ENDIF» - «ENDFOR» - «FOR rosServiceServer:component.rosserviceserver» - «IF component.hasNS»«IF !rosServiceServer.name.equals(compile_service_name(rosServiceServer.srvserver,component.get_ns()))» - - «ENDIF»«ENDIF» - «ENDFOR» - «FOR rosServiceClient:component.rosserviceclient» - «IF component.hasNS»«IF !rosServiceClient.name.equals(compile_service_name(rosServiceClient.srvclient,component.get_ns()))» - - «ENDIF»«ENDIF» - «ENDFOR» - «FOR rosActionServer:component.rosactionserver» - «IF component.hasNS»«IF !rosActionServer.name.equals(compile_action_name(rosActionServer.actserver,component.get_ns()))» - - «ENDIF»«ENDIF» - «ENDFOR» - «FOR rosActionClient:component.rosactionclient» - «IF component.hasNS»«IF !rosActionClient.name.equals(compile_action_name(rosActionClient.actclient,component.get_ns()))» - - «ENDIF»«ENDIF» - «ENDFOR» - «ENDFOR» +««« «FOR component:system.rosComponent» + ««« «FOR rosPublisher:component.rospublisher» + ««« «IF component.hasNS»«IF !rosPublisher.name.equals(compile_topic_name(rosPublisher.publisher,component.get_ns()))» + ««« + ««« «ENDIF»«ENDIF» + ««« «ENDFOR» + ««« «FOR rosSubscriber:component.rossubscriber» + ««« «IF component.hasNS»«IF !rosSubscriber.name.equals(compile_topic_name(rosSubscriber.subscriber,component.get_ns()))» + ««« + ««« «ENDIF»«ENDIF» + ««« «ENDFOR» + ««« «FOR rosServiceServer:component.rosserviceserver» + ««« «IF component.hasNS»«IF !rosServiceServer.name.equals(compile_service_name(rosServiceServer.srvserver,component.get_ns()))» + ««« + ««« «ENDIF»«ENDIF» + ««« «ENDFOR» + ««« «FOR rosServiceClient:component.rosserviceclient» + ««« «IF component.hasNS»«IF !rosServiceClient.name.equals(compile_service_name(rosServiceClient.srvclient,component.get_ns()))» + ««« + ««« «ENDIF»«ENDIF» + ««« «ENDFOR» + ««« «FOR rosActionServer:component.rosactionserver» + ««« «IF component.hasNS»«IF !rosActionServer.name.equals(compile_action_name(rosActionServer.actserver,component.get_ns()))» + ««« + ««« «ENDIF»«ENDIF» + ««« «ENDFOR» + ««« «FOR rosActionClient:component.rosactionclient» + ««« «IF component.hasNS»«IF !rosActionClient.name.equals(compile_action_name(rosActionClient.actclient,component.get_ns()))» + ««« + ««« «ENDIF»«ENDIF» + ««« «ENDFOR» + ««« «ENDFOR» «FOR component:system.rosComponent» «init_comp()»«init_pkg» «FOR rosPublisher:component.rospublisher» - «IF !rosPublisher.name.equals(compile_topic_name(rosPublisher.publisher,component.check_ns))» - - «ENDIF» - «FOR topicConnection:system.topicConnections» - «IF topicConnection.from.contains(rosPublisher)» - «IF !topicConnection.topicName.equals(rosPublisher.name)» - - «ENDIF» - «ENDIF» - «ENDFOR» + «remapping_function_pub(rosPublisher, component.hasNS, inTopicFromConnection(rosPublisher, system.topicConnections),component.check_ns)» «ENDFOR» «FOR rosSubscriber:component.rossubscriber» - «IF !rosSubscriber.name.equals(compile_topic_name(rosSubscriber.subscriber,component.check_ns))» - - «ENDIF» - «FOR topicConnection:system.topicConnections» - «IF topicConnection.from.contains(rosSubscriber)» - «IF !topicConnection.topicName.equals(rosSubscriber.name)» - - «ENDIF» - «ENDIF» - «ENDFOR» + «remapping_function_sub(rosSubscriber, component.hasNS, inTopicToConnection(rosSubscriber, system.topicConnections),component.check_ns)» «ENDFOR» «FOR rosServiceServer:component.rosserviceserver» - «IF !rosServiceServer.name.equals(compile_service_name(rosServiceServer.srvserver,component.check_ns))» - - «ENDIF» - «FOR topicConnection:system.topicConnections» - «IF topicConnection.from.contains(rosServiceServer)» - «IF !topicConnection.topicName.equals(rosServiceServer.name)» - - «ENDIF» - «ENDIF» - «ENDFOR» + «remapping_function_srv(rosServiceServer, component.hasNS, inServiceFromConnection(rosServiceServer, system.serviceConnections),component.check_ns)» «ENDFOR» «FOR rosServiceClient:component.rosserviceclient» - «IF !rosServiceClient.name.equals(compile_service_name(rosServiceClient.srvclient,component.check_ns))» - - «ENDIF» - «FOR topicConnection:system.topicConnections» - «IF topicConnection.from.contains(rosServiceClient)» - «IF !topicConnection.topicName.equals(rosServiceClient.name)» - - «ENDIF» - «ENDIF» - «ENDFOR» + «remapping_function_client(rosServiceClient, component.hasNS, inServiceToConnection(rosServiceClient, system.serviceConnections),component.check_ns)» «ENDFOR» «FOR rosActionServer:component.rosactionserver» - «IF !rosActionServer.name.equals(compile_action_name(rosActionServer.actserver,component.check_ns))» - - «ENDIF» - «FOR topicConnection:system.topicConnections» - «IF topicConnection.from.contains(rosActionServer)» - «IF !topicConnection.topicName.equals(rosActionServer.name)» - - «ENDIF» - «ENDIF» - «ENDFOR» + «remapping_function_acts(rosActionServer, component.hasNS, inActionFromConnection(rosActionServer, system.actionConnections),component.check_ns)» «ENDFOR» «FOR rosActionClient:component.rosactionclient» - «IF !rosActionClient.name.equals(compile_action_name(rosActionClient.actclient,component.check_ns))» - - «ENDIF» - «FOR topicConnection:system.topicConnections» - «IF topicConnection.from.contains(rosActionClient)» - «IF !topicConnection.topicName.equals(rosActionClient.name)» - - «ENDIF» - «ENDIF» - «ENDFOR» + «remapping_function_actc(rosActionClient, component.hasNS, inActionToConnection(rosActionClient, system.actionConnections),component.check_ns)» «ENDFOR» «FOR rosParameter:component.rosparameter» «IF rosParameter.parameter.type.toString.contains("ParameterStructType")»«str_output=""» @@ -171,6 +127,133 @@ class LaunchFileCompiler_ROS1 { ''' + + // TOPICS REMAP + def String remapping_function_pub(RosPublisher rosPublisher, boolean HasNS, String inConnection, String NS) { + if(inConnection!==null){ + if (!(prefix(NS)+rosPublisher.publisher.name).equals(inConnection)){ + if(HasNS){ + return "" + } else { + return "" + } + }}else if (!((prefix(NS)+rosPublisher.name).equals(compile_topic_name(rosPublisher.publisher, NS)))){ + return ""; + } + } + def String remapping_function_sub(RosSubscriber rosSubscriber, boolean HasNS, String inConnection, String NS) { + if(inConnection!==null){ + if (! (prefix(NS)+rosSubscriber.subscriber.name).equals(inConnection)){ + if(HasNS){ + return "" + } else { + return "" + } + }} else if (!((prefix(NS)+rosSubscriber.name).equals(compile_topic_name(rosSubscriber.subscriber, NS)))){ + return ""; + } + } + def String inTopicFromConnection(RosPublisher publisher, EList list) { + for (topicConnection:list){ + if (topicConnection.from.contains(publisher)){ + return topicConnection.topicName + } + } + return null ; + } + def String inTopicToConnection(RosSubscriber subscriber, EList list) { + for (topicConnection:list){ + if (topicConnection.to.contains(subscriber)){ + return topicConnection.topicName + } + } + return null ; + } + + // SERVICES REMAP + def String remapping_function_srv(RosServiceServer rosServiceServer, boolean HasNS, String inConnection, String NS) { + if(inConnection!==null){ + if (! (prefix(NS)+rosServiceServer.srvserver.name).equals(inConnection)){ + if(HasNS){ + return "" + } else { + return "" + } + }} else if (!((prefix(NS)+rosServiceServer.name).equals(compile_service_name(rosServiceServer.srvserver, NS)))){ + return ""; + } + } + def String remapping_function_client(RosServiceClient rosServiceClient, boolean HasNS, String inConnection, String NS) { + if(inConnection!==null){ + if (! (prefix(NS)+rosServiceClient.srvclient.name).equals(inConnection)){ + if(HasNS){ + return "" + } else { + return "" + } + }} else if (!((prefix(NS)+rosServiceClient.name).equals(compile_service_name(rosServiceClient.srvclient, NS)))){ + return ""; + } + } + def String inServiceFromConnection(RosServiceServer service, EList list) { + for (serviceConnection:list){ + if (serviceConnection.from.contains(service)){ + return serviceConnection.serviceName + } + } + return null ; + } + def String inServiceToConnection(RosServiceClient client, EList list) { + for (serviceConnection:list){ + if (serviceConnection.to.equals(client)){ + return serviceConnection.serviceName + } + } + return null ; + } + + // ACTIONS REMAP + def String remapping_function_acts(RosActionServer rosActionService, boolean HasNS, String inConnection, String NS) { + if(inConnection!==null){ + if (! (prefix(NS)+rosActionService.actserver.name).equals(inConnection)){ + if(HasNS){ + return "" + } else { + return "" + } + }} else if (!((prefix(NS)+rosActionService.name).equals(compile_action_name(rosActionService.actserver, NS)))){ + return ""; + } + } + def String remapping_function_actc(RosActionClient rosActionClient, boolean HasNS, String inConnection, String NS) { + if(inConnection!==null){ + if (! (prefix(NS)+rosActionClient.actclient.name).equals(inConnection)){ + if(HasNS){ + return "" + } else { + return "" + } + }} else if (!((prefix(NS)+rosActionClient.name).equals(compile_action_name(rosActionClient.actclient, NS)))){ + return ""; + } + } + def String inActionFromConnection(RosActionServer service, EList list) { + for (actionConnection:list){ + if (actionConnection.from.equals(service)){ + return actionConnection.actionName + } + } + return null ; + } + def String inActionToConnection(RosActionClient client, EList list) { + for (actionConnection:list){ + if (actionConnection.to.equals(client)){ + return actionConnection.actionName + } + } + return null ; + } + // 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 0fb33ea8b..7d03330a7 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 @@ -39,8 +39,8 @@ def generate_launch_description(): namespace="«component.get_ns»"«ENDIF»«IF !component.rosparameter.empty», parameters=[ «component.rosparameter.compile_parameters_str» - ] - «ENDIF» + ]«ENDIF» + «component.compile_remappings_str» ) «ENDFOR» @@ -78,6 +78,67 @@ def generate_launch_description(): return component.nameSpace.replaceFirst("/",""); } + def String is_comma(Integer count) { + return (count > 0) ? ",\n" : "\n" + } + + def String compile_remappings_str(ComponentInterface component) { + var remap_str = ""; + var count = component.rospublisher.length + + component.rossubscriber.length + + component.rosserviceserver.length + + component.rosserviceclient.length + + component.rosactionserver.length + + component.rosactionclient.length; + val NS = component.check_ns(); + for (rosPublisher : component.rospublisher) { + if (!((prefix(NS)+rosPublisher.name).equals(compile_topic_name(rosPublisher.publisher, NS)))) { + remap_str += "\t(\"" + rosPublisher.publisher.name + "\", \"" + rosPublisher.name + "\")"; + count--; + remap_str += is_comma(count); + } + } + for (rosSubscriber : component.rossubscriber) { + if (!((prefix(NS)+rosSubscriber.name).equals(compile_topic_name(rosSubscriber.subscriber, NS)))) { + remap_str += "\t(\"" + rosSubscriber.subscriber.name + "\", \"" + rosSubscriber.name + "\")"; + count--; + remap_str += is_comma(count); + } + } + for (rosServiceServer : component.rosserviceserver) { + if (!((prefix(NS)+rosServiceServer.name).equals(compile_service_name(rosServiceServer.srvserver, NS)))) { + remap_str += "\t(\"" + rosServiceServer.srvserver.name + "\", \"" + rosServiceServer.name + "\")"; + count--; + remap_str += is_comma(count); + } + } + for (rosServiceClient : component.rosserviceclient) { + if (!((prefix(NS)+rosServiceClient.name).equals(compile_service_name(rosServiceClient.srvclient, NS)))) { + remap_str += "\t(\"" + rosServiceClient.srvclient.name + "\", \"" + rosServiceClient.name + "\")"; + count--; + remap_str += is_comma(count); + } + } + for (rosActionServer : component.rosactionserver) { + if (!((prefix(NS)+rosActionServer.name).equals(compile_action_name(rosActionServer.actserver, NS)))) { + remap_str += "\t(\"" + rosActionServer.actserver.name + "\", \"" + rosActionServer.name + "\")"; + count--; + remap_str += is_comma(count); + } + } + for (rosActionClient : component.rosactionclient) { + if (!((prefix(NS)+rosActionClient.name).equals(compile_action_name(rosActionClient.actclient, NS)))) { + remap_str += "\t(\"" + rosActionClient.actclient.name + "\", \"" + rosActionClient.name + "\")"; + count--; + remap_str += is_comma(count); + } + } + if (!remap_str.empty) { + remap_str = ",\nremappings=[\n" + remap_str + "]\n"; + } + return remap_str; + } + def String compile_parameters_str(EList rosParameters) { param_count = rosParameters.length; var param_str = ""; From 71269afddcbdf3311ca61c2ae22c9ee95c69128e Mon Sep 17 00:00:00 2001 From: Harsh Deshpande Date: Tue, 8 Jun 2021 13:47:05 +0200 Subject: [PATCH 08/11] compile remappings for node interfaces --- .../ipa/rossystem/generator/LaunchFileCompiler_ROS1.xtend | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS1.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS1.xtend index 3170d7c6a..5befdf054 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS1.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/LaunchFileCompiler_ROS1.xtend @@ -41,12 +41,12 @@ class LaunchFileCompiler_ROS1 { «IF ROSParameter.value!==null» «FOR ParamMember:ROSParameter.value.eContents» - «getParamName(ParamMember.eContents.get(0))»:«compile_param_value(convertParamValue(ParamMember.eContents.get(0).eContents.get(0)))» + «getParamName(ParamMember.eContents.get(0))»: «compile_param_value(convertParamValue(ParamMember.eContents.get(0).eContents.get(0)))» «ENDFOR» «ELSE» «FOR ParamMember:ROSParameter.eContents.get(0).eContents» «IF !(ParamMember.eContents.get(0).eContents.empty)» - «getParamName(ParamMember)»:«compile_param_value(convertParamValue(ParamMember.eContents.get(0).eContents.get(0)))» + «getParamName(ParamMember)»: «compile_param_value(convertParamValue(ParamMember.eContents.get(0).eContents.get(0)))» «ENDIF» «ENDFOR» «ENDIF» From 919f05e743a385f4f3e461b26ab84a5b4296e82d Mon Sep 17 00:00:00 2001 From: ipa-nhg Date: Wed, 9 Jun 2021 17:11:09 +0200 Subject: [PATCH 09/11] simplify the compile_remappings_str function for the ROS2 launch file generator --- .../generator/LaunchFileCompiler_ROS2.xtend | 39 ++++--------------- 1 file changed, 8 insertions(+), 31 deletions(-) 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 7d03330a7..1eb1b9667 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 @@ -39,8 +39,7 @@ def generate_launch_description(): namespace="«component.get_ns»"«ENDIF»«IF !component.rosparameter.empty», parameters=[ «component.rosparameter.compile_parameters_str» - ]«ENDIF» - «component.compile_remappings_str» + ]«ENDIF»«component.compile_remappings_str» ) «ENDFOR» @@ -78,63 +77,41 @@ def generate_launch_description(): return component.nameSpace.replaceFirst("/",""); } - def String is_comma(Integer count) { - return (count > 0) ? ",\n" : "\n" - } - def String compile_remappings_str(ComponentInterface component) { var remap_str = ""; - var count = component.rospublisher.length - + component.rossubscriber.length - + component.rosserviceserver.length - + component.rosserviceclient.length - + component.rosactionserver.length - + component.rosactionclient.length; val NS = component.check_ns(); for (rosPublisher : component.rospublisher) { if (!((prefix(NS)+rosPublisher.name).equals(compile_topic_name(rosPublisher.publisher, NS)))) { - remap_str += "\t(\"" + rosPublisher.publisher.name + "\", \"" + rosPublisher.name + "\")"; - count--; - remap_str += is_comma(count); + remap_str += "\t(\"" + rosPublisher.publisher.name + "\", \"" + rosPublisher.name + "\"),\n"; } } for (rosSubscriber : component.rossubscriber) { if (!((prefix(NS)+rosSubscriber.name).equals(compile_topic_name(rosSubscriber.subscriber, NS)))) { - remap_str += "\t(\"" + rosSubscriber.subscriber.name + "\", \"" + rosSubscriber.name + "\")"; - count--; - remap_str += is_comma(count); + remap_str += "\t(\"" + rosSubscriber.subscriber.name + "\", \"" + rosSubscriber.name + "\"),\n"; } } for (rosServiceServer : component.rosserviceserver) { if (!((prefix(NS)+rosServiceServer.name).equals(compile_service_name(rosServiceServer.srvserver, NS)))) { - remap_str += "\t(\"" + rosServiceServer.srvserver.name + "\", \"" + rosServiceServer.name + "\")"; - count--; - remap_str += is_comma(count); + remap_str += "\t(\"" + rosServiceServer.srvserver.name + "\", \"" + rosServiceServer.name + "\"),\n"; } } for (rosServiceClient : component.rosserviceclient) { if (!((prefix(NS)+rosServiceClient.name).equals(compile_service_name(rosServiceClient.srvclient, NS)))) { - remap_str += "\t(\"" + rosServiceClient.srvclient.name + "\", \"" + rosServiceClient.name + "\")"; - count--; - remap_str += is_comma(count); + remap_str += "\t(\"" + rosServiceClient.srvclient.name + "\", \"" + rosServiceClient.name + "\"),\n"; } } for (rosActionServer : component.rosactionserver) { if (!((prefix(NS)+rosActionServer.name).equals(compile_action_name(rosActionServer.actserver, NS)))) { - remap_str += "\t(\"" + rosActionServer.actserver.name + "\", \"" + rosActionServer.name + "\")"; - count--; - remap_str += is_comma(count); + remap_str += "\t(\"" + rosActionServer.actserver.name + "\", \"" + rosActionServer.name + "\"),\n"; } } for (rosActionClient : component.rosactionclient) { if (!((prefix(NS)+rosActionClient.name).equals(compile_action_name(rosActionClient.actclient, NS)))) { - remap_str += "\t(\"" + rosActionClient.actclient.name + "\", \"" + rosActionClient.name + "\")"; - count--; - remap_str += is_comma(count); + remap_str += "\t(\"" + rosActionClient.actclient.name + "\", \"" + rosActionClient.name + "\"),\n"; } } if (!remap_str.empty) { - remap_str = ",\nremappings=[\n" + remap_str + "]\n"; + remap_str = ",\nremappings=[\n" + remap_str.substring(0,remap_str.length-2) + "]\n"; } return remap_str; } From 773818384138a00152619a99aed02bc8f0f1b28b Mon Sep 17 00:00:00 2001 From: ipa-nhg Date: Wed, 9 Jun 2021 17:14:57 +0200 Subject: [PATCH 10/11] update the resources of the ROS1 system tests generators --- .../resources/test.rossystem | 24 +++++++++---------- .../resources/test_system.componentinterface | 4 ---- .../test_system/launch/test_system.launch | 8 ++++--- .../tests/RosSystemGeneratorTest.xtend | 10 +++++++- .../tests/RosSystemParsingTest.xtend | 2 +- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/resources/test.rossystem b/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/resources/test.rossystem index 411adf789..cee8e4eb9 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/resources/test.rossystem +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/resources/test.rossystem @@ -15,17 +15,17 @@ RosSystem { Name 'test_system' RosComponents ( } } , ComponentInterface { name test_node2 NameSpace test2 FromRosNode "test_pkg.test_node.test_node" - RosPublishers { RosPublisher "test2/scan" { ns test2 RefPublisher "test_pkg.test_node.test_node.scan" } } - RosSubscribers { RosSubscriber "test2/power_state" { ns test2 RefSubscriber "test_pkg.test_node.test_node.power_state" } } - RosSrvServers { RosServiceServer "test2/setBool" { ns test2 RefServer "test_pkg.test_node.test_node.setBool" } } - RosSrvClients { RosServiceClient "test2/init" { ns test2 RefClient "test_pkg.test_node.test_node.init" } } - RosParameters { RosParameter "test2/string_test" { ns test2 RefParameter "test_pkg.test_node.test_node.string_test" } , - RosParameter "test2/bool_tets" { ns test2 RefParameter "test_pkg.test_node.test_node.bool_tets" } , - RosParameter "test2/array_tets" { ns test2 RefParameter "test_pkg.test_node.test_node.array_tets" } , - RosParameter "test2/base64_test" { ns test2 RefParameter "test_pkg.test_node.test_node.base64_test" } , - RosParameter "test2/double_test" { ns test2 RefParameter "test_pkg.test_node.test_node.double_test" } , - RosParameter "test2/int_test" { ns test2 RefParameter "test_pkg.test_node.test_node.int_test" } , - RosParameter "test2/list_test" { ns test2 RefParameter "test_pkg.test_node.test_node.list_test" } + RosPublishers { RosPublisher "scan" { RefPublisher "test_pkg.test_node.test_node.scan" } } + RosSubscribers { RosSubscriber "power_state" { RefSubscriber "test_pkg.test_node.test_node.power_state" } } + RosSrvServers { RosServiceServer "setBool" { RefServer "test_pkg.test_node.test_node.setBool" } } + RosSrvClients { RosServiceClient "init" { RefClient "test_pkg.test_node.test_node.init" } } + RosParameters { RosParameter "string_test" { RefParameter "test_pkg.test_node.test_node.string_test" } , + RosParameter "bool_tets" { RefParameter "test_pkg.test_node.test_node.bool_tets" } , + RosParameter "array_tets" { RefParameter "test_pkg.test_node.test_node.array_tets" } , + RosParameter "base64_test" { RefParameter "test_pkg.test_node.test_node.base64_test" } , + RosParameter "double_test" { RefParameter "test_pkg.test_node.test_node.double_test" } , + RosParameter "int_test" { RefParameter "test_pkg.test_node.test_node.int_test" } , + RosParameter "list_test" { RefParameter "test_pkg.test_node.test_node.list_test" } } } , ComponentInterface { name test_nodea RosPublishers { RosPublisher power_state { RefPublisher "test_pkg.test_node.test_node.power_state" } } @@ -33,7 +33,7 @@ RosSystem { Name 'test_system' RosComponents ( RosSrvServers { RosServiceServer init { RefServer "test_pkg.test_node.test_node.init" } } RosSrvClients { RosServiceClient SetBool { RefClient "test_pkg.test_node.test_node.SetBool" } } } ) TopicConnections { - TopicConnection scan { From ( "test_node.scan" ) To ( "test_nodea.scan" ) } , + TopicConnection scan_rename { From ( "test_node.scan" ) To ( "test_nodea.scan" ) } , TopicConnection power_state { From ( "test_nodea.power_state" ) To ( "test_node.power_state" ) } } ServiceConnections { ServiceConnection init { From ( "test_nodea.init" ) To "test_node.init" } } Parameters { diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/resources/test_system.componentinterface b/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/resources/test_system.componentinterface index 80d7eba73..06984a638 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/resources/test_system.componentinterface +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/resources/test_system.componentinterface @@ -1,22 +1,18 @@ ComponentInterface { name test_system RosPublishers{ RosPublisher "scan" { RefPublisher "test_pkg.test_node.test_node.scan"}, - RosPublisher "test2/scan" { RefPublisher "test_pkg.test_node.test_node.scan"}, RosPublisher "power_state" { RefPublisher "test_pkg.test_node.test_node.power_state"} } RosSubscribers{ RosSubscriber "power_state" { RefSubscriber "test_pkg.test_node.test_node.power_state"}, - RosSubscriber "test2/power_state" { RefSubscriber "test_pkg.test_node.test_node.power_state"}, RosSubscriber "scan" { RefSubscriber "test_pkg.test_node.test_node.scan"} } RosSrvServers{ RosServiceServer "setBool" { RefServer "test_pkg.test_node.test_node.setBool"}, - RosServiceServer "test2/setBool" { RefServer "test_pkg.test_node.test_node.setBool"}, RosServiceServer "init" { RefServer "test_pkg.test_node.test_node.init"} } RosSrvClients{ RosServiceClient "init" { RefClient "test_pkg.test_node.test_node.init"}, - RosServiceClient "test2/init" { RefClient "test_pkg.test_node.test_node.init"}, RosServiceClient "SetBool" { RefClient "test_pkg.test_node.test_node.SetBool"} } RosParameters{ diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/resources/test_system/launch/test_system.launch b/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/resources/test_system/launch/test_system.launch index 06a0873ff..03e62025f 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/resources/test_system/launch/test_system.launch +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/resources/test_system/launch/test_system.launch @@ -4,15 +4,17 @@ [1,2,a] [1,3] -first_element:8 -third_element:dsd +first_element: 8 +third_element: dsd - + + + diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/src/de/fraunhofer/ipa/rossystem/tests/RosSystemGeneratorTest.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/src/de/fraunhofer/ipa/rossystem/tests/RosSystemGeneratorTest.xtend index 1ce4b7d63..9fbe509b3 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/src/de/fraunhofer/ipa/rossystem/tests/RosSystemGeneratorTest.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/src/de/fraunhofer/ipa/rossystem/tests/RosSystemGeneratorTest.xtend @@ -102,7 +102,15 @@ class RosSystemGeneratorTest { // Test the generated launch file Assert.assertEquals(new String(Files.readAllBytes(Paths.get(RESOURCES_BASE_DIR+'/test_system/launch/', 'test_system.launch'))).trim, - fsa.textFiles.get(CustomOutputProvider::DEFAULT_OUTPUT+'test_system/launch/test_system.launch').toString.trim) + fsa.textFiles.get(CustomOutputProvider::DEFAULT_OUTPUT+'test_system/launch/test_system.launch').toString.trim) + + // Test the generated package.xml file + Assert.assertEquals(new String(Files.readAllBytes(Paths.get(RESOURCES_BASE_DIR+'/test_system/', 'package.xml'))).trim, + fsa.textFiles.get(CustomOutputProvider::DEFAULT_OUTPUT+'test_system/package.xml').toString.trim) + + // Test the generated CMakeLists.txt file + Assert.assertEquals(new String(Files.readAllBytes(Paths.get(RESOURCES_BASE_DIR+'/test_system/', 'CMakeLists.txt'))).trim, + fsa.textFiles.get(CustomOutputProvider::DEFAULT_OUTPUT+'test_system/CMakeLists.txt').toString.trim) // Test the generated component interface Assert.assertEquals(new String(Files.readAllBytes(Paths.get(RESOURCES_BASE_DIR+'/test_system.componentinterface'))).trim, diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/src/de/fraunhofer/ipa/rossystem/tests/RosSystemParsingTest.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/src/de/fraunhofer/ipa/rossystem/tests/RosSystemParsingTest.xtend index 52665ac20..1f1f3e83b 100644 --- a/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/src/de/fraunhofer/ipa/rossystem/tests/RosSystemParsingTest.xtend +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext.tests/src/de/fraunhofer/ipa/rossystem/tests/RosSystemParsingTest.xtend @@ -42,7 +42,7 @@ class RosSystemParsingTest { Assert.assertEquals("test_node", ComponentName) val TopicConnectionName = model.topicConnections.get(0).topicName - Assert.assertEquals("scan", TopicConnectionName) + Assert.assertEquals("scan_rename", TopicConnectionName) val FromTopic = model.topicConnections.get(0).from.get(0).name val Publisher = model.rosComponent.get(0).rospublisher.get(0).name From 36b7ffa71ebe5dba1359c2e3d925e3df87327c1c Mon Sep 17 00:00:00 2001 From: ipa-nhg Date: Wed, 9 Jun 2021 17:43:27 +0200 Subject: [PATCH 11/11] use syntax from an old version of java to with maven and the CI setup --- .../generator/LaunchFileCompiler_ROS2.xtend | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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 1eb1b9667..23dd521a0 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 @@ -126,7 +126,11 @@ def generate_launch_description(): } else { param_str += "{ \"" + rosParameter.parameter.name + "\" : " + get_param_value(rosParameter.value, rosParameter.parameter.name); } - param_str += (param_count > 1) ? " },\n" : " }\n"; + if (param_count > 1){ + param_str +=" },\n" + } else { + param_str +=" }\n"; + } } return param_str; } @@ -139,7 +143,9 @@ def generate_launch_description(): var member = ((elem as ParameterStructImpl).eContents.get(0) as ParameterStructMemberImpl); param_str += "{ \"" + name + "/" + member.getName() + "\" : " + get_param_value(member.getValue(), member.getName()); elem_count--; - param_str += (elem_count > 0) ? " },\n" : ""; + if (elem_count > 0){ + param_str +=" },\n" + } } return param_str; @@ -161,8 +167,10 @@ def generate_launch_description(): for (elem : (value as ParameterSequenceImpl).eContents) { param_val += get_param_value(elem as ParameterValue, name); elem_count--; - param_val += (elem_count > 0) ? ", " : ""; - } + if (elem_count > 0){ + param_val +=", " + } + } param_val += "]"; } return param_val;