Skip to content

Commit

Permalink
Add the parameters to the README code generator for ROS2 systems
Browse files Browse the repository at this point in the history
  • Loading branch information
ipa-nhg committed Feb 29, 2024
1 parent c8760bd commit b2cbe8d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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»'''

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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»

Expand Down Expand Up @@ -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+"]"
}
}

}


0 comments on commit b2cbe8d

Please sign in to comment.