如何修复 ROS2 Package '...' not found: package '...' not found, searching ...
问题
你想从本地目录而不是全局 ROS2 搜索目录加载包。
假设你想加载 my_package:
fix_ros2_package_not_found.sh
$ ls
my_package你使用
ros2_launch_with_prefix.sh
AMENT_PREFIX_PATH=$(pwd) ros2 launch my_package my.launch.py将前缀路径设置为当前目录,期望 ROS2 在当前目录中找到 ./my_package。
但是,你看到如下错误
ros2_package_not_found_error.txt
Package 'my_package' not found: "package 'my_package' not found, searching: ['/home/user/']"解决方案
当你将 AMENT_PREFIX_PATH 设置为例如 /home/user 时,ROS2 不会在 /home/user 中搜索 ./my_package。
相反,它会在 /home/user/share/ament_index/resource_index/packages 中查找名为 my_package 的(可能为空的)文件。
换句话说,ROS2 期望索引在特定的目录结构中:
ament_index_tree.txt
/home/user/
└── share
└── ament_index
└── resource_index
└── packages
└── my_package使用 ROS2 包的官方方式
你必须构建 my_package 并使用自动生成的 setup 脚本来设置正确的环境变量!ROS2 官方不支持像这样自定义 AMENT_PREFIX_PATH 的做法。
colcon_build.sh
cd my_package
colcon build之后,使用包名加载包:
source_install_setup.sh
source install/local_setup.sh这将设置
colcon_prefix_path.sh
COLCON_PREFIX_PATH=/home/user/my_package/install其中包含正确的 ament 索引目录结构。
变通方法
如果你不想构建包,可以在预期目录中创建指向包的符号链接:
create_ament_index.sh
mkdir -p share/ament_index/resource_index/packages
touch share/ament_index/resource_index/packages/my_package这将使 ROS2 找到该包。但是,正确的 share 目录仍然不会存在,因此不推荐这样做。将来,我可能会添加有关如何解决此问题的信息。
Check out similar posts by category:
ROS
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow