From 00c0c1e1249a4ab0f7a13ee8d6bd549f3a429a5e Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Thu, 2 Mar 2023 13:05:07 -0800 Subject: [PATCH 1/3] gzserver.launch.py: _conditional_command helper Add a helper function to replace the functionality of _arg_command with the condition argument. Signed-off-by: Steve Peters --- gazebo_ros/launch/gzserver.launch.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/gazebo_ros/launch/gzserver.launch.py b/gazebo_ros/launch/gzserver.launch.py index c684ad5e3..e709a30e4 100644 --- a/gazebo_ros/launch/gzserver.launch.py +++ b/gazebo_ros/launch/gzserver.launch.py @@ -55,11 +55,16 @@ def generate_launch_description(): # Wait for (https://github.com/ros-simulation/gazebo_ros_pkgs/pull/941) # _plugin_command('force_system'), ' ', _arg_command('profile'), LaunchConfiguration('profile'), - # convenience parameter for params file - _arg_command('ros-args', condition=LaunchConfiguration('params_file')), - _arg_command('params-file', condition=LaunchConfiguration('params_file')), + # Support a yaml params_file: + # If a params file is to be used, it needs to be preceded by --ros-args + # and followed by a trailing -- + # This provides the leading --ros-args if a params_file is specified. + _conditional_command('ros-args', LaunchConfiguration('params_file')), + # These two lines provide the --params-file [params_file] arguments + _conditional_command('params-file', LaunchConfiguration('params_file')), LaunchConfiguration('params_file'), - _arg_command('', condition=LaunchConfiguration('params_file')), + # This provides the trailing -- if a params_file is specified. + _conditional_command('', LaunchConfiguration('params_file')), LaunchConfiguration('extra_gazebo_args'), ] @@ -230,6 +235,13 @@ def _arg_command(arg, condition=None): return py_cmd +# Add --command if condition not empty +def _conditional_command(arg, condition): + cmd = ['"--', arg, '" if "" != "', condition, '" else ""'] + py_cmd = PythonExpression(cmd) + return py_cmd + + # Add gazebo_ros plugins if true def _plugin_command(arg): cmd = ['"-s', 'libgazebo_ros_', arg, '.so" if "true" == "', From efa494f3285bd8516b1e32af925a72559e5232a7 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Thu, 2 Mar 2023 13:07:09 -0800 Subject: [PATCH 2/3] gzserver.launch.py: refactor _arg_command This refactors the _arg_command helper function to remove the condition parameter (which is now unused since the _conditional_command helper was added) and always passes the LaunchConfiguration along with the --command with a "join_with" separator. This simplifies the `cmd` array definition. Signed-off-by: Steve Peters --- gazebo_ros/launch/gzserver.launch.py | 29 +++++++++++++--------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/gazebo_ros/launch/gzserver.launch.py b/gazebo_ros/launch/gzserver.launch.py index e709a30e4..bd7d15b8d 100644 --- a/gazebo_ros/launch/gzserver.launch.py +++ b/gazebo_ros/launch/gzserver.launch.py @@ -39,22 +39,22 @@ def generate_launch_description(): _boolean_command('lockstep'), _boolean_command('help'), _boolean_command('pause'), - _arg_command('physics'), LaunchConfiguration('physics'), - _arg_command('play'), LaunchConfiguration('play'), + _arg_command('physics'), + _arg_command('play'), _boolean_command('record'), - _arg_command('record_encoding'), LaunchConfiguration('record_encoding'), - _arg_command('record_path'), LaunchConfiguration('record_path'), - _arg_command('record_period'), LaunchConfiguration('record_period'), - _arg_command('record_filter'), LaunchConfiguration('record_filter'), - _arg_command('seed'), LaunchConfiguration('seed'), - _arg_command('iters'), LaunchConfiguration('iters'), + _arg_command('record_encoding'), + _arg_command('record_path'), + _arg_command('record_period'), + _arg_command('record_filter'), + _arg_command('seed'), + _arg_command('iters'), _boolean_command('minimal_comms'), _plugin_command('init'), _plugin_command('factory'), _plugin_command('force_system'), # Wait for (https://github.com/ros-simulation/gazebo_ros_pkgs/pull/941) # _plugin_command('force_system'), ' ', - _arg_command('profile'), LaunchConfiguration('profile'), + _arg_command('profile'), # Support a yaml params_file: # If a params file is to be used, it needs to be preceded by --ros-args # and followed by a trailing -- @@ -225,14 +225,11 @@ def _boolean_command(arg): return py_cmd -# Add string commands if not empty -def _arg_command(arg, condition=None): - if condition: - cmd = ['"--', arg, '" if "" != "', condition, '" else ""'] - else: - cmd = ['"--', arg, '" if "" != "', LaunchConfiguration(arg), '" else ""'] +# Add string command and argument if not empty +def _arg_command(arg, join_with=" "): + cmd = ['"--', arg, join_with, '" if "" != "', LaunchConfiguration(arg), '" else ""'] py_cmd = PythonExpression(cmd) - return py_cmd + return (py_cmd, LaunchConfiguration(arg)) # Add --command if condition not empty From c6f90bcb365d63286fa4fa05fea6e5fdb89c2f03 Mon Sep 17 00:00:00 2001 From: Steve Peters Date: Thu, 2 Mar 2023 15:02:58 -0800 Subject: [PATCH 3/3] gzserver.launch.py: add initial_sim_time argument Expose gzserver CLI parameter added in gazebosim/gazebo-classic#3294. Signed-off-by: Steve Peters --- gazebo_ros/launch/gzserver.launch.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gazebo_ros/launch/gzserver.launch.py b/gazebo_ros/launch/gzserver.launch.py index bd7d15b8d..23f87cbb1 100644 --- a/gazebo_ros/launch/gzserver.launch.py +++ b/gazebo_ros/launch/gzserver.launch.py @@ -39,6 +39,9 @@ def generate_launch_description(): _boolean_command('lockstep'), _boolean_command('help'), _boolean_command('pause'), + # join with '=' (--initial_sim_time=[time]) so that old versions of + # gazebo will parse it all as a single argument and ignore the [time]. + _arg_command('initial_sim_time', join_with='='), _arg_command('physics'), _arg_command('play'), _boolean_command('record'), @@ -112,6 +115,10 @@ def generate_launch_description(): 'help', default_value='false', description='Set "true" to produce gzserver help message.' ), + DeclareLaunchArgument( + 'initial_sim_time', default_value='', + description='Specify the initial simulation time (seconds).' + ), DeclareLaunchArgument( 'pause', default_value='false', description='Set "true" to start the server in a paused state.'