Skip to content

Commit

Permalink
Generate the launch file for the bridges separately
Browse files Browse the repository at this point in the history
  • Loading branch information
ipa-nhg committed May 15, 2024
1 parent 92f25d7 commit 7f82fbf
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -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
'''
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"," ")
)
}
}
}
Expand Down

0 comments on commit 7f82fbf

Please sign in to comment.