From 78127ca861f9e5bbe1ecd69bf14f0baa23cd9c9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Thu, 18 Apr 2024 22:03:07 +0200 Subject: [PATCH 1/2] Launch file for running gzserver (#532) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Launch file for the bridge Signed-off-by: Carlos Agüero --- ros_gz_sim/CMakeLists.txt | 1 + ros_gz_sim/launch/gz_server.launch.py | 91 +++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 ros_gz_sim/launch/gz_server.launch.py diff --git a/ros_gz_sim/CMakeLists.txt b/ros_gz_sim/CMakeLists.txt index b54269ce..dbc811fe 100644 --- a/ros_gz_sim/CMakeLists.txt +++ b/ros_gz_sim/CMakeLists.txt @@ -120,6 +120,7 @@ install(FILES ) install(FILES + "launch/gz_server.launch.py" "launch/ros_gz_sim.launch.py" DESTINATION share/${PROJECT_NAME}/launch ) diff --git a/ros_gz_sim/launch/gz_server.launch.py b/ros_gz_sim/launch/gz_server.launch.py new file mode 100644 index 00000000..f13bb471 --- /dev/null +++ b/ros_gz_sim/launch/gz_server.launch.py @@ -0,0 +1,91 @@ +# Copyright 2024 Open Source Robotics Foundation, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Launch gzserver in a component container.""" + +from launch import LaunchDescription +from launch.actions import DeclareLaunchArgument, GroupAction +from launch.conditions import IfCondition +from launch.substitutions import LaunchConfiguration, PythonExpression, TextSubstitution +from launch_ros.actions import ComposableNodeContainer, Node +from launch_ros.descriptions import ComposableNode + + +def generate_launch_description(): + + world_sdf_file = LaunchConfiguration('world_sdf_file') + world_sdf_string = LaunchConfiguration('world_sdf_string') + container_name = LaunchConfiguration('container_name') + use_composition = LaunchConfiguration('use_composition') + + declare_world_sdf_file_cmd = DeclareLaunchArgument( + 'world_sdf_file', default_value=TextSubstitution(text=''), + description='Path to the SDF world file') + declare_world_sdf_string_cmd = DeclareLaunchArgument( + 'world_sdf_string', default_value=TextSubstitution(text=''), + description='SDF world string') + declare_container_name_cmd = DeclareLaunchArgument( + 'container_name', + default_value='ros_gz_container', + description='Name of container that nodes will load in if use composition', + ) + declare_use_composition_cmd = DeclareLaunchArgument( + 'use_composition', default_value='False', description='Use composed bringup if True' + ) + + load_nodes = GroupAction( + condition=IfCondition(PythonExpression(['not ', use_composition])), + actions=[ + Node( + package='ros_gz_sim', + executable='gzserver', + output='screen', + parameters=[{'world_sdf_file': world_sdf_file, + 'world_sdf_string': world_sdf_string}], + ), + ], + ) + + load_composable_nodes = ComposableNodeContainer( + condition=IfCondition(use_composition), + name=container_name, + namespace='', + package='rclcpp_components', + executable='component_container', + composable_node_descriptions=[ + ComposableNode( + package='ros_gz_sim', + plugin='ros_gz_sim::GzServer', + name='gzserver', + parameters=[{'world_sdf_file': world_sdf_file, + 'world_sdf_string': world_sdf_string}], + extra_arguments=[{'use_intra_process_comms': True}], + ), + ], + output='screen', + ) + + # Create the launch description and populate + ld = LaunchDescription() + + # Declare the launch options + ld.add_action(declare_world_sdf_file_cmd) + ld.add_action(declare_world_sdf_string_cmd) + ld.add_action(declare_container_name_cmd) + ld.add_action(declare_use_composition_cmd) + # Add the actions to launch all of the gzserver nodes + ld.add_action(load_nodes) + ld.add_action(load_composable_nodes) + + return ld From 3860b747a18ba68153b4c26ad8a46b0be3dfbd3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Thu, 18 Apr 2024 22:04:51 +0200 Subject: [PATCH 2/2] Update ros_gz_sim/launch/ros_gz_sim.launch.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alejandro Hernández Cordero Signed-off-by: Carlos Agüero --- ros_gz_sim/launch/ros_gz_sim.launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ros_gz_sim/launch/ros_gz_sim.launch.py b/ros_gz_sim/launch/ros_gz_sim.launch.py index 0ae186bf..edc4b8ea 100644 --- a/ros_gz_sim/launch/ros_gz_sim.launch.py +++ b/ros_gz_sim/launch/ros_gz_sim.launch.py @@ -82,7 +82,7 @@ def generate_launch_description(): ('namespace', namespace), ('use_composition', use_composition), ('use_respawn', use_respawn), - ('log_level', log_level), ]) + ('log_level', log_level)]) gzserver_description = IncludeLaunchDescription( PythonLaunchDescriptionSource(