From be17cb8912a3548dfa2dce358c5fabed25b82800 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Tue, 11 Oct 2022 09:09:45 -0500 Subject: [PATCH 1/3] Fix launch substitutions for ign_args Signed-off-by: Michael Carroll --- ros_gz_sim/launch/gz_sim.launch.py.in | 87 +++++++-------- ros_ign_gazebo/CMakeLists.txt | 12 +-- ros_ign_gazebo/launch/ign_gazebo.launch.py | 33 ++++++ ros_ign_gazebo/launch/ign_gazebo.launch.py.in | 100 ------------------ 4 files changed, 75 insertions(+), 157 deletions(-) create mode 100644 ros_ign_gazebo/launch/ign_gazebo.launch.py delete mode 100644 ros_ign_gazebo/launch/ign_gazebo.launch.py.in diff --git a/ros_gz_sim/launch/gz_sim.launch.py.in b/ros_gz_sim/launch/gz_sim.launch.py.in index 19569c29..36bafb97 100644 --- a/ros_gz_sim/launch/gz_sim.launch.py.in +++ b/ros_gz_sim/launch/gz_sim.launch.py.in @@ -17,13 +17,11 @@ from os import environ from launch import LaunchDescription -from launch.actions import DeclareLaunchArgument +from launch.actions import DeclareLaunchArgument, OpaqueFunction from launch.actions import ExecuteProcess -from launch.substitutions import LaunchConfiguration, AndSubstitution, PythonExpression -from launch.conditions import LaunchConfigurationEquals, LaunchConfigurationNotEquals, IfCondition +from launch.substitutions import LaunchConfiguration - -def generate_launch_description(): +def launch_gz(context, *args, **kwargs): env = {'GZ_SIM_SYSTEM_PLUGIN_PATH': ':'.join([environ.get('GZ_SIM_SYSTEM_PLUGIN_PATH', default=''), environ.get('LD_LIBRARY_PATH', default='')]), @@ -31,14 +29,48 @@ def generate_launch_description(): ':'.join([environ.get('IGN_GAZEBO_SYSTEM_PLUGIN_PATH', default=''), environ.get('LD_LIBRARY_PATH', default='')])} + gz_args = LaunchConfiguration('gz_args').perform(context) + gz_version = LaunchConfiguration('gz_version').perform(context) + ign_args = LaunchConfiguration('ign_args').perform(context) + ign_version = LaunchConfiguration('ign_version').perform(context) + debugger = LaunchConfiguration('debugger').perform(context) + + if not len(gz_args) and len(ign_args): + print("ign_args is deprecated, migrate to gz_args!") + exec_args = ign_args + else: + exec_args = gz_args + + if len(ign_version) or (ign_version == '' and int(gz_version) < 7): + exec = 'ruby $(which ign) gazebo' + + if len(ign_version): + gz_version = ign_version + else: + exec = 'ruby $(which gz) sim' + + if debugger != 'false': + debug_prefix = 'x-terminal-emulator -e gdb -ex run --args' + else: + debug_prefix = None + + + return [ExecuteProcess( + cmd=[exec, exec_args, '--force-version', gz_version], + output='screen', + additional_env=env, + shell=True, + prefix=debug_prefix + )] + +def generate_launch_description(): return LaunchDescription([ DeclareLaunchArgument('gz_args', default_value='', - description='Arguments to be passed to Gazebo Sim'), + description='Arguments to be passed to Gazebo Sim'), # Gazebo Sim's major version DeclareLaunchArgument('gz_version', default_value='@GZ_SIM_VER@', - description='Gazebo Sim\'s major version'), - + description='Gazebo Sim\'s major version'), # TODO(CH3): Deprecated. Remove on tock. DeclareLaunchArgument( 'ign_args', default_value='', @@ -52,42 +84,5 @@ def generate_launch_description(): DeclareLaunchArgument( 'debugger', default_value='false', description='Run in Debugger'), - - ExecuteProcess( - condition=IfCondition( - AndSubstitution( - PythonExpression(["'", LaunchConfiguration('ign_version'), "' == ''"]), - PythonExpression(["'", LaunchConfiguration('gz_version'), "' < '7'"]) - ) - ), - cmd=['ruby $(which ign) gazebo', - LaunchConfiguration('gz_args'), - '--force-version', - LaunchConfiguration('gz_version'), - ], - output='screen', - additional_env=env, - shell=True, - prefix=PythonExpression([ - "'x-terminal-emulator -e gdb -ex run --args' if '", LaunchConfiguration('debugger'), "'=='true' else ''"]) - ), - - ExecuteProcess( - condition=IfCondition( - AndSubstitution( - PythonExpression(["'", LaunchConfiguration('ign_version'), "' == ''"]), - PythonExpression(["'", LaunchConfiguration('gz_version'), "' >= '7'"]) - ) - ), - cmd=['ruby $(which gz) sim', - LaunchConfiguration('gz_args'), - '--force-version', - LaunchConfiguration('gz_version'), - ], - output='screen', - additional_env=env, - shell=True, - prefix=PythonExpression([ - "'x-terminal-emulator -e gdb -ex run --args' if '", LaunchConfiguration('debugger'), "'=='true' else ''"]) - ), + OpaqueFunction(function = launch_gz), ]) diff --git a/ros_ign_gazebo/CMakeLists.txt b/ros_ign_gazebo/CMakeLists.txt index bac24631..d5c937ee 100644 --- a/ros_ign_gazebo/CMakeLists.txt +++ b/ros_ign_gazebo/CMakeLists.txt @@ -46,18 +46,8 @@ else() message(STATUS "Compiling against Gazebo Fortress") endif() -configure_file( - launch/ign_gazebo.launch.py.in - launch/ign_gazebo.launch.py.configured - @ONLY -) -file(GENERATE - OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/launch/ign_gazebo.launch.py" - INPUT "${CMAKE_CURRENT_BINARY_DIR}/launch/ign_gazebo.launch.py.configured" -) - install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/launch/ign_gazebo.launch.py" + "${CMAKE_CURRENT_SOURCE_DIR}/launch/ign_gazebo.launch.py" DESTINATION share/${PROJECT_NAME}/launch ) diff --git a/ros_ign_gazebo/launch/ign_gazebo.launch.py b/ros_ign_gazebo/launch/ign_gazebo.launch.py new file mode 100644 index 00000000..e8cb5342 --- /dev/null +++ b/ros_ign_gazebo/launch/ign_gazebo.launch.py @@ -0,0 +1,33 @@ +# Copyright 2020 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 Gazebo Sim with command line arguments.""" + +import os + +from ament_index_python.packages import get_package_share_directory + +from launch import LaunchDescription +from launch.actions import IncludeLaunchDescription +from launch.launch_description_sources import PythonLaunchDescriptionSource + +def generate_launch_description(): + ros_gz_sim_dir = get_package_share_directory('ros_gz_sim') + launch_dir = os.path.join(ros_gz_sim_dir, 'launch') + + return LaunchDescription([ + IncludeLaunchDescription( + PythonLaunchDescriptionSource(os.path.join(launch_dir, 'gz_sim.launch.py')) + ) + ]) diff --git a/ros_ign_gazebo/launch/ign_gazebo.launch.py.in b/ros_ign_gazebo/launch/ign_gazebo.launch.py.in deleted file mode 100644 index f8cded2c..00000000 --- a/ros_ign_gazebo/launch/ign_gazebo.launch.py.in +++ /dev/null @@ -1,100 +0,0 @@ -# Copyright 2020 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 Gazebo Sim with command line arguments.""" - -from os import environ - -from launch import LaunchDescription -from launch.actions import DeclareLaunchArgument -from launch.actions import ExecuteProcess -from launch.substitutions import LaunchConfiguration, AndSubstitution, PythonExpression -from launch.conditions import LaunchConfigurationEquals, LaunchConfigurationNotEquals, IfCondition - - -def generate_launch_description(): - env = {'GZ_SIM_SYSTEM_PLUGIN_PATH': - ':'.join([environ.get('GZ_SIM_SYSTEM_PLUGIN_PATH', default=''), - environ.get('LD_LIBRARY_PATH', default='')]), - 'IGN_GAZEBO_SYSTEM_PLUGIN_PATH': # TODO(CH3): To support pre-garden. Deprecated. - ':'.join([environ.get('IGN_GAZEBO_SYSTEM_PLUGIN_PATH', default=''), - environ.get('LD_LIBRARY_PATH', default='')])} - - return LaunchDescription([ - DeclareLaunchArgument('gz_args', default_value='', - description='Arguments to be passed to Gazebo Sim'), - # Gazebo Sim's major version - DeclareLaunchArgument('gz_version', default_value='@GZ_SIM_VER@', - description='Gazebo Sim\'s major version'), - - # TODO(CH3): Deprecated. Remove on tock. - DeclareLaunchArgument( - 'ign_args', default_value='', - description='Deprecated: Arguments to be passed to Gazebo Sim' - ), - # Gazebo Sim's major version - DeclareLaunchArgument( - 'ign_version', default_value='', - description='Deprecated: Gazebo Sim\'s major version' - ), - - # NOTE(CH3): We need ign gazebo to support pre-garden... - # It's deprecated. Remove on tock. - ExecuteProcess( - condition=LaunchConfigurationNotEquals('ign_version', ''), - cmd=['ign gazebo', - LaunchConfiguration('ign_args'), - '--force-version', - LaunchConfiguration('ign_version'), - ], - output='screen', - additional_env=env, - shell=True - ), - - ExecuteProcess( - condition=IfCondition( - AndSubstitution( - PythonExpression(["'", LaunchConfiguration('ign_version'), "' == ''"]), - PythonExpression(["'", LaunchConfiguration('gz_version'), "' < '7'"]) - ) - ), - cmd=['ign gazebo', - LaunchConfiguration('gz_args'), - '--force-version', - LaunchConfiguration('gz_version'), - ], - output='screen', - additional_env=env, - shell=True - ), - - ExecuteProcess( - condition=IfCondition( - AndSubstitution( - PythonExpression(["'", LaunchConfiguration('ign_version'), "' == ''"]), - PythonExpression(["'", LaunchConfiguration('gz_version'), "' >= '7'"]) - ) - ), - cmd=['gz sim', - LaunchConfiguration('gz_args'), - '--force-version', - LaunchConfiguration('gz_version'), - ], - output='screen', - additional_env=env, - shell=True - ), - - ]) From 5327ec9be8b8cdfa78bbb695c654dec19d4c3c52 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Tue, 11 Oct 2022 09:56:58 -0500 Subject: [PATCH 2/3] Address reviewer feedback Signed-off-by: Michael Carroll --- ros_gz_sim/launch/gz_sim.launch.py.in | 6 +++--- ros_gz_sim/package.xml | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ros_gz_sim/launch/gz_sim.launch.py.in b/ros_gz_sim/launch/gz_sim.launch.py.in index 36bafb97..659e238c 100644 --- a/ros_gz_sim/launch/gz_sim.launch.py.in +++ b/ros_gz_sim/launch/gz_sim.launch.py.in @@ -54,7 +54,6 @@ def launch_gz(context, *args, **kwargs): else: debug_prefix = None - return [ExecuteProcess( cmd=[exec, exec_args, '--force-version', gz_version], output='screen', @@ -67,10 +66,11 @@ def launch_gz(context, *args, **kwargs): def generate_launch_description(): return LaunchDescription([ DeclareLaunchArgument('gz_args', default_value='', - description='Arguments to be passed to Gazebo Sim'), + description='Arguments to be passed to Gazebo Sim'), # Gazebo Sim's major version DeclareLaunchArgument('gz_version', default_value='@GZ_SIM_VER@', - description='Gazebo Sim\'s major version'), + description='Gazebo Sim\'s major version'), + # TODO(CH3): Deprecated. Remove on tock. DeclareLaunchArgument( 'ign_args', default_value='', diff --git a/ros_gz_sim/package.xml b/ros_gz_sim/package.xml index eaa43e25..48d7ed13 100644 --- a/ros_gz_sim/package.xml +++ b/ros_gz_sim/package.xml @@ -13,6 +13,7 @@ ament_cmake pkg-config + ament_index_python libgflags-dev rclcpp std_msgs From 8906aec0125085dcc35cd28baf8fe1aa8da01b4f Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Tue, 11 Oct 2022 12:41:14 -0500 Subject: [PATCH 3/3] Remove extra cmake variables Signed-off-by: Michael Carroll --- ros_ign_gazebo/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ros_ign_gazebo/CMakeLists.txt b/ros_ign_gazebo/CMakeLists.txt index d5c937ee..debdbb57 100644 --- a/ros_ign_gazebo/CMakeLists.txt +++ b/ros_ign_gazebo/CMakeLists.txt @@ -31,18 +31,14 @@ endif() # Edifice if("$ENV{GZ_VERSION}" STREQUAL "edifice") find_package(ignition-gazebo5 REQUIRED) - set(GZ_SIM_VER ${ignition-gazebo5_VERSION_MAJOR}) message(STATUS "Compiling against Gazebo Edifice") # Garden elseif("$ENV{GZ_VERSION}" STREQUAL "garden") find_package(gz-sim7 REQUIRED) - set(GZ_SIM_VER ${gz-sim7_VERSION_MAJOR}) - set(GZ_TARGET_PREFIX gz) message(STATUS "Compiling against Gazebo Garden") # Default to Fortress else() find_package(ignition-gazebo6 REQUIRED) - set(GZ_SIM_VER ${ignition-gazebo6_VERSION_MAJOR}) message(STATUS "Compiling against Gazebo Fortress") endif()