|
AutoAPMS
Streamlining behaviors in ROS 2
|
Handles the registration of a PX4 mode with the FMU and announces its dynamically assigned nav_state. More...
#include <auto_apms_px4/mode_registration.hpp>
Public Member Functions | |
| ModeRegistrationHandler (rclcpp::Node::SharedPtr node_ptr) | |
| Constructor. | |
| ~ModeRegistrationHandler () | |
| Stops announcing the mode (see stopModeAnnouncement()) if it was ever announced. | |
| void | registerMode (px4_ros2::ModeBase &mode, const std::string &mode_name) |
Wait for the FMU, register mode with it and announce the mode's assigned nav_state. | |
| void | registerMode (px4_ros2::ModeExecutorBase &executor, const std::string &mode_name) |
Wait for the FMU and register executor (together with its owned mode). | |
| void | stopModeAnnouncement () |
| Stop announcing the mode registered with registerMode(). | |
Static Public Attributes | |
| static constexpr auto | TOPIC_NAME = "registered_modes" |
| Shared topic (relative to the node namespace) on which registered modes are announced. | |
Handles the registration of a PX4 mode with the FMU and announces its dynamically assigned nav_state.
Designed for composition: any class that owns a px4_ros2::ModeBase instance can add a ModeRegistrationHandler member and call registerMode() to execute the common registration sequence (wait for the FMU, register the mode, announce the name-to-nav_state mapping).
PX4 assigns the nav_state of a (custom/external) mode dynamically during registration, so the mapping from a mode's name to its nav_state is only known at runtime and is not otherwise exposed on a topic that arbitrary subscribers can read. This handler closes that gap: after successful registration it publishes an auto_apms_px4_interfaces::msg::RegisteredMode on the shared registered_modes topic, so behaviors can discover the mode (e.g. through the GetModeNavState behavior tree node). The announcement uses a transient-local (latched) QoS so late-joining subscribers immediately receive it, and it is additionally re-published periodically. The periodic re-announcement acts as an availability heartbeat and, because several mode components typically publish to the same topic, ensures a behavior reliably observes every mode's mapping regardless of its tick rate.
Definition at line 47 of file mode_registration.hpp.
|
explicit |
Constructor.
| node_ptr | ROS 2 node used to communicate with the FMU and announce the registered mode. |
Definition at line 25 of file mode_registration.cpp.
Stops announcing the mode (see stopModeAnnouncement()) if it was ever announced.
Definition at line 27 of file mode_registration.cpp.
| void registerMode | ( | px4_ros2::ModeBase & | mode, |
| const std::string & | mode_name ) |
Wait for the FMU, register mode with it and announce the mode's assigned nav_state.
After successful registration the mode's dynamically assigned nav_state (px4_ros2::ModeBase::id) is announced on the shared registered_modes topic (latched and periodically re-announced).
| mode | The mode instance to register. Must outlive this handler or be unregistered before its destruction. |
| mode_name | Name under which the mode is announced. |
| std::runtime_error | if the FMU is not available or registration fails. |
Definition at line 34 of file mode_registration.cpp.
| void registerMode | ( | px4_ros2::ModeExecutorBase & | executor, |
| const std::string & | mode_name ) |
Wait for the FMU and register executor (together with its owned mode).
Mode executors are registered through px4_ros2::ModeExecutorBase::doRegister, which registers the executor and its owned mode in one step. Unlike registerMode(px4_ros2::ModeBase &, const std::string &), the owned mode is not announced on the registered_modes topic: a mode executor cannot be put in charge by another mode executor, and is intended as a mechanism to trigger automation from PX4 itself (RC switch, GCS), not as a target for native ROS 2 orchestration. From ROS 2, prefer registering and switching plain modes directly.
| executor | The mode executor to register. Must outlive this handler. |
| mode_name | Name of the executor's owned mode, used for logging only. |
| std::runtime_error | if the FMU is not available or registration fails. |
Definition at line 49 of file mode_registration.cpp.
| void stopModeAnnouncement | ( | ) |
Stop announcing the mode registered with registerMode().
Retracts the latched announcement and stops the heartbeat, so behaviors no longer discover the mode. The FMU itself only unregisters the mode when the px4_ros2::ModeBase instance is destroyed, which remains the responsibility of the owning class (px4_ros2 exposes no separate unregistration call).
Called automatically from the destructor, so an explicit call is only needed to stop the announcement before this handler itself is destroyed (e.g. to retract it while the mode stays registered).
Definition at line 92 of file mode_registration.cpp.
|
staticconstexpr |
Shared topic (relative to the node namespace) on which registered modes are announced.
Definition at line 51 of file mode_registration.hpp.