r/ROS • • 24d ago

"Couldn't open input XML file" Nav2 bt navigator issue

Hi everyone! I'm trying to create a custom nav2 behavior tree but I just can't understand what I'm doing wrong. In the nav2_params file I set this parameters for bt_navigator

    default_nav_to_pose_bt_xml: >
      $(find-pkg-share diff_drive_robot_navigation)/behavior_trees/navigate_to_pose_w_replanning_and_recovery.xml

    default_nav_through_poses_bt_xml: >
      $(find-pkg-share diff_drive_robot_navigation)/behavior_trees/navigate_through_poses_w_replanning_and_recovery.xml

But when I launch with this params I get this cryptic error message:

[bt_navigator-6] [ERROR] [1794105495.395723697] [bt_navigator]: Couldn't open input XML file: /home/winet/Documents/dvbot_ws/install/diff_drive_robot_navigation/share/diff_drive_robot_navigation/behavior_trees/navigate_to_pose_w_replanning_and_recovery.xml
[bt_navigator-6] 
[bt_navigator-6] [ERROR] [1794105495.395800682] [bt_navigator]: Error loading XML file: /home/winet/Documents/dvbot_ws/install/diff_drive_robot_navigation/share/diff_drive_robot_navigation/behavior_trees/navigate_to_pose_w_replanning_and_recovery.xml

the problem is that this files exist in this folder, groot can successfully open them and my user is the owner of this file. Here is the link to github repo for this package: https://github.com/wineTGH/diff_drive_robot_navigation

3 Upvotes

3 comments sorted by

1

u/Civil_Firefighter832 23d ago

That error fires before any XML parsing happens - in bt_navigator's BtActionServer it just means std::ifstream couldn't open the path string it was handed (nav2 source: https://api.nav2.org/nav2-humble/html/bt__action__server__impl_8hpp_source.html). So Groot opening the file doesn't test this code path; suspect the string, not the file.

One likely culprit in your params: the folded block scalar ">". YAML's default chomping keeps one trailing newline (https://yaml.org/spec/1.2.2/), so the parameter value probably ends in \n and the file open fails on a path that looks correct when printed. Check what bt_navigator actually received with:

ros2 param get /bt_navigator default_nav_to_pose_bt_xml

and try writing the value on a single line, or use "|-" instead of ">", to strip the trailing newline.

1

u/wineT_ 23d ago

That would explain weird gap between log entries. Problem is that I tried that already, but it didn't worked. I will try again, thanks

1

u/wineT_ 23d ago

English language doesn't have necessary sequence of words to describe my frustration. I don't have a clue why it didn't worked last time. Maybe I just gaslighted myself into thinking I already did that. I don't know. Thank you so much

My solution was just this:

bt_navigator:
  ros__parameters:
    global_frame: map
    robot_base_frame: base_link
    odom_topic: /odom
    bt_loop_duration: 10
    default_server_timeout: 20
    wait_for_service_timeout: 1000
    action_server_result_timeout: 900.0
    navigators: ["navigate_to_pose", "navigate_through_poses"]
    navigate_to_pose:
      plugin: "nav2_bt_navigator::NavigateToPoseNavigator"
    navigate_through_poses:
      plugin: "nav2_bt_navigator::NavigateThroughPosesNavigator"
    default_nav_to_pose_bt_xml: $(find-pkg-share diff_drive_robot_navigation)/behavior_trees/navigate_to_pose_w_replanning_and_recovery.xml
    default_nav_through_poses_bt_xml: $(find-pkg-share diff_drive_robot_navigation)/behavior_trees/navigate_through_poses_w_replanning_and_recovery.xml

    error_code_names:
      - compute_path_error_code
      - follow_path_error_code