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

Add --namespace argument to launch command. #433

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
13 changes: 9 additions & 4 deletions ros2launch/ros2launch/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import launch
from launch.frontend import Parser
from launch.launch_description_sources import get_launch_description_from_any_launch_file
from launch_ros.actions import PushROSNamespace


class MultipleLaunchFilesError(Exception):
Expand Down Expand Up @@ -145,7 +146,8 @@ def launch_a_launch_file(
noninteractive=False,
args=None,
option_extensions={},
debug=False
debug=False,
namespace=None
):
"""Launch a given launch file (by path) and pass it the given launch file arguments."""
for name in sorted(option_extensions.keys()):
Expand All @@ -167,14 +169,17 @@ def launch_a_launch_file(
parsed_launch_arguments = parse_launch_arguments(launch_file_arguments)
# Include the user provided launch file using IncludeLaunchDescription so that the
# location of the current launch file is set.
launch_description = launch.LaunchDescription([
launch_description = launch.LaunchDescription()
if namespace is not None:
launch_description.add_action(PushROSNamespace(namespace))
launch_description.add_action(
launch.actions.IncludeLaunchDescription(
launch.launch_description_sources.AnyLaunchDescriptionSource(
launch_file_path
),
launch_arguments=parsed_launch_arguments,
),
])
)
)
for name in sorted(option_extensions.keys()):
result = option_extensions[name].prelaunch(
launch_description,
Expand Down
7 changes: 6 additions & 1 deletion ros2launch/ros2launch/command/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def add_arguments(self, parser, cli_name):
help=('Regex pattern for filtering which executables the --launch-prefix is applied '
'to by matching the executable name.')
)
parser.add_argument(
'--namespace',
help=('A namespace to push to the actions/nodes started by the launch file.')
)
arg = parser.add_argument(
'package_name',
help='Name of the ROS package which contains the launch file')
Expand Down Expand Up @@ -175,5 +179,6 @@ def main(self, *, parser, args):
noninteractive=args.noninteractive,
args=args,
option_extensions=self._option_extensions,
debug=args.debug
debug=args.debug,
namespace=args.namespace
)