0
$\begingroup$

I am lost :) Here is the problem (ROS2). Say, I have

params_file = LaunchConfiguration('params_file')
declare_params_file_cmd = DeclareLaunchArgument(
    'params_file',
    default_value=def_nav2_params_path 
        if robots[0]['name']=='' else def_nav2_params_path_multi,
    description='Full path to the ROS2 parameters file to use for all launched nodes')

Now I have access to this command line parameter in some node:

params_file = LaunchConfiguration('params_file')

So far so good.

But let's say I want to modify the file in a "calling" code:

namespaced_params = ReplaceString(
    source_file=params_file, replacements={
        "namespace"  :  (namespace),                # /robot1
        "robot_name" :  (robot['name']),            # robot1                
    }
)

Now I want the node to use that modified file:

robot_localization_node = Node(
    package='robot_localization',
    executable='ekf_node',
    name='ekf_filter_node',
    namespace=namespace,
    output='screen',
    parameters=[namespaced_params, {'use_sim_time': use_sim_time }]
) 

It works fine. However, we also have LaunchDescriptions, so I can call one launch file from another:

IncludeLaunchDescription(
    PythonLaunchDescriptionSource(os.path.join(def_launch_dir, 'bringup_launch.py')),
    condition=LaunchConfigurationNotEquals('mode', 'simple'),
    launch_arguments={
        'namespace': namespace,
        'use_namespace': 'True',
        'slam': slam,
        'map': map_yaml_file,
        'keepout_mask': keepout_mask,
        'use_sim_time': use_sim_time,
        'params_file': namespaced_params,
        'default_bt_xml_filename': default_bt_xml_filename,
        'autostart': 'True' }.items()),
])

Here, I have passed namespaced_params to launch file, but I have no idea how to use it! Because in that launch file I see the already familiar

params_file = LaunchConfiguration('params_file')

which reads a command line argument, so I assume, it will get an initial, non-modifier params file. So how can I access namespaced_params?

Thank you.

=================

I'll try to rephrase it shorter: if in a "main" launch file I have

params_file = LaunchConfiguration('params_file')
declare_params_file_cmd = DeclareLaunchArgument(
    'params_file',
    default_value=def_nav2_params_path 
        if robots[0]['name']=='' else def_nav2_params_path_multi,
    description='Full path to the ROS2 parameters file to use for all launched nodes')

and then I do this:

namespaced_params = ReplaceString(
    source_file=params_file, replacements={
        "namespace"  :  (namespace),                # /robot1
        "robot_name" :  (robot['name']),            # robot1                
    }
)

and pass namespaced_params as one of launch_arguments:

IncludeLaunchDescription(
    PythonLaunchDescriptionSource(os.path.join(def_launch_dir, 'bringup_launch.py')),
    condition=LaunchConfigurationNotEquals('mode', 'simple'),
    launch_arguments={
        'namespace': namespace,
        'use_namespace': 'True',
        'slam': slam,
        'map': map_yaml_file,
        'keepout_mask': keepout_mask,
        'use_sim_time': use_sim_time,
        'params_file': namespaced_params,
        'default_bt_xml_filename': default_bt_xml_filename,
        'autostart': 'True' }.items()),
])

Then which of the two will I get inside bringup_launch.py, when I issue params_file = LaunchConfiguration('params_file') ?

In other words, how can I access launch_arguments that I passed to bringup_launch.py?

$\endgroup$
0

1 Answer 1

1
$\begingroup$

I have figured it all out. A fully functional example at https://robotics.snowcron.com, in the "multiple robots" section.

$\endgroup$
5
  • $\begingroup$ This seems to be a link only answer. If the link dies then your answer will not be much use. Please edit and add the relevant details from the link. $\endgroup$ Commented Jul 25, 2023 at 19:08
  • $\begingroup$ Welcome to Robotics, Steve Brown. I followed your link but there is no obvious answer there. Please edit your answer to explain what steps you needed to follow to resolve your question. $\endgroup$
    – Chuck
    Commented Jul 26, 2023 at 11:48
  • $\begingroup$ I am away from the comp. now, but I will in 2 weeks, hope it is ok. $\endgroup$ Commented Jul 26, 2023 at 21:05
  • $\begingroup$ Hello @SteveBrown, any updates? $\endgroup$
    – Chuck
    Commented Aug 9, 2023 at 11:48
  • $\begingroup$ A fully functioning implementation is available by the link. Briefly, I cheated. I ignored params_file, and passed namespaced_params as an additional parameter. Now, in a target file, I can use namespaced_params parameter, and it doesn't interfere with params_file. $\endgroup$ Commented Aug 24, 2023 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.