项目场景:
程序如下:
<!-- 需要启动多个乌龟GUI节点 -->
<launch>
<node pkg="turtlesim" type="turtlesim_node" name="turtlesim" />
<!-- 名称重映射 -->
<node pkg="turtlesim" type="turtlesim_node" name="t1" />
<!-- 命名空间 -->
<node pkg="turtlesim" type="turtlesim_node" name="turtlesim" ns="ergouzi" />
<!-- 命名空间+名称重映射 -->
<node pkg="turtlesim" type="turtlesim_node" name="t2" ns="maolvzi" />
</launch>
在学习【奥特学园】ROS机器人入门课程《ROS理论与实践》零基础教程P162 节点名称重名_方式2 _launch文件时运行出错
问题描述:运行roslaunch rename01_node start_turtle.launch报错
ERROR: cannot launch node of type [turtlesim/turtlesim_node]: Cannot locate node of type [turtlesim_node] in package [turtlesim]. Make sure file exists in package path and permission is set to executable (chmod +x)
ERROR: cannot launch node of type [turtlesim/turtlesim_node]: Cannot locate node of type [turtlesim_node] in package [turtlesim]. Make sure file exists in package path and permission is set to executable (chmod +x)
ERROR: cannot launch node of type [turtlesim/turtlesim_node]: Cannot locate node of type [turtlesim_node] in package [turtlesim]. Make sure file exists in package path and permission is set to executable (chmod +x)
ERROR: cannot launch node of type [turtlesim/turtlesim_node]: Cannot locate node of type [turtlesim_node] in package [turtlesim]. Make sure file exists in package path and permission is set to executable (chmod +x)
我又运行了之前的roslaunch plumbing_test start_turtle.launch文件,还是报错!
ERROR: cannot launch node of type [turtlesim/turtlesim_node]: Cannot locate node of type [turtlesim_node] in package [turtlesim]. Make sure file exists in package path and permission is set to executable (chmod +x)
ERROR: cannot launch node of type [turtlesim/turtle_teleop_key]: Cannot locate node of type [turtle_teleop_key] in package [turtlesim]. Make sure file exists in package path and permission is set to executable (chmod +x)
我退出,重启电脑等,又启动roscore, rosrun turtlesim turtlesim_node,还是报错
[rosrun] Couldn't find executable named turtlesim_node below /opt/ros/noetic/share/turtlesim
原因分析:
1.我检查了代码没问题,配置环境没问题;
2.运行之前的roslaunch plumbing_test start_turtle.launch出问题了;
3.关机重启单独运行乌龟控制节点rosrun turtlesim turtlesim_node也报错
4.运行键盘控制节点rosrun turtlesim ,用tab只能自动补齐hello_ws2,明显是上一节课的重名的功能包turtlesim造成的
5.最后,查看ROS环境环境变量echo $ROS_PACKAGE_PATH,发现在 ROS PACKAGE PATH 中只包含两个工作空间(应该又3个,原本4个我注释掉了一个)
解决方案:删除自定义工作空间的 build 与 devel 目录
分析到这里,我想到了上一节课提到的BUG:
BUG 说明:
当在 .bashrc 文件中 source 多个工作空间后,可能出现的情况,在 ROS PACKAGE PATH 中只包含两个工作空间,可以删除自定义工作空间的 build 与 devel 目录,重新 catkin_make,然后重新载入 .bashrc 文件,问题解决。
然后删掉了工作空间的 build 与 devel 文件夹,重新编译后就正常了。(我把上节课demo03_ws下的turtlesim功能包也删掉了,demo01也打包成压缩包了,然后删掉了demo01_ws,以免又其他影响)
运行 roslaunch plumbing_test start_turtle.launch正常
运行roslaunch rename01_node start_turtle.launch正常