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

Launch gzserver from xml #548

Merged
merged 28 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
82f4ffb
Launch file for the bridge
caguero Apr 10, 2024
968a9dc
Tweak
caguero Apr 10, 2024
ff3149b
Tweak
caguero Apr 11, 2024
1ff1ae7
gzserver launch file
caguero Apr 12, 2024
7ebdffd
Rename
caguero Apr 12, 2024
d220277
Merge branch 'gz_sim_ros_node_composition' into gzserver_launch
caguero Apr 12, 2024
09da4ed
Create a combined bridge+gzserver launch file.
caguero Apr 12, 2024
7718888
Spawn models with bridge
caguero Apr 12, 2024
de3908a
Initial launch_gz
caguero Apr 18, 2024
3860b74
Update ros_gz_sim/launch/ros_gz_sim.launch.py
caguero Apr 18, 2024
54c68d7
Tweaks
caguero Apr 18, 2024
774334f
Merge from gz_sim_ros_node_composition
caguero Apr 18, 2024
1990402
Merge branch 'gzserver_and_bridge_launch' into spawn_model_and_bridge…
caguero Apr 18, 2024
4b16d7a
Style
caguero Apr 18, 2024
73dc37d
Tweaks
caguero Apr 26, 2024
c7aa5a5
Working gzserver.launch example
caguero May 10, 2024
9709a9f
Tweak
caguero May 13, 2024
43f2a88
Merge branch 'spawn_model_and_bridge_launch' into launch_gz
caguero May 13, 2024
16e5779
Merge branch 'gz_sim_ros_node_composition' into gzserver_and_bridge_l…
caguero May 13, 2024
c7fd874
Merge branch 'gzserver_and_bridge_launch' into spawn_model_and_bridge…
caguero May 13, 2024
ca47316
Merge branch 'spawn_model_and_bridge_launch' into launch_gz
caguero May 13, 2024
e6201ca
Update launch_gz/launch_gz/actions/__init__.py
caguero May 13, 2024
4e502c2
Update launch_gz/launch_gz/actions/gzserver.py
caguero May 13, 2024
95e9c78
Update launch_gz/launch_gz/actions/gzserver.py
caguero May 13, 2024
f4a6d1a
Update launch_gz/setup.py
caguero May 13, 2024
53c024a
Tweak
caguero May 13, 2024
7bcbd32
Merge branch 'gz_sim_ros_node_composition' into launch_gz
caguero May 15, 2024
7b80582
Adding launch_ros dependency
caguero May 17, 2024
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
22 changes: 22 additions & 0 deletions launch_gz/launch_gz/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 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.

"""Main entry point for the `launch_gz` package."""

from . import actions


__all__ = [
'actions',
]
22 changes: 22 additions & 0 deletions launch_gz/launch_gz/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 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.

"""Actions module."""

from .gzserver import GzServer


__all__ = [
'GzServer',
]
115 changes: 115 additions & 0 deletions launch_gz/launch_gz/actions/gzserver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Copyright 2024 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.

"""Module for the GzServer action."""

from typing import List
from typing import Optional

from launch.action import Action
from launch.actions import IncludeLaunchDescription
from launch.frontend import expose_action, Entity, Parser
from launch.launch_context import LaunchContext
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.some_substitutions_type import SomeSubstitutionsType
from launch.substitutions import PathJoinSubstitution
from launch_ros.substitutions import FindPackageShare

@expose_action('gzserver')
class GzServer(Action):
"""Action that executes a gzserver ROS [composable] node."""

def __init__(
self,
*,
world_sdf_file: SomeSubstitutionsType,
world_sdf_string: SomeSubstitutionsType,
container_name: SomeSubstitutionsType,
use_composition: SomeSubstitutionsType,
**kwargs
) -> None:
"""
Construct a gzserver action.

All arguments are forwarded to `ros_gz_sim.launch.gzserver.launch.py`, so see the documentation
of that class for further details.

:param: world_sdf_file Path to the SDF world file.
:param: world_sdf_string SDF world string.
:param: container_name Name of container that nodes will load in if use composition.
:param: use_composition Use composed bringup if True.
"""

super().__init__(**kwargs)
self.__world_sdf_file = world_sdf_file
self.__world_sdf_string = world_sdf_string
self.__container_name = container_name
self.__use_composition = use_composition

@classmethod
def parse(cls, entity: Entity, parser: Parser):
"""Parse gzserver."""
_, kwargs = super().parse(entity, parser)

world_sdf_file = entity.get_attr(
'world_sdf_file', data_type=str,
optional=True)

world_sdf_string = entity.get_attr(
'world_sdf_string', data_type=str,
optional=True)

container_name = entity.get_attr(
'container_name', data_type=str,
optional=True)

use_composition = entity.get_attr(
'use_composition', data_type=str,
optional=True)

if isinstance(world_sdf_file, str):
world_sdf_file = parser.parse_substitution(world_sdf_file)
kwargs['world_sdf_file'] = world_sdf_file

if isinstance(world_sdf_string, str):
world_sdf_string = parser.parse_substitution(world_sdf_string)
kwargs['world_sdf_string'] = world_sdf_string

if isinstance(container_name, str):
container_name = parser.parse_substitution(container_name)
kwargs['container_name'] = container_name

if isinstance(use_composition, str):
use_composition = parser.parse_substitution(use_composition)
kwargs['use_composition'] = use_composition

return cls, kwargs

def execute(self, context: LaunchContext) -> Optional[List[Action]]:
"""
Execute the action.
"""

gzserver_description = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
[PathJoinSubstitution([FindPackageShare('ros_gz_sim'),
'launch',
'gzserver.launch.py'])]),
launch_arguments=[('world_sdf_file', self.__world_sdf_file),
('world_sdf_string', self.__world_sdf_string),
('container_name', self.__container_name),
('use_composition', self.__use_composition),
])

return [gzserver_description]
36 changes: 36 additions & 0 deletions launch_gz/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<?xml-model
href="http://download.ros.org/schema/package_format2.xsd"
schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>launch_gz</name>
<version>0.246.0</version>
<description>gz specific extensions to the launch tool.</description>

<maintainer email="ahcorde@openrobotics.org">Alejandro Hernandez</maintainer>
<maintainer email="caguero@openrobotics.org">Carlos Agüero</maintainer>

<license>Apache License 2.0</license>

<author email="caguero@openrobotics.org">Carlos Agüero</author>

<depend>ament_index_python</depend>
<depend>composition_interfaces</depend>
<depend>launch</depend>
<depend>launch_ros</depend>
<depend>lifecycle_msgs</depend>
<depend>osrf_pycommon</depend>
<depend>ros_gz_sim</depend>
<depend>python3-importlib-metadata</depend>
<depend>python3-yaml</depend>
<depend>rclpy</depend>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>

<export>
<build_type>ament_python</build_type>
</export>
</package>
Empty file added launch_gz/resource/launch_gz
Empty file.
49 changes: 49 additions & 0 deletions launch_gz/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from setuptools import find_packages
from setuptools import setup

package_name = 'launch_gz'

setup(
name=package_name,
version='0.246.0',
packages=find_packages(exclude=['test']),
data_files=[
('share/' + package_name, ['package.xml']),
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
],
package_data={'launch_gz': ['py.typed']},
install_requires=[
'setuptools',
'ament_index_python',
'launch',
mjcarroll marked this conversation as resolved.
Show resolved Hide resolved
'launch_ros',
'osrf_pycommon',
'pyyaml',
],
zip_safe=True,
author='Carlos Agüero',
author_email='caguero@openrobotics.org',
maintainer='Carlos Agüero, Alejandro Hernandez, Michael Carroll',
maintainer_email='caguero@openrobotics.org, alejandro@openrobotics.org, mjcarroll@intrinsic.ai',
url='https://github.com/gazebosim/ros_gz/launch_gz',
download_url='https://github.com/gazebosim/ros_gz/releases',
keywords=['ROS'],
classifiers=[
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
'Topic :: Software Development',
],
description='gz specific extensions to `launch`.',
long_description=(
'This package provides gz specific extensions to the launch package.'
),
license='Apache License, Version 2.0',
tests_require=['pytest'],
entry_points={
'launch.frontend.launch_extension': [
'launch_gz = launch_gz',
],
}
)
3 changes: 2 additions & 1 deletion ros_gz_sim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ install(FILES
)

install(FILES
"launch/gz_server.launch.py"
"launch/gzserver.launch"
"launch/gzserver.launch.py"
"launch/gz_spawn_model.launch.py"
"launch/ros_gz_sim.launch.py"
"launch/ros_gz_spawn_model.launch.py"
Expand Down
12 changes: 12 additions & 0 deletions ros_gz_sim/launch/gzserver.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<launch>
<arg name="world_sdf_file" default="empty.sdf" />
<arg name="world_sdf_string" default="" />
<arg name="container_name" default="ros_gz_container" />
<arg name="use_composition" default="False" />
<gzserver
world_sdf_file="$(var world_sdf_file)"
world_sdf_string="$(var world_sdf_string)"
container_name="$(var container_name)"
use_composition="$(var use_composition)">
</gzserver>
</launch>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""Launch gzserver in a component container."""

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, GroupAction
from launch.actions import DeclareLaunchArgument
from launch.conditions import IfCondition
from launch.substitutions import LaunchConfiguration, PythonExpression, TextSubstitution
from launch_ros.actions import ComposableNodeContainer, Node
Expand All @@ -24,42 +24,31 @@

def generate_launch_description():

world_sdf_file = LaunchConfiguration('world_sdf_file')
world_sdf_string = LaunchConfiguration('world_sdf_string')
container_name = LaunchConfiguration('container_name')
use_composition = LaunchConfiguration('use_composition')

declare_world_sdf_file_cmd = DeclareLaunchArgument(
'world_sdf_file', default_value=TextSubstitution(text=''),
description='Path to the SDF world file')
declare_world_sdf_string_cmd = DeclareLaunchArgument(
'world_sdf_string', default_value=TextSubstitution(text=''),
description='SDF world string')
declare_container_name_cmd = DeclareLaunchArgument(
'container_name',
default_value='ros_gz_container',
description='Name of container that nodes will load in if use composition',
)
'container_name', default_value='ros_gz_container',
description='Name of container that nodes will load in if use composition',)
declare_use_composition_cmd = DeclareLaunchArgument(
'use_composition', default_value='False', description='Use composed bringup if True'
)
'use_composition', default_value='False',
description='Use composed bringup if True')

load_nodes = GroupAction(
condition=IfCondition(PythonExpression(['not ', use_composition])),
actions=[
Node(
package='ros_gz_sim',
executable='gzserver',
output='screen',
parameters=[{'world_sdf_file': world_sdf_file,
'world_sdf_string': world_sdf_string}],
),
],
load_nodes = Node(
condition=IfCondition(PythonExpression(['not ', LaunchConfiguration('use_composition')])),
package='ros_gz_sim',
executable='gzserver',
output='screen',
parameters=[{'world_sdf_file': LaunchConfiguration('world_sdf_file'),
'world_sdf_string': LaunchConfiguration('world_sdf_string')}],
)

load_composable_nodes = ComposableNodeContainer(
condition=IfCondition(use_composition),
name=container_name,
condition=IfCondition(LaunchConfiguration('use_composition')),
name=LaunchConfiguration('container_name'),
namespace='',
package='rclcpp_components',
executable='component_container',
Expand All @@ -68,8 +57,8 @@ def generate_launch_description():
package='ros_gz_sim',
plugin='ros_gz_sim::GzServer',
name='gzserver',
parameters=[{'world_sdf_file': world_sdf_file,
'world_sdf_string': world_sdf_string}],
parameters=[{'world_sdf_file': LaunchConfiguration('world_sdf_file'),
'world_sdf_string': LaunchConfiguration('world_sdf_string')}],
extra_arguments=[{'use_intra_process_comms': True}],
),
],
Expand Down
2 changes: 1 addition & 1 deletion ros_gz_sim/launch/ros_gz_sim.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def generate_launch_description():
PythonLaunchDescriptionSource(
[PathJoinSubstitution([FindPackageShare('ros_gz_sim'),
'launch',
'gz_server.launch.py'])]),
'gzserver.launch.py'])]),
launch_arguments=[('world_sdf_file', world_sdf_file),
('world_sdf_string', world_sdf_string),
('use_composition', use_composition), ])
Expand Down