From b7dfd9ae61409319c3214e08aa6e529845d4a2e2 Mon Sep 17 00:00:00 2001 From: GuillaumeLaine Date: Wed, 5 Feb 2025 18:35:47 +0100 Subject: [PATCH] update readme, revert disabling message compat --- README.md | 28 +++++++++++++++++-- .../include/px4_ros2/components/mode.hpp | 7 ++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5782a820..fbd3343d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # PX4 ROS 2 Interface Library Library to interface with PX4 from a companion computer using ROS 2. -It provides some tooling to used to write external modes that are dynamically registered with PX4 and behave the same way as internal ones. +It provides some tooling used to write external modes that are dynamically registered with PX4 and behave the same way as internal ones. A mode can send different types of setpoints, ranging from high-level navigation tasks all the way down to direct actuator controls. Documentation: @@ -10,7 +10,12 @@ Documentation: ## Compatibility with PX4 The library interacts with PX4 by using its uORB messages, and thus requires a matching set of message definitions on the ROS 2 side. -Compatibility is only guaranteed if using latest `main` on the PX4 and px4_ros2/px4_msgs side. This might change in the future. +To ensure compatibility, you must either: + +1. Use latest `main` on the PX4 and px4_ros2/px4_msgs sides, which should define matching messages +1. (Experimental) Run the PX4 [message translation node](https://github.com/PX4/PX4-Autopilot/tree/message_versioning_and_translation/msg/translation_node), which dynamically monitors and translates PX4 messages when different message version are used within the same ROS 2 domain + +### Option 1: Match Messages The library checks for message compatibility on startup when registering a mode. `ALL_PX4_ROS2_MESSAGES` defines the set of checked messages. If you use other messages, you can check them using: @@ -26,6 +31,25 @@ To manually verify that two local versions of PX4 and px4_msgs have matching mes ./scripts/check-message-compatibility.py -v path/to/px4_msgs/ path/to/PX4-Autopilot/ ``` +### Option 2: Translate Messages + +If you intend to run the message translation node to use mismatching message versions in PX4 and px4_ros2/px4_msgs, then you must manually disable the message compatibility check that runs when registering a mode. +This can be done the following way: + +```c++ +class CustomMode : public px4_ros2::ModeBase +{ +public: + CustomMode(rclcpp::Node & node) + : ModeBase(node, "node_name") + { + setSkipMessageCompatibilityCheck(); // Disables compatibility check + ... + } + ... +}; +``` + ## Examples There are code examples under [examples/cpp/modes](examples/cpp/modes). diff --git a/px4_ros2_cpp/include/px4_ros2/components/mode.hpp b/px4_ros2_cpp/include/px4_ros2/components/mode.hpp index 5177bd94..6f6ca419 100644 --- a/px4_ros2_cpp/include/px4_ros2/components/mode.hpp +++ b/px4_ros2_cpp/include/px4_ros2/components/mode.hpp @@ -162,10 +162,7 @@ class ModeBase : public Context RequirementFlags & modeRequirements() {return _health_and_arming_checks.modeRequirements();} protected: - void setSkipMessageCompatibilityCheck(bool skip = true) - { - _skip_message_compatibility_check = skip; - } + void setSkipMessageCompatibilityCheck() {_skip_message_compatibility_check = true;} void overrideRegistration(const std::shared_ptr & registration); private: @@ -194,7 +191,7 @@ class ModeBase : public Context std::shared_ptr _registration; const Settings _settings; - bool _skip_message_compatibility_check{true}; + bool _skip_message_compatibility_check{false}; HealthAndArmingChecks _health_and_arming_checks;