Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ros2] Add default ign_gazebo version #145

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 37 additions & 8 deletions ros_ign_gazebo/launch/ign_gazebo.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,57 @@

"""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.actions import DeclareLaunchArgument, ExecuteProcess, OpaqueFunction
from launch.launch_context import LaunchContext
from launch.substitutions import LaunchConfiguration


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'),
DeclareLaunchArgument(
'ign_args', default_value='',
description='Arguments to be passed to Ignition Gazebo'),
ExecuteProcess(
cmd=['ign gazebo',
LaunchConfiguration('ign_args'),
OpaqueFunction(__get_ign_args)
],
output='screen',
additional_env=env,
shell=True
)
])


def __get_ign_args(context: LaunchContext):
ign_args = LaunchConfiguration('ign_args').perform(context)
if '--force_version' not in ign_args:
ign_args += f' --force_version {IGN_GAZEBO_DEFAULT_VERSION}'

return ign_args


def __get_ign_gazebo_default_version():
manifest_path = os.path.join(*[get_package_share_directory('ros_ign_gazebo'), 'package.xml'])

# this will fail if workspace was built with '--merge-install'
this_pkg = parse_package(manifest_path)

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()
3 changes: 3 additions & 0 deletions ros_ign_gazebo/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<depend condition="$IGNITION_VERSION == citadel">ignition-gazebo3</depend>
<depend condition="$IGNITION_VERSION == ''">ignition-gazebo3</depend>

<exec_depend>ament_index_python</exec_depend>
<exec_depend>python3-catkin-pkg-modules</exec_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

Expand Down