问题已解决,原因是环境变量AMENT_PREFIX_PATH错误,虽然没有找到这个变量为什么出错导致查找不到robot_tracker包,但我通过在lauch.json配置中手动修复该环境变量后启动正常,修改前配置为
// robot_tracker_launch_task { "name" : "ROS2_Debug: robot_tracker", "type" : "ros", "request" : "launch", "target" : "${workspaceFolder}/install/robot_tracker/share/robot_tracker/launch/debug_robot_tracker.launch.py", "preLaunchTask": "build:debug_robot_tracker", "launch": ["rviz"] },修改后配置为
// robot_tracker_launch_task { "name" : "ROS2_Debug: robot_tracker", "type" : "ros", "request" : "launch", "target" : "${workspaceFolder}/install/robot_tracker/share/robot_tracker/launch/debug_robot_tracker.launch.py", "preLaunchTask": "build:debug_robot_tracker", "launch": ["rviz"], "env":{ "AMENT_PREFIX_PATH" : "/opt/ros/humble:${workspaceFolder}/install/robot_tracker" } },@小鱼 感谢大佬