Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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»,
Expand All @@ -88,14 +88,20 @@ 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»

return ld
'''



// def void compile_list_of_ROS2components(RosSystem system, ComponentStack stack) {
// components_tmp_.clear;
// Ros2components.clear;
Expand Down Expand Up @@ -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")){
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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»

Expand All @@ -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:

```
Expand Down Expand Up @@ -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:
Expand All @@ -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){
Expand All @@ -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+"]"
Expand All @@ -144,5 +147,3 @@ ros2 launch «system.fromFile.split("/",2).get(0)» «system.fromFile.substring(
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -89,4 +98,3 @@ class RosSystemGenerator extends AbstractGenerator {
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -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»

'''

}