记录一下在用ROS的时的一些错误以及解决方法
1、创建自己的包package 编译时出现错误:
add_custom_target cannot create target
“realsense2_camera_generate_messages_py” because another target with the
same name already exists. The existing target is a custom target created
in source directory “/home/liubaorong/catkin_ws/src/robot_vision”. See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
/opt/ros/kinetic/share/genmsg/cmake/genmsg-extras.cmake:307 (include)
realsense2_camera/CMakeLists.txt:76 (generate_messages)
原因是在 robot_vision包的CMakeLists.txt中的findpackage 和package.xml 中的build_depend有一项不相同,改正即可。
注意:package.xml文件里 build_depend 的所有项要与CMakeLists.txt文件中的find_package 中的依赖项完全相同
2、运行节点文件时 rosrun robot_vision robot_vision 出现错误:
[rosrun] Couldn’t find executable named robot_vision below
/home/liubaorong/catkin_ws/src/robot_vision
[rosrun] Found the following, but they’re either not files,
[rosrun] or not executable:
[rosrun] /home/liubaorong/catkin_ws/src/robot_vision
[rosrun] /home/liubaorong/catkin_ws/src/robot_vision/include/robot_vision
原因:
package.xml文件中有两种格式,对应的书写模式不一样:
<run_depend>在模式1中的格式为:
<run_depend>foo</run_depend>
在模式2中的书写格式为:
<build_export_depend>foo</build_export_depend>
<exec_depend>foo</exec_depend>
这里参考博客: https://bbs.csdn.net/topics/392277718?page=1
3、节点无法订阅消息
原因: 可执行文件中订阅话题时话题名称没有写全。应完全按照rostopic list 查到的格式来写。
4、camke编译时 添加 #include<librealsense2/rs.hpp>出错
#error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support
这个文件需要编译器和库支持的ISO C++ 2011标准。必须使用-STD= C++ 11或-STD= GNU+11编译器选项来启用此支持。
#错误此文件需要编译器和库支持\
解决:
在工程主目录的CMakeLists.txt中添加如下,可以编译成功:
SET( CMAKE_CXX_FLAGS "-std=c++11 -O3")
5、在自定义消息时,在可执行文件(节点文件)中include消息的.h文件,cmake时出错:
fatal error: robot_vision/vision_msg.h: 没有那个文件或目录
但是通过rosmsg show可以看见详细信息无误
原因:在CmakeList文件中没有添加
generate_messages(
DEPENDENCIES
std_msgs
)