diff --git a/ros_ign_gazebo/launch/ign_gazebo.launch.py b/ros_ign_gazebo/launch/ign_gazebo.launch.py index c889a351..ed9b2bab 100644 --- a/ros_ign_gazebo/launch/ign_gazebo.launch.py +++ b/ros_ign_gazebo/launch/ign_gazebo.launch.py @@ -14,28 +14,51 @@ """Launch Ignition Gazebo with command line arguments.""" -from os import environ +import os + +from ament_index_python.packages import get_package_share_directory, +from catkin_pkg.package import parse_package from launch import LaunchDescription from launch.actions import DeclareLaunchArgument from launch.actions import ExecuteProcess -from launch.substitutions import LaunchConfiguration +from launch.substitutions import LaunchConfiguration, PathJoinSubstitution +from launch_ros.substitutions import FindPackageShare def generate_launch_description(): env = {'IGN_GAZEBO_SYSTEM_PLUGIN_PATH': - ':'.join([environ.get('IGN_GAZEBO_SYSTEM_PLUGIN_PATH', default=''), - environ.get('LD_LIBRARY_PATH', default='')])} + ':'.join([os.environ.get('IGN_GAZEBO_SYSTEM_PLUGIN_PATH', default=''), + os.environ.get('LD_LIBRARY_PATH', default='')])} return LaunchDescription([ DeclareLaunchArgument('ign_args', default_value='', description='Arguments to be passed to Ignition Gazebo'), ExecuteProcess( cmd=['ign gazebo', - LaunchConfiguration('ign_args'), + __get_ign_args(LaunchConfiguration('ign_args')), ], output='screen', additional_env=env, shell=True ) ]) + + +def __get_ign_args(ign_args): + if '--force_version' not in ign_args: + ign_args += '--force_version {}'.format(__IGN_GAZEBO_DEFAULT_VERSION) + + return ign_args + + +def __get_ign_gazebo_default_version(): # this will fail if the package build was performed with '--merge-install' + this_pkg = parse_package(os.path.join(*[get_package_share_directory('ros_ign_gazebo'), 'package.xml'])) + this_pkg.evaluate_conditions(os.environ) + lookup_name = next(dep.name for dep in this_pkg.exec_depends + if dep.evaluated_condition + if 'ignition-gazebo' in dep.name) + + return lookup_name.replace('ignition-gazebo', '') + +__IGN_GAZEBO_DEFAULT_VERSION=__get_ign_gazebo_default_version() diff --git a/ros_ign_gazebo/package.xml b/ros_ign_gazebo/package.xml index 47ea5c4e..dc665c5f 100644 --- a/ros_ign_gazebo/package.xml +++ b/ros_ign_gazebo/package.xml @@ -17,6 +17,9 @@ rclcpp ignition-math6 + ament_index_python + python3-catkin-pkg-modules + ignition-gazebo4 ignition-msgs6