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 2e7a90d1..7cf7b243 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 @@ -22,6 +22,14 @@ import system.RosNode import ros.impl.AmentPackageImpl import system.impl.RosNodeImpl import system.SubSystem +import ros.ParameterValue +import ros.impl.ParameterSequenceImpl +import ros.impl.ParameterStructMemberImpl +import ros.impl.ParameterStructImpl +import ros.impl.ParameterStringImpl +import ros.impl.ParameterIntegerImpl +import ros.impl.ParameterDoubleImpl +import ros.impl.ParameterBooleanImpl class GeneratorHelpers { @@ -110,6 +118,55 @@ class GeneratorHelpers { return PkgsList; } + 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); + val param_val = get_param_value(member.getValue(), name + "/" + member.getName()); + if (param_val.startsWith("{")) { + param_str += param_val; + } else { + param_str += "{ \"" + name + "/" + member.getName() + "\" : " + param_val; + } + elem_count--; + if (elem_count > 0){ + param_str +=" },\n" + } + } + return param_str; + } + + def String get_param_value(ParameterValue value, String name) { + 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) { + var elem_count = (value as ParameterSequenceImpl).eContents.length; + if ((value as ParameterSequenceImpl).eContents.get(0) instanceof ParameterStructImpl) { + param_val = compile_struct_str(value, name); + } else { + param_val += "["; + for (elem : (value as ParameterSequenceImpl).eContents) { + param_val += get_param_value(elem as ParameterValue, name); + elem_count--; + if (elem_count > 0){ + param_val +=", " + } + } + param_val += "]"; + } + } + return param_val; + } + def compile_pkg(RosNode component) '''«IF !(component.from===null)»«component.from.getPackage_node.name»«ENDIF»''' 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 71d90d46..150e8dc6 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 @@ -268,52 +268,5 @@ def generate_launch_description(): // 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); - val param_val = get_param_value(member.getValue(), name + "/" + member.getName()); - if (param_val.startsWith("{")) { - param_str += param_val; - } else { - param_str += "{ \"" + name + "/" + member.getName() + "\" : " + param_val; - } - elem_count--; - if (elem_count > 0){ - param_str +=" },\n" - } - } - return param_str; - } - - def String get_param_value(ParameterValue value, String name) { - 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) { - var elem_count = (value as ParameterSequenceImpl).eContents.length; - if ((value as ParameterSequenceImpl).eContents.get(0) instanceof ParameterStructImpl) { - param_val = compile_struct_str(value, name); - } else { - param_val += "["; - for (elem : (value as ParameterSequenceImpl).eContents) { - param_val += get_param_value(elem as ParameterValue, name); - elem_count--; - if (elem_count > 0){ - param_val +=", " - } - } - param_val += "]"; - } - } - return param_val; - } } 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 a379e2e0..62dc6cd0 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 @@ -85,7 +85,7 @@ source install/setup.bash To execute the launch file, the following command can be called: ``` -ros2 launch «system.name» «system.name».launch.py +ros2 launch «system.name» «system.name».launch.py «FOR param:system.parameter»«param.name»:=«get_param_value(param.value,param.name)» «ENDFOR» ``` The generated launch files requires the xterm package, it can be installed by: @@ -98,7 +98,7 @@ 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)» +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» ``` «ENDIF» @@ -142,6 +142,7 @@ ros2 launch «system.fromFile.split("/",2).get(0)» «system.fromFile.substring( return "- ActionClient: "+ port.name+" ["+(port.reference as RosActionClientReferenceImpl).basicGetFrom.action.fullname+"]" } } + }