Add headerinstructions

This commit is contained in:
winterhalderp 2021-07-07 12:28:07 +02:00
parent 36dd783f61
commit fda583ad18
1 changed files with 69 additions and 0 deletions

69
Header_Error.md Normal file
View File

@ -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
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>rosidl_default_generators</buildtool_depend>
```
* Add _build_depend_:
```xml
<build_depend>builtin_interfaces</build_depend>
<build_depend>std_msgs</build_depend>
```
* Add _exec_depend_:
```xml
<exec_depend>rosidl_default_runtime</exec_depend>
<exec_depend>builtin_interfaces</exec_depend>
<exec_depend>std_msgs</exec_depend>
```
## 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 ~/<path_to_ws>`
* Run build: `colcon build`
## Test and Verify
* Run publisher: `ros2 topic pub /chatter <pkg_name>/msg/<custom_msg_file>`
* 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/)