自定义消息
在消息功能包下创建msg文件夹,再创建.msg文件,并写入自定义类型;
修改Cmakeist.txt:
find_package(catkin REQUIRED COMPONENTS
message_generation
roscpp
rospy
sensor_msgs
std_msgs
tf
nav_msgs
open_karto
slam_karto_ceres
)
add_message_files(FILES
Gposes.msg
)
generate_messages(DEPENDENCIES
std_msgs
nav_msgs
)
catkin_package(
INCLUDE_DIRS include
#LIBRARIES six_f #这里注释掉,解决下面的错误
CATKIN_DEPENDS roscpp rospy sensor_msgs std_msgs tf message_runtime
DEPENDS system_lib
)
修改package.xml:
<build_depend>message_generation</build_depend>
<build_export_depend>message_generation</build_export_depend>
<build_depend>nav_msgs</build_depend>
<exec_depend>nav_msgs</exec_depend>
<exec_depend>message_runtime</exec_depend>
<exec_depend>message_generation</exec_depend>
注意,nav_msgs那里应该也需要添加上std_msgs
参考:
如下错误解决办法:
错误1:Project ‘xxx’ tried to find library ‘A_package’. The library is neither a target nor built/installed properly. Did you compile project ‘A_package’? Did you find_package() it before the subdirectory containing its code is included?
修改:A_package的CMakeList.txt文件:
catkin_package(
INCLUDE_DIRS include
#LIBRARIES A_package (这里要注释掉)
CATKIN_DEPENDS roscpp rospy std_msgs message_runtime
DEPENDS system_lib )
原因分析:
A包输出了并不存在的库(LIBRARIES A),导致B包find_package()在寻找A库的时候无法找到。
当去掉LIBRARIES A的时候,find_package()将不会寻找LIBRARIES A,因此CMAKE配置通过。
其他包调用:
package.xml:
<build_depend>six_f</build_depend>
<build_export_depend>six_f</build_export_depend>
<exec_depend>six_f</exec_depend>
six_f:是自己的消息功能包
如需要:
还可以添加上,自定义消息里面依赖的基础消息,如six_f,换成nav_msgs
在需要调用消息的功能包下,CmakeList.txt添加自定义的pkg在find_package
中
并添加:
add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
${PROJECT_NAME}_node改为自己的可执行文件
最后,通过#include“”........即可。
查看自己定义的消息,可以使用如下命令:
rosmsg show ....