无法将ROS2自定义消息导入不同程序包C++中的Node头文件



我是用c++开发ROS2的新手,但在Python方面有经验。我为自定义消息创建了一个单独的包,其中包含CustomMessage包所需的CMakeLists。现在我已经创建了另一个ROS2C++包,并试图将消息导入一个Header文件,但ROS2没有显示这样的文件或目录。

自定义消息包的名称:map_messages

自定义消息->HDMapBin.msg

uint8 MAP_FORMAT_LANELET2=0
std_msgs/Header header
uint8 map_format
string format_version
string map_version
std_msgs/UInt8[] values

映射消息包CMAKELST

cmake_minimum_required(VERSION 3.8)
project(map_messages)
# find dependencies
find_package(ament_cmake_auto REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(std_msgs REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(geometry_msgs REQUIRED)
ament_auto_find_build_dependencies()
rosidl_generate_interfaces(${PROJECT_NAME}
"msg/HDMapBin.msg"
"msg/HDMapSegment.msg"
"msg/HDMapPrimitive.msg"
"msg/HDMapRoute.msg"
DEPENDENCIES
"std_msgs"
"geometry_msgs"
"builtin_interfaces"
ADD_LINTER_TESTS
)
ament_export_dependencies(rosidl_default_runtime)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
ament_auto_package()

现在,我将其导入到一个单独的包中,并已将所需内容放入find_package(map_messages REQUIRED)等辅助包的CMakeLists中,并将消息导入为"map_messages/msg/hd_map_bin.hpp"[根据我在ROS2WS.的构建文件夹下找到的命名约定

一旦我构建了相同的,ros2就会给我以下错误map_messages/msg/hd_map_bin.hpp: No such file or directory

有什么办法吗??

您对命名约定的猜测几乎是正确的。

如果您的包在CamelCase:"msg/HDMapBin.msg"中命名

然后,每个大写字母都将为消息生成器指示一个新词。

这意味着HDMapBin.msg->h_d_map_bin.hpp

您应该包括:

#include map_messages/msg/h_d_map_bin.hpp

当然,您应该将CMakeList.txt文件中的dependency添加到安装目标中

find_package(map_messages REQUIRED)
ament_target_dependencies(cpp_node
rclcpp
map_messages
)

最新更新