Skip to content

Commit b2404b3

Browse files
committed
Add --remap argument to launch command
Signed-off-by: Jonathan <[email protected]>
1 parent f9ab937 commit b2404b3

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

ros2launch/ros2launch/api/api.py

Lines changed: 10 additions & 3 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 SetRemap
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+
remap_rules=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,19 @@ 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 remap_rules is not None:
174+
for remap_rule in remap_rules:
175+
from_name, to_name = remap_rule.split(':=', maxsplit=1)
176+
launch_description.add_action(SetRemap(src=from_name, dst=to_name))
177+
launch_description.add_action(
171178
launch.actions.IncludeLaunchDescription(
172179
launch.launch_description_sources.AnyLaunchDescriptionSource(
173180
launch_file_path
174181
),
175182
launch_arguments=parsed_launch_arguments,
176183
),
177-
])
184+
)
178185
for name in sorted(option_extensions.keys()):
179186
result = option_extensions[name].prelaunch(
180187
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+
'-r', '--remap', action='append', dest='remap_rules',
107+
help=("Topics remapping rules, in the 'from:=to' form")
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+
remap_rules=args.remap_rules
179184
)

0 commit comments

Comments
 (0)