Issue in unit 4 - bt_navigation.yaml - path_planner_server vs absolute path to behavior.xml

Hi,

In the bt_navigation.yaml:

default_nav_to_pose_bt_xml: “/home/user/ros2_ws/src/path_planner/config/behavior.xml”

But later the material asks us to create a package path_planner_server, so the bt_navigation.yaml file will contain a bad path for the behavior.xml file.

See here:

You can easily fix it, but I think, pointing to a file in the src directory is bad practice. Also i think, that using hard-coded absolute path is fragile, so I looked for a better solution.

The documentation says
https://navigation.ros.org/configuration/packages/configuring-bt-navigator.html#example

default_nav_to_pose_bt_xml: replace/with/path/to/bt.xml # or $(find-pkg-share my_package)/behavior_tree/my_nav_to_pose_bt.xml

that we can use $(find-pkg-share my_package) but it did not work for me nor I did see it in the ROS2 source, so probably this is a mistake in the docs.
However, there is a possibility to change the yaml file itself, like this:

    shared_dir = get_package_share_directory('path_planner_server')
    config_dir = os.path.join(shared_dir, 'config') 

    bt_navigator_yaml_raw = os.path.join(config_dir, 'bt_navigator.yaml')
    context = LaunchContext()
    param_substitutions = {
        'default_nav_to_pose_bt_xml': os.path.join(config_dir, 'behavior.xml')
    }

    configured_params = RewrittenYaml(
        source_file=bt_navigator_yaml_raw,
        root_key='',
        param_rewrites=param_substitutions
    )

    bt_navigator_yaml = configured_params.perform(context)

    bt_nav_node = Node(
            package='nav2_bt_navigator',
            executable='bt_navigator',
            name='bt_navigator',
            output='screen',
            parameters=[bt_navigator_yaml]
    )

Where RewrittenYaml is in nav2_common package and they are using this exactly for this purpose:

See where I found all these info:

So for a quick fix you can edit the bt_navigation.yaml with a “proper” path or for a more general solution you may add this RewrittenYaml trick to the material. Or maybe there are other solutions, so if you know one, please, point me to the right direction.

Thank you in advance
Péter

Hi @peterborkuti

Thank you for the feedback. We’ll review it and update the notes if applicable.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.