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

Fix launch substitutions for ign_args #309

Merged
merged 4 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
81 changes: 38 additions & 43 deletions ros_gz_sim/launch/gz_sim.launch.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,53 @@
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='')]),
'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='')])}

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'),
Expand All @@ -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),
])
1 change: 1 addition & 0 deletions ros_gz_sim/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>pkg-config</buildtool_depend>

<depend>ament_index_python</depend>
<depend>libgflags-dev</depend>
<depend>rclcpp</depend>
<depend>std_msgs</depend>
Expand Down
12 changes: 1 addition & 11 deletions ros_ign_gazebo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,8 @@ else()
message(STATUS "Compiling against Gazebo Fortress")
endif()

configure_file(
mjcarroll marked this conversation as resolved.
Show resolved Hide resolved
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
)

Expand Down
33 changes: 33 additions & 0 deletions ros_ign_gazebo/launch/ign_gazebo.launch.py
Original file line number Diff line number Diff line change
@@ -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
mjcarroll marked this conversation as resolved.
Show resolved Hide resolved

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'))
)
])
100 changes: 0 additions & 100 deletions ros_ign_gazebo/launch/ign_gazebo.launch.py.in

This file was deleted.