diff --git a/Header_Error.md b/Header_Error.md new file mode 100644 index 0000000..754fcd2 --- /dev/null +++ b/Header_Error.md @@ -0,0 +1,69 @@ +# Header Message Errors +When wanting to introduce [headers](http://docs.ros.org/en/melodic/api/std_msgs/html/msg/Header.html) do the following steps. + +You should have a CMake package created already (as only Cmake packages can implement custom msgs as of now). + +## Custom Message File +* Create a *.mgs file inside the `msg/` directory and start the file name with a capital letter +* Add the line `std_msgs/Header header` in order to use the header message, this msg type is from standard messages ([std_msgs](http://docs.ros.org/en/melodic/api/std_msgs/html/index-msg.html)) +* Only introduce absolutely necessary comments in *.msg file (eg. #Header) in order to minimize possible errors. + +## Configure package.xml +* Add _buildtool_depend_: +```xml +ament_cmake +rosidl_default_generators +``` +* Add _build_depend_: +```xml +builtin_interfaces +std_msgs +``` +* Add _exec_depend_: +```xml +rosidl_default_runtime +builtin_interfaces +std_msgs +``` + +## Configure CMakeLists.txt +* Add required packages: +```cmake +find_package(ament_cmake REQUIRED) +find_package(rosidl_default_generators REQUIRED) +find_package(builtin_interfaces REQUIRED) +find_package(std_msgs REQUIRED) +``` +* Create msg files set (exchange with your own `msg/*.msg` files): +```cmake +set(msg_files + "msg/IMUInfo.msg" + "msg/Extrinsics.msg" +) +``` +* Load set into _rosidl_generate_interfaces_ and add the dependency for std_msgs: +```cmake +rosidl_generate_interfaces(${PROJECT_NAME} + ${msg_files} + DEPENDENCIES builtin_interfaces std_msgs +) +``` + +## Build Colcon Workspace +* Move to root of workspace: `cd ~/` +* Run build: `colcon build` + +## Test and Verify +* Run publisher: `ros2 topic pub /chatter /msg/` +* Run subscriber: `ros2 topic echo /chatter` + +You should see your custom msg being published and received, including the header. + +## Source +[Link to the problem's solution at ros.org forum](https://answers.ros.org/question/326008/ros2-run-symbol-not-found-on-custom-msg/) +Example Files: +* ROS2 Realsense: + * [Custom msg file](https://github.com/IntelRealSense/realsense-ros/blob/eloquent/realsense2_camera_msgs/msg/IMUInfo.msg) + * [CMakeLists.txt](https://github.com/IntelRealSense/realsense-ros/blob/eloquent/realsense2_camera_msgs/CMakeLists.txt) + * [package.xml](https://github.com/IntelRealSense/realsense-ros/blob/eloquent/realsense2_camera_msgs/package.xml) + * [Write timestamp](https://answers.ros.org/question/354203/timestamp-message-ros2-python/)