Skip to content

Commit

Permalink
Fix RosSystem launch file generator issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ipa-nhg committed May 13, 2024
1 parent 96cd2a4 commit 2810a35
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,36 @@ class GeneratorHelpers {
String Pkg
RosNode node
String[] FromFileInfo
Boolean os_import


def void init_pkg(){
PackageSet=false
}

def boolean YamlFileGenerated(System rossystem) {
os_import=false
for (component: getRos2Nodes(rossystem)){
for(param:component.rosparameters){
if(param.eContents.get(0).eClass.name.contains("ParameterStruct")){
os_import=true
}
}
if(component.rosparameters.length>5){
os_import=true
}
}
return os_import
}

def <Components> getNodes (System rossystem) {
def <Components> getRos2Nodes (System rossystem) {
val nodeList = new ArrayList<RosNode>
if (!rossystem.components.nullOrEmpty){
for (component: rossystem.components) {
if (component.class.toString.contains("RosNode")){
nodeList.add(component as RosNode)
if((component as RosNode).from.eContainer.eContainer.class.toString.contains("Ament")){
nodeList.add(component as RosNode)
}
}
}}
return nodeList
Expand All @@ -57,7 +75,7 @@ class GeneratorHelpers {

def ArrayList<String> getAllRepos(System system) {
RepoList = new ArrayList<String>()
for (node : getNodes(system)){
for (node : getRos2Nodes(system)){
if (!((node.from.eContainer.eContainer as Package).fromGitRepo.nullOrEmpty)) {
val repo=(node.from.eContainer.eContainer as Package).fromGitRepo
if (repo.contains(":")){
Expand All @@ -80,7 +98,7 @@ class GeneratorHelpers {
def <String> getPkgsDependencies (System rossystem){
PkgsList = new ArrayList()
if (rossystem.fromFile.isNullOrEmpty) {
for (component: getNodes(rossystem)){
for (component: getRos2Nodes(rossystem)){
init_pkg()
node = component as RosNode
Pkg = node.compile_pkg.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class LaunchFileCompiler_ROS2 {


def compile_toROS2launch(System system) '''
«IF YamlFileGenerated(system)»import os«ENDIF»
from launch import LaunchDescription
from launch_ros.actions import Node
«IF !getSubsystems(system).empty»from ament_index_python.packages import get_package_share_directory«ENDIF»
Expand All @@ -40,7 +41,7 @@ from launch.substitutions import LaunchConfiguration, PythonExpression, PathJoin
def generate_launch_description():
ld = LaunchDescription()

«FOR component:getNodes(system)»«IF generate_yaml(component
«FOR component:getRos2Nodes(system)»«IF generate_yaml(component
«component.name»_config = os.path.join(
get_package_share_directory('«system.getName().toLowerCase»'),
'config',
Expand All @@ -56,18 +57,17 @@ def generate_launch_description():
«ENDIF»
«ENDFOR»

«FOR component:getNodes(system
«FOR component:getRos2Nodes(system
«(component as RosNode).name» = Node(
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»parameters=[{«FOR param:component.rosparameters»
"«param.from.name»": LaunchConfiguration("«param.name»"),«ENDFOR»}]«ENDIF»«ENDIF»
«IF generate_yaml(component)» parameters = [«component.name»_config]
«ELSE» parameters=[{«FOR param:component.rosparameters»
"«param.from.name»": LaunchConfiguration("«param.name»"),«ENDFOR»}]«ENDIF»«ENDIF»
)
«ENDFOR»
«FOR subsystem:getSubsystems(system)»
Expand All @@ -82,7 +82,7 @@ def generate_launch_description():
«ENDIF»
«ENDFOR»

«FOR component:getNodes(system)»
«FOR component:getRos2Nodes(system)»
ld.add_action(«(component as RosNode).name»)
«ENDFOR»«FOR subsystem:getSubsystems(system)»
ld.add_action(include_«subsystem.name»)
Expand Down Expand Up @@ -156,7 +156,15 @@ def generate_launch_description():
var to_action = new Object
var rename = ""
for (interface : node.rosinterfaces){
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 (connection : connections){
var rosconnection = connection as RosSystemConnectionImpl
if (rosconnection.from.reference.eClass.toString.contains("RosPublisherReference")){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class PlantUMLCompiler{
/'SUBSYSTEMS'/
«FOR subsystem:system.subsystems»
component «subsystem.name» {
«FOR component:getNodes(subsystem)»
«FOR component:getRos2Nodes(subsystem)»
«compile_ports(component)»
«ENDFOR» }
«ENDFOR»

«FOR component:getNodes(system)»
«FOR component:getRos2Nodes(system)»
«compile_ports(component)»
«ENDFOR»
«FOR connection:system.connections» «get_connection_port((connection as RosSystemConnectionImpl).from)» --> «get_connection_port((connection as RosSystemConnectionImpl).to)»
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ This package has be created automatically using the [RosTooling](https://github.


It holds the launch file to run the following nodes:
«FOR node:getNodes(system
«FOR node:getRos2Nodes(system
- «(node as RosNode).name»
«ENDFOR»
«FOR subsystem:system.subsystems»
«FOR node:getNodes(subsystem
«FOR node:getRos2Nodes(subsystem
- «(node as RosNode).name»
«ENDFOR»
«ENDFOR»

«IF(!IsInterfacesEmpty(system))»The listed nodes offer the following connections:
«FOR node:getNodes(system)»«FOR port:(node as RosNode).rosinterfaces»
«FOR node:getRos2Nodes(system)»«FOR port:(node as RosNode).rosinterfaces»
«getPortInfo(port
«ENDFOR»«ENDFOR»«FOR subsystem:system.subsystems»«FOR node:getNodes(subsystem)»«FOR port:(node as RosNode).rosinterfaces»
«ENDFOR»«ENDFOR»«FOR subsystem:system.subsystems»«FOR node:getRos2Nodes(subsystem)»«FOR port:(node as RosNode).rosinterfaces»
«getPortInfo(port
«ENDFOR»«ENDFOR»«ENDFOR»«ENDIF»

Expand Down Expand Up @@ -106,13 +106,13 @@ ros2 launch «system.fromFile.split("/",2).get(0)» «system.fromFile.substring(
'''

def IsInterfacesEmpty(System system){
for(node: getNodes(system)){
for(node: getRos2Nodes(system)){
if (!(node as RosNode).rosinterfaces.empty){
return false
}
}
for (subsystem: system.subsystems){
for(node: getNodes(subsystem)){
for(node: getRos2Nodes(subsystem)){
if (!(node as RosNode).rosinterfaces.empty){
return false
}
Expand Down

0 comments on commit 2810a35

Please sign in to comment.