Skip to content

Commit

Permalink
Merge branch 'ros2' into caguero/navsat_demo_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
caguero authored Dec 13, 2024
2 parents 0d01a36 + 13b6640 commit 0590bc3
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 258 deletions.
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,26 @@
ROS 2 version | Gazebo version | Branch | Binaries hosted at
-- | -- | -- | --
Foxy | Citadel | [foxy](https://github.com/gazebosim/ros_gz/tree/foxy) | https://packages.ros.org
Foxy | Edifice | [foxy](https://github.com/gazebosim/ros_gz/tree/foxy) | only from source
Galactic | Edifice | [galactic](https://github.com/gazebosim/ros_gz/tree/galactic) | https://packages.ros.org
Foxy | Edifice | [foxy](https://github.com/gazebosim/ros_gz/tree/foxy) | only from source [^2]
Galactic | Edifice | [galactic](https://github.com/gazebosim/ros_gz/tree/galactic) | https://packages.ros.org [^2]
Galactic | Fortress | [galactic](https://github.com/gazebosim/ros_gz/tree/galactic) | only from source
Humble | Fortress | [humble](https://github.com/gazebosim/ros_gz/tree/humble) | https://packages.ros.org
Humble | Garden | [humble](https://github.com/gazebosim/ros_gz/tree/humble) | [gazebo packages](https://gazebosim.org/docs/latest/ros_installation#gazebo-garden-with-ros-2-humble-iron-or-rolling-use-with-caution-)[^1]
Humble | Garden | [humble](https://github.com/gazebosim/ros_gz/tree/humble) | [gazebo packages](https://gazebosim.org/docs/latest/ros_installation#gazebo-garden-with-ros-2-humble-iron-or-rolling-use-with-caution-)[^1] [^2]
Humble | Harmonic | [humble](https://github.com/gazebosim/ros_gz/tree/humble) | [gazebo packages](https://gazebosim.org/docs/harmonic/ros_installation#-gazebo-harmonic-with-ros-2-humble-iron-or-rolling-use-with-caution-)[^1]
Iron | Fortress | [humble](https://github.com/gazebosim/ros_gz/tree/iron) | https://packages.ros.org
Iron | Garden | [humble](https://github.com/gazebosim/ros_gz/tree/iron) | only from source
Iron | Garden | [humble](https://github.com/gazebosim/ros_gz/tree/iron) | only from source [^2]
Iron | Harmonic | [humble](https://github.com/gazebosim/ros_gz/tree/iron) | only from source
Jazzy | Garden | [ros2](https://github.com/gazebosim/ros_gz/tree/ros2) | only from source
Jazzy | Garden | [ros2](https://github.com/gazebosim/ros_gz/tree/ros2) | only from source [^2]
Jazzy | Harmonic | [jazzy](https://github.com/gazebosim/ros_gz/tree/jazzy) | https://packages.ros.org
Rolling | Fortress | [humble](https://github.com/gazebosim/ros_gz/tree/humble) | https://packages.ros.org
Rolling | Garden | [ros2](https://github.com/gazebosim/ros_gz/tree/ros2) | only from source
Rolling | Garden | [ros2](https://github.com/gazebosim/ros_gz/tree/ros2) | only from source [^2]
Rolling | Harmonic | [ros2](https://github.com/gazebosim/ros_gz/tree/ros2) | only from source

[^1]: Binaries for these pairings are provided from a the packages.osrfoundation.org repository. Refer to https://gazebosim.org/docs/latest/ros_installation for installation instructions.
[^1]: Binaries for these pairings are provided from the packages.osrfoundation.org repository. Refer to https://gazebosim.org/docs/latest/ros_installation for installation instructions.
[^2]: Note that the Gazebo version on this row has reached end-of-life.

For information on ROS(1) and Gazebo compatibility, refer to the [noetic branch README](https://github.com/gazebosim/ros_gz/tree/noetic)

> Please [ticket an issue](https://github.com/gazebosim/ros_gz/issues/) if you'd like support to be added for some combination.
[Details about the renaming process](README_RENAME.md) from `ign` to `gz` .

**Note**: The `ros_ign` prefixed packages are shim packages that redirect to their `ros_gz` counterpart.
Expand Down Expand Up @@ -86,7 +85,7 @@ Be sure you've installed

#### Gazebo

Install either [Fortress, Garden, or Harmonic](https://gazebosim.org/docs).
Install either [Fortress, Harmonic or Ionic](https://gazebosim.org/docs).

Set the `GZ_VERSION` environment variable to the Gazebo version you'd
like to compile against. For example:
Expand All @@ -97,7 +96,7 @@ like to compile against. For example:
#### Compile ros_gz

The following steps are for Linux and OSX.
The following steps are for Linux and macOS.

1. Create a colcon workspace:

Expand Down
211 changes: 103 additions & 108 deletions ros_gz_bridge/ros_gz_bridge/actions/ros_gz_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@

"""Module for the ros_gz bridge action."""

from typing import List
from typing import Optional
from typing import cast, Dict, List, Optional, Union

from launch.action import Action
from launch.actions import GroupAction
from launch.conditions import IfCondition
from launch.frontend import Entity, expose_action, Parser
from launch.launch_context import LaunchContext
from launch.some_substitutions_type import SomeSubstitutionsType
from launch.substitutions import PythonExpression
from launch.substitutions import TextSubstitution
from launch.utilities import ensure_argument_type
from launch.utilities.type_utils import normalize_typed_substitution, perform_typed_substitution
from launch_ros.actions import ComposableNodeContainer, LoadComposableNodes, Node
from launch_ros.descriptions import ComposableNode
from launch_ros.parameters_type import SomeParameters


@expose_action('ros_gz_bridge')
Expand All @@ -37,13 +37,13 @@ def __init__(
*,
bridge_name: SomeSubstitutionsType,
config_file: SomeSubstitutionsType,
container_name: Optional[SomeSubstitutionsType] = 'ros_gz_container',
create_own_container: Optional[SomeSubstitutionsType] = 'False',
namespace: Optional[SomeSubstitutionsType] = '',
use_composition: Optional[SomeSubstitutionsType] = 'False',
use_respawn: Optional[SomeSubstitutionsType] = 'False',
log_level: Optional[SomeSubstitutionsType] = 'info',
bridge_params: Optional[SomeSubstitutionsType] = '',
container_name: SomeSubstitutionsType = 'ros_gz_container',
create_own_container: Union[bool, SomeSubstitutionsType] = False,
namespace: SomeSubstitutionsType = '',
use_composition: Union[bool, SomeSubstitutionsType] = False,
use_respawn: Union[bool, SomeSubstitutionsType] = False,
log_level: SomeSubstitutionsType = 'info',
bridge_params: Optional[SomeParameters] = None,
**kwargs
) -> None:
"""
Expand All @@ -60,20 +60,49 @@ def __init__(
:param: bridge_params Extra parameters to pass to the bridge.
"""
super().__init__(**kwargs)

self.__bridge_name = bridge_name
self.__config_file = config_file
self.__container_name = container_name
self.__create_own_container = create_own_container
self.__namespace = namespace
self.__use_composition = use_composition
self.__use_respawn = use_respawn

# This is here to allow using strings or booleans as values for boolean variables when
# the Action is used from Python i.e., this allows users to do:
# RosGzBridge(bridge_name='bridge1', use_composition='true', create_own_container=True)
# Note that use_composition is set to a string while create_own_container is set to a
# boolean. The reverse would also work.
# At some point, we might want to deprecate this and only allow setting booleans since
# that's what users would expect when calling this from Python
if isinstance(create_own_container, str):
self.__create_own_container = normalize_typed_substitution(
TextSubstitution(text=create_own_container), bool
)
else:
self.__create_own_container = normalize_typed_substitution(
create_own_container, bool
)

if isinstance(use_composition, str):
self.__use_composition = normalize_typed_substitution(
TextSubstitution(text=use_composition), bool
)
else:
self.__use_composition = normalize_typed_substitution(use_composition, bool)

self.__use_respawn = normalize_typed_substitution(use_respawn, bool)
self.__log_level = log_level
self.__bridge_params = bridge_params
self.__bridge_params = [{'config_file': self.__config_file}]
if bridge_params is not None:
# This handling of bridge_params was copied from launch_ros/actions/node.py
ensure_argument_type(bridge_params, (list), 'bridge_params', 'RosGzBridge')
# All elements in the list are paths to files with parameters (or substitutions that
# evaluate to paths), or dictionaries of parameters (fields can be substitutions).
self.__bridge_params.extend(cast(list, bridge_params))

@classmethod
def parse(cls, entity: Entity, parser: Parser):
"""Parse ros_gz_bridge."""
_, kwargs = super().parse(entity, parser)
kwargs: Dict = super().parse(entity, parser)[1]

bridge_name = entity.get_attr(
'bridge_name', data_type=str,
Expand Down Expand Up @@ -107,9 +136,7 @@ def parse(cls, entity: Entity, parser: Parser):
'log_level', data_type=str,
optional=True)

bridge_params = entity.get_attr(
'bridge_params', data_type=str,
optional=True)
parameters = entity.get_attr('param', data_type=List[Entity], optional=True)

if isinstance(bridge_name, str):
bridge_name = parser.parse_substitution(bridge_name)
Expand Down Expand Up @@ -144,102 +171,70 @@ def parse(cls, entity: Entity, parser: Parser):
log_level = parser.parse_substitution(log_level)
kwargs['log_level'] = log_level

if isinstance(bridge_params, str):
bridge_params = parser.parse_substitution(bridge_params)
kwargs['bridge_params'] = bridge_params
if parameters is not None:
kwargs['bridge_params'] = Node.parse_nested_parameters(parameters, parser)

return cls, kwargs

def execute(self, context: LaunchContext) -> Optional[List[Action]]:
"""Execute the action."""
if hasattr(self.__bridge_params, 'perform'):
string_bridge_params = self.__bridge_params.perform(context)
elif isinstance(self.__bridge_params, list):
if hasattr(self.__bridge_params[0], 'perform'):
string_bridge_params = self.__bridge_params[0].perform(context)
else:
string_bridge_params = str(self.__bridge_params)
# Remove unnecessary symbols
simplified_bridge_params = string_bridge_params.translate(
{ord(i): None for i in '{} "\''}
use_composition_eval = perform_typed_substitution(
context, self.__use_composition, bool
)
# Parse to dictionary
parsed_bridge_params = {}
if simplified_bridge_params:
bridge_params_pairs = simplified_bridge_params.split(',')
parsed_bridge_params = dict(pair.split(':') for pair in bridge_params_pairs)

if isinstance(self.__use_composition, list):
self.__use_composition = self.__use_composition[0]

if isinstance(self.__create_own_container, list):
self.__create_own_container = self.__create_own_container[0]

if isinstance(self.__use_respawn, list):
self.__use_respawn = self.__use_respawn[0]

# Standard node configuration
load_nodes = GroupAction(
condition=IfCondition(PythonExpression(['not ', self.__use_composition])),
actions=[
Node(
package='ros_gz_bridge',
executable='bridge_node',
name=self.__bridge_name,
namespace=self.__namespace,
output='screen',
respawn=bool(self.__use_respawn),
respawn_delay=2.0,
parameters=[{'config_file': self.__config_file, **parsed_bridge_params}],
arguments=['--ros-args', '--log-level', self.__log_level],
),
],
create_own_container_eval = perform_typed_substitution(
context, self.__create_own_container, bool
)

launch_descriptions: List[Action] = []

if not use_composition_eval:
# Standard node configuration
launch_descriptions.append(Node(
package='ros_gz_bridge',
executable='bridge_node',
name=self.__bridge_name,
namespace=self.__namespace,
output='screen',
respawn=perform_typed_substitution(context, self.__use_respawn, bool),
respawn_delay=2.0,
parameters=self.__bridge_params,
arguments=['--ros-args', '--log-level', self.__log_level],
))

# Composable node with container configuration
load_composable_nodes_with_container = ComposableNodeContainer(
condition=IfCondition(
PythonExpression([self.__use_composition, ' and ', self.__create_own_container])
),
name=self.__container_name,
namespace='',
package='rclcpp_components',
executable='component_container',
composable_node_descriptions=[
ComposableNode(
package='ros_gz_bridge',
plugin='ros_gz_bridge::RosGzBridge',
name=self.__bridge_name,
namespace=self.__namespace,
parameters=[{'config_file': self.__config_file, **parsed_bridge_params}],
extra_arguments=[{'use_intra_process_comms': True}],
),
],
output='screen',
)
if use_composition_eval and create_own_container_eval:
launch_descriptions.append(ComposableNodeContainer(
name=self.__container_name,
namespace='',
package='rclcpp_components',
executable='component_container',
composable_node_descriptions=[
ComposableNode(
package='ros_gz_bridge',
plugin='ros_gz_bridge::RosGzBridge',
name=self.__bridge_name,
namespace=self.__namespace,
parameters=self.__bridge_params,
extra_arguments=[{'use_intra_process_comms': True}],
),
],
output='screen',
))

# Composable node without container configuration
load_composable_nodes_without_container = LoadComposableNodes(
condition=IfCondition(
PythonExpression(
[self.__use_composition, ' and not ', self.__create_own_container]
)
),
target_container=self.__container_name,
composable_node_descriptions=[
ComposableNode(
package='ros_gz_bridge',
plugin='ros_gz_bridge::RosGzBridge',
name=self.__bridge_name,
namespace=self.__namespace,
parameters=[{'config_file': self.__config_file, **parsed_bridge_params}],
extra_arguments=[{'use_intra_process_comms': True}],
),
],
)

return [
load_nodes,
load_composable_nodes_with_container,
load_composable_nodes_without_container
]
if use_composition_eval and not create_own_container_eval:
launch_descriptions.append(LoadComposableNodes(
target_container=self.__container_name,
composable_node_descriptions=[
ComposableNode(
package='ros_gz_bridge',
plugin='ros_gz_bridge::RosGzBridge',
name=self.__bridge_name,
namespace=self.__namespace,
parameters=self.__bridge_params,
extra_arguments=[{'use_intra_process_comms': True}],
),
],
))

return launch_descriptions
Loading

0 comments on commit 0590bc3

Please sign in to comment.