zhoudingjiang
zhoudingjiang

Reputation: 93

ROS2 `colcon build` could not generate hpp files

I followed the tutorial: https://docs.ros.org/en/foxy/Tutorials/Custom-ROS2-Interfaces.html to create custom msg and srv, and use colcon build to compile the package, however, I found there is no hpp file generated to use in other packages. For example, I have package agv_interfaces to maintain custom msg and srv. I have CMakeLists.txt as:

cmake_minimum_required(VERSION 3.5)
project(agv_interfaces)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
  "msg/AgvJoy.msg"
  "srv/JoyLimit.srv"
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # uncomment the line when a copyright and license is not present in all source files
  #set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # uncomment the line when this package is not in a git repo
  #set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()

and its package.xml is as:

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>agv_interfaces</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="[email protected]">taipan</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>
  <build_depend>rosidl_default_generators</build_depend>
  <exec_depend>rosidl_default_runtime</exec_depend>
  <member_of_group>rosidl_interface_packages</member_of_group>
  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

The command:

colcon build --packages-select agv_interfaces

is able to build this package, however, there is no *.hpp file be generated. The official tutorial does not mention this neither. Follow the tutorial, I can use command:

ros2 interface show agv_interfaces/msg/AgvJoy

to see how is my message defined, so far so good. So I tried to use this interface in other packages joystick, I have CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)
project(joystick)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 17)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(agv_interfaces REQUIRED)

include_directories(./include/)

# --------------------------------
add_executable(
  joy_node
  "src/joy.cpp"
  "src/joy-node.cpp"
)

ament_target_dependencies(
  joy_node
  rclcpp
  agv_interfaces
)

install(TARGETS joy_node
  DESTINATION lib/${PROJECT_NAME}
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()

and package.xml:

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>joystick</name>
  <version>0.0.0</version>
  <description>AGV Joystick</description>
  <maintainer email="[email protected]">ros2-agv</maintainer>
  <license>MIT</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <depend>agv_interfaces</depend>
  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>
  <member_of_group>rosidl_interface_packages</member_of_group>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

Then I use colon build, I see error:

In file included from /home/taipan/ros2-ws/src/joystick/src/joy.cpp:1:
/home/taipan/ros2-ws/src/joystick/./include/joystick/joy.h:3:10: fatal error: agv_interfaces/msg/agvjoy.hpp: No such file or directory
    3 | #include "agv_interfaces/msg/agvjoy.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/joy_node.dir/build.make:63: CMakeFiles/joy_node.dir/src/joy.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /home/taipan/ros2-ws/src/joystick/src/joy-node.cpp:1:
/home/taipan/ros2-ws/src/joystick/./include/joystick/joy.h:3:10: fatal error: agv_interfaces/msg/agvjoy.hpp: No such file or directory
    3 | #include "agv_interfaces/msg/agvjoy.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/joy_node.dir/build.make:76: CMakeFiles/joy_node.dir/src/joy-node.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/joy_node.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

Some official ROS2 document says I should use rosidl_generator_cpp instead of rosidl_default_generators, but how?

Upvotes: 1

Views: 4413

Answers (2)

Glob
Glob

Reputation: 36

Just complementing @zhoudingjang's answer, in case it helps someone, cause it took me forever.

In my case, I had a "custom_msgs/msg/RadarOdometry.msg" custom msg, but when trying to include it, I had to include it as

#include "custom_msgs/msg/radar_odometry.hpp"

Apparently, ros2 does a renaming thingy when compiling messages.

Upvotes: 2

zhoudingjiang
zhoudingjiang

Reputation: 93

#include "agv_interfaces/agv_joy.hpp" is the solution.

Upvotes: 1

Related Questions