diff --git a/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/BridgesLaunchFileCompiler_ROS2.xtend b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/BridgesLaunchFileCompiler_ROS2.xtend new file mode 100644 index 00000000..95238df5 --- /dev/null +++ b/plugins/de.fraunhofer.ipa.rossystem.xtext/src/de/fraunhofer/ipa/rossystem/generator/BridgesLaunchFileCompiler_ROS2.xtend @@ -0,0 +1,83 @@ +package de.fraunhofer.ipa.rossystem.generator + +import system.System +import com.google.inject.Inject + +class BridgesLaunchFileCompiler_ROS2 { + + @Inject extension GeneratorHelpers + + + def compile_toROS2launchbridges(System system) ''' +import os +from launch import LaunchDescription +from launch_ros.actions import Node +from launch.actions import IncludeLaunchDescription, DeclareLaunchArgument +from launch.launch_description_sources import PythonLaunchDescriptionSource +from launch.substitutions import LaunchConfiguration, PythonExpression, PathJoinSubstitution, TextSubstitution + +def generate_launch_description(): + ld = LaunchDescription() + + # *** ROS 1 to ROS 2 bridges *** + «IF TopicBridgeGenerated(system) || ServiceFromBridgeGenerated(system)|| ServiceToBridgeGenerated(system) » + «system.name»_ros1_bridge_config = os.path.join( + get_package_share_directory('«system.getName().toLowerCase»'), + 'config', + 'ros1_bridges.yaml' + )«ENDIF»«IF TopicBridgeGenerated(system)» + ros1_topic_bridge_parameter_bridge = Node( + package='ros1_bridge', + executable='parameter_bridge', + name='ros1_topic_bridge_parameter_bridge', + namespace='bridge_«system.name»_topics', + output='screen', + parameters=[ + {'__ns': 'bridge_«system.name»_topics'}, + {'__name': 'bridge_«system.name»_topics'} + ], + arguments=[ + '--ros-args', '-r', '__name:=bridge_«system.name»_topics' + ] + )«ENDIF»«IF ServiceFromBridgeGenerated(system)» + ros1_service_from_bridge_parameter_bridge = Node( + package='ros1_bridge', + executable='parameter_bridge', + name='ros1_service_from_bridge_parameter_bridge', + namespace='bridge_«system.name»_from_services', + output='screen', + parameters=[ + {'__ns': 'bridge_«system.name»_from_services'}, + {'__name': 'bridge_«system.name»_from_services'} + ], + arguments=[ + '--ros-args', '-r', '__name:=bridge_«system.name»_from_services' + ] + )«ENDIF»«IF ServiceToBridgeGenerated(system)» + ros1_service_to_bridge_parameter_bridge = Node( + package='ros1_bridge', + executable='parameter_bridge', + name='ros1_service_to_bridge_parameter_bridge', + namespace='bridge_«system.name»_to_services', + output='screen', + parameters=[ + {'__ns': 'bridge_«system.name»_to_services'}, + {'__name': 'bridge_«system.name»_to_services'} + ], + arguments=[ + '--ros-args', '-r', '__name:=bridge_«system.name»_to_services' + ] + )«ENDIF» + + # *** Add actions *** + «IF TopicBridgeGenerated(system)» + ld.add_action(ros1_topic_bridge_parameter_bridge) + «ENDIF»«IF ServiceFromBridgeGenerated(system)» + ld.add_action(ros1_service_from_bridge_parameter_bridge) + «ENDIF»«IF ServiceToBridgeGenerated(system)» + ld.add_action(ros1_service_to_bridge_parameter_bridge) + «ENDIF» + + return ld + ''' +} 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 17b74f2f..43fff5b0 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 @@ -69,9 +69,9 @@ class GeneratorHelpers { os_import=true } } - if (TopicBridgeGenerated(rossystem) || ServiceFromBridgeGenerated(rossystem) || ServiceToBridgeGenerated(rossystem)){ - os_import=true - } +// if (TopicBridgeGenerated(rossystem) || ServiceFromBridgeGenerated(rossystem) || ServiceToBridgeGenerated(rossystem)){ +// os_import=true +// } return os_import } 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 3f952976..74d4c6cd 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 @@ -83,70 +83,14 @@ def generate_launch_description(): include_«subsystem.name»= IncludeLaunchDescription( PythonLaunchDescriptionSource([get_package_share_directory('«subsystem.fromFile.split("/",2).get(0)»') + '/«subsystem.fromFile.split("/",2).get(1)»']) ) - «ENDIF» - - # *** ROS 1 to ROS 2 bridges *** - «ENDFOR»«IF TopicBridgeGenerated(system) || ServiceFromBridgeGenerated(system)|| ServiceToBridgeGenerated(system) » - «system.name»_ros1_bridge_config = os.path.join( - get_package_share_directory('«system.getName().toLowerCase»'), - 'config', - 'ros1_bridges.yaml' - )«ENDIF»«IF TopicBridgeGenerated(system)» - ros1_topic_bridge_parameter_bridge = Node( - package='ros1_bridge', - executable='parameter_bridge', - name='ros1_topic_bridge_parameter_bridge', - namespace='bridge_«system.name»_topics', - output='screen', - parameters=[ - {'__ns': 'bridge_«system.name»_topics'}, - {'__name': 'bridge_«system.name»_topics'} - ], - arguments=[ - '--ros-args', '-r', '__name:=bridge_«system.name»_topics' - ] - )«ENDIF»«IF ServiceFromBridgeGenerated(system)» - ros1_service_from_bridge_parameter_bridge = Node( - package='ros1_bridge', - executable='parameter_bridge', - name='ros1_service_from_bridge_parameter_bridge', - namespace='bridge_«system.name»_from_services', - output='screen', - parameters=[ - {'__ns': 'bridge_«system.name»_from_services'}, - {'__name': 'bridge_«system.name»_from_services'} - ], - arguments=[ - '--ros-args', '-r', '__name:=bridge_«system.name»_from_services' - ] - )«ENDIF»«IF ServiceToBridgeGenerated(system)» - ros1_service_to_bridge_parameter_bridge = Node( - package='ros1_bridge', - executable='parameter_bridge', - name='ros1_service_to_bridge_parameter_bridge', - namespace='bridge_«system.name»_to_services', - output='screen', - parameters=[ - {'__ns': 'bridge_«system.name»_to_services'}, - {'__name': 'bridge_«system.name»_to_services'} - ], - arguments=[ - '--ros-args', '-r', '__name:=bridge_«system.name»_to_services' - ] - )«ENDIF» + «ENDIF»«ENDFOR» # *** Add actions *** «FOR component:getRos2Nodes(system)» ld.add_action(«(component as RosNode).name») «ENDFOR»«FOR subsystem:getSubsystems(system)» ld.add_action(include_«subsystem.name») - «ENDFOR»«IF TopicBridgeGenerated(system)» - ld.add_action(ros1_topic_bridge_parameter_bridge) - «ENDIF»«IF ServiceFromBridgeGenerated(system)» - ld.add_action(ros1_service_from_bridge_parameter_bridge) - «ENDIF»«IF ServiceToBridgeGenerated(system)» - ld.add_action(ros1_service_to_bridge_parameter_bridge) - «ENDIF» + «ENDFOR» return ld ''' 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 c83b1e46..2e016c7b 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 @@ -26,6 +26,7 @@ class RosSystemGenerator extends AbstractGenerator { @Inject extension PlantUMLCompiler @Inject extension GeneratorHelpers @Inject extension Ros1BridgesYamlFileCompiler + @Inject extension BridgesLaunchFileCompiler_ROS2 override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { var yaml_gen = false @@ -79,6 +80,10 @@ class RosSystemGenerator extends AbstractGenerator { system.getName().toLowerCase+"/config/"+"ros1_bridges.yaml", compile_ROS1bridges_config(system) ) + fsa.generateFile( + system.getName().toLowerCase+"/launch/"+system.getName()+"_bridges.launch.py", + compile_toROS2launchbridges(system).toString().replace("\t"," ") + ) } } }