Files
Main/99 Work/0 OneSec/OneSecNotes/10 Projects/PX4/Custom uORB Message.md
2024-12-02 15:11:30 +01:00

43 lines
3.2 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
uORB message are the equivalent of [[ROS2]] messages in the PX4 messaging system. uORB does the same job as the ROS2 middleware system by sharing messages in a public and subscribe system across different modules. A good overview on how uORB works and how to customize it look at the dev-series on [this blog](https://px4.io/px4-uorb-explained-part-1/).
In order to add a custom uORB message that can be used to share information between modules and allow to log data we need to do the following steps:
- add the message definition to `PX4-Autopilot/msg/custom_msg.msg`
- add the timestamp field in the first line, since it is mandatory:
`uint64 timestamp`
- add the message file path to `PX4-Autopilot/msg/CMakeLists.txt` in order to compile the message.
If the message should be used in several independent topics we can add the following line to the message definition:
`# TOPICS topic_name_1 topic_name_2 topic_name_3`
# ROS2 Compatibility
Starting from PX4 v1.14 ROS2 compatibility is native (see [this release article](https://px4.io/px4-autopilot-release-v1-14-what-you-need-to-know)).
In order to use the new uORB message with the ROS2 system on the companion computer you need to enable it on the bridge. In order to do this there are 4 steps required as explained in [this thread](https://github.com/PX4/px4_msgs/issues/7):
1. create the uORB `.msg` file under `PX4-Autopilot/msg/`
2. Generate the ROS `.msg` using the `uorb_to_ros_msgs.py` script and copy it to `px4_msgs` under you colcon/ament workspace
3. Do the changes on both `yaml` files in `PX4-Autopilot/msg/tools` and `px4_ros_com/templates` as you did above
4. Build your colcon/ament workspace with both updated `px4_ros_com` and `px4_msgs`
## Bridge Message Yaml File
The `.yaml` file is located in two locations: under `PX4-Autopilot/msg/tools/` and in `px4_ros_com/templates/` and it needs to be the correct version in the two locations in order for the bridge to work seamlessly. Below you can find a part of such a file ([px4_ros_com](https://github.com/PX4/px4_ros_com/blob/release/1.13/templates/urtps_bridge_topics.yaml) version):
```yaml
- msg: TelemetryStatus #9
receive: true
- msg: Timesync #10
receive: true
send: true
- msg: TrajectoryWaypoint #11
send: true
- msg: VehicleCommand #12
receive: true
- msg: VehicleControlMode #13
send: true
- msg: VehicleLocalPositionSetpoint #14
receive: true
- base: VehicleLocalPositionSetpoint #15
msg: TrajectorySetpoint
receive: true
```
The option `receive: true` means that the bridge shares the messages from the companion computer to the PX4-flight controller, whereas the option `send: true` means that the PX4-flight controller sends the messages to the companion computer. If a two-way communication is desired you can add both options, just like in the example above (`Timesync`).
The PX4-Autopilot version uses the uORB message names (lowercase and underscore), whereas the px4_ros_com version uses the default ROS2 standard for the message definition (CamelCase).
It is **extremely** important that the yaml file definition of those messages matches, else the bridge won't work properly. Specifically, the order of the messages as well. Because in the background, the messages are shared over their id (indicated as a comment in the excerpt above).