出现问题的源博客: ROS入门(十)——两只小乌龟(乌龟跟随C++实现)
在运行 launch 文件的过程中,出现了这个报错。无法启动launch文件。
RLException: Unable to launch [turtle2-2].
If it is a script, you may be missing a '#!' declaration at the top.
The traceback for the exception was written to the log file
# 匹配异常,无法运行 launch
# 如果是一个脚本,您可能缺少一个'#!'的声明。
一、我的问题
我出现这个原因其实是因为粗心,在 launch 文件中,启动小乌龟的 type 应设置为 t1_turtle2,但我却写成了 t1_turtle2.cpp ,导致无法正常找到这个文件
# 正确启动方式
<launch>
<!-- 启动乌龟GUI节点 -->
<node pkg="turtlesim" type="turtlesim_node" name="turtle1" output="screen"/>
<!-- 生成新乌龟的节点 -->
<node pkg="tf1_turtle" type="t1_turtle2" name="turtle2" output="screen"/>
</launch>
# 错误写法,除非对应c文件的名称为 t1_turtle2.cpp.cpp
# <node pkg="tf1_turtle" type="t1_turtle2.cpp" name="turtle2" output="screen"/>
重新编译并运行。发现不再报错
二、其他方案
(1)未进行source
- 方法一:终端运行
source ./devel/setup.bash
- 方法二:永久配置
参考链接Ubuntu、VSCODE小技巧的二、2.一次性 source
(2)检查 cpp 的脚本头
看是否少写了 " # " 或导入的包有问题
(3)检查文件名
检查是否正确调用文件或运行文件【例如我的错误】。
文件名是否统一