Skip to content

Commit

Permalink
[ros2] Port gazebo launch scripts to ROS2 (ros-simulation#962)
Browse files Browse the repository at this point in the history
* [ros2] Port gazebo launch scripts to ROS2

* Add gdb and valgrind option

* Use shell command for extra gazebo args
  • Loading branch information
shiveshkhaitan committed Aug 15, 2019
1 parent 53bac8d commit 2edc893
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 225 deletions.
22 changes: 0 additions & 22 deletions .ros1_unported/gazebo_ros/scripts/debug

This file was deleted.

55 changes: 0 additions & 55 deletions .ros1_unported/gazebo_ros/scripts/gazebo

This file was deleted.

25 changes: 0 additions & 25 deletions .ros1_unported/gazebo_ros/scripts/gdbrun

This file was deleted.

42 changes: 0 additions & 42 deletions .ros1_unported/gazebo_ros/scripts/gzclient

This file was deleted.

41 changes: 0 additions & 41 deletions .ros1_unported/gazebo_ros/scripts/gzserver

This file was deleted.

19 changes: 0 additions & 19 deletions .ros1_unported/gazebo_ros/scripts/libcommon.sh

This file was deleted.

21 changes: 0 additions & 21 deletions .ros1_unported/gazebo_ros/scripts/perf

This file was deleted.

35 changes: 35 additions & 0 deletions gazebo_ros/launch/gazebo.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2019 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 server and client with command line arguments."""

from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import ThisLaunchFileDir


def generate_launch_description():

# (TODO) Allow conditional include of gzserver and gzclient, once supported
# https://github.com/ros2/launch/issues/303
return LaunchDescription([
IncludeLaunchDescription(
PythonLaunchDescriptionSource([ThisLaunchFileDir(), '/gzserver.launch.py']),
),

IncludeLaunchDescription(
PythonLaunchDescriptionSource([ThisLaunchFileDir(), '/gzclient.launch.py']),
),
])
82 changes: 82 additions & 0 deletions gazebo_ros/launch/gzclient.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright 2019 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 a Gazebo client 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
from launch.substitutions import PythonExpression

from scripts import GazeboRosPaths


def generate_launch_description():
model, plugin, media = GazeboRosPaths.get_paths()

if 'GAZEBO_MODEL_PATH' in environ:
model += ':'+environ['GAZEBO_MODEL_PATH']
if 'GAZEBO_PLUGIN_PATH' in environ:
plugin += ':'+environ['GAZEBO_PLUGIN_PATH']
if 'GAZEBO_RESOURCE_PATH' in environ:
media += ':'+environ['GAZEBO_RESOURCE_PATH']

env = {'GAZEBO_MODEL_PATH': model,
'GAZEBO_PLUGIN_PATH': plugin,
'GAZEBO_RESOURCE_PATH': media}

return LaunchDescription([
DeclareLaunchArgument('version', default_value='false',
description='Set "true" to output version information'),
DeclareLaunchArgument('verbose', default_value='false',
description='Set "true" to increase messages written to terminal'),
DeclareLaunchArgument('help', default_value='false',
description='Set "true" to produce gzclient help message'),
DeclareLaunchArgument('extra_gazebo_args', default_value='',
description='Extra arguments to be passed to Gazebo'),

# Specific to gazebo_ros
DeclareLaunchArgument('gdb', default_value='false',
description='Set "true" to run gzserver with gdb'),
DeclareLaunchArgument('valgrind', default_value='false',
description='Set "true" to run gzserver with valgrind'),

# Execute
ExecuteProcess(
cmd=[['gzclient',
_boolean_command('version'), ' ',
_boolean_command('verbose'), ' ',
_boolean_command('help'), ' ',
LaunchConfiguration('extra_gazebo_args'),
]],
output='screen',
additional_env=env,
shell=True,
prefix=PythonExpression(['"gdb -ex run --args" if "true" == "',
LaunchConfiguration('gdb'),
'"else "valgrind" if "true" == "',
LaunchConfiguration('valgrind'),
'"else ""']),
)
])


# Add boolean commands if true
def _boolean_command(arg):
cmd = ['"--', arg, '" if "true" == "', LaunchConfiguration(arg), '" else ""']
py_cmd = PythonExpression(cmd)
return py_cmd
Loading

0 comments on commit 2edc893

Please sign in to comment.