Skip to content

Commit 0e09968

Browse files
StefanFabiankramer-sim
authored andcommitted
Add --namespace argument to launch command to push a namespace when launching a launch file.
Signed-off-by: Stefan Fabian <[email protected]> Signed-off-by: Markus Kramer <[email protected]>
1 parent f9ab937 commit 0e09968

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

ros2launch/ros2launch/api/api.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import launch
2626
from launch.frontend import Parser
2727
from launch.launch_description_sources import get_launch_description_from_any_launch_file
28+
from launch_ros.actions import PushROSNamespace
2829

2930

3031
class MultipleLaunchFilesError(Exception):
@@ -145,7 +146,8 @@ def launch_a_launch_file(
145146
noninteractive=False,
146147
args=None,
147148
option_extensions={},
148-
debug=False
149+
debug=False,
150+
namespace=None
149151
):
150152
"""Launch a given launch file (by path) and pass it the given launch file arguments."""
151153
for name in sorted(option_extensions.keys()):
@@ -167,14 +169,17 @@ def launch_a_launch_file(
167169
parsed_launch_arguments = parse_launch_arguments(launch_file_arguments)
168170
# Include the user provided launch file using IncludeLaunchDescription so that the
169171
# location of the current launch file is set.
170-
launch_description = launch.LaunchDescription([
172+
launch_description = launch.LaunchDescription()
173+
if namespace is not None:
174+
launch_description.add_action(PushROSNamespace(namespace))
175+
launch_description.add_action(
171176
launch.actions.IncludeLaunchDescription(
172177
launch.launch_description_sources.AnyLaunchDescriptionSource(
173178
launch_file_path
174179
),
175180
launch_arguments=parsed_launch_arguments,
176-
),
177-
])
181+
)
182+
)
178183
for name in sorted(option_extensions.keys()):
179184
result = option_extensions[name].prelaunch(
180185
launch_description,

ros2launch/ros2launch/command/launch.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ def add_arguments(self, parser, cli_name):
102102
help=('Regex pattern for filtering which executables the --launch-prefix is applied '
103103
'to by matching the executable name.')
104104
)
105+
parser.add_argument(
106+
'--namespace',
107+
help=('A namespace to push to the actions/nodes started by the launch file.')
108+
)
105109
arg = parser.add_argument(
106110
'package_name',
107111
help='Name of the ROS package which contains the launch file')
@@ -175,5 +179,6 @@ def main(self, *, parser, args):
175179
noninteractive=args.noninteractive,
176180
args=args,
177181
option_extensions=self._option_extensions,
178-
debug=args.debug
182+
debug=args.debug,
183+
namespace=args.namespace
179184
)

0 commit comments

Comments
 (0)