22#include "auto_apms_px4_interfaces/msg/registered_mode.hpp"
23#include "px4_ros2/components/mode.hpp"
24#include "px4_ros2/components/mode_executor.hpp"
25#include "rclcpp/rclcpp.hpp"
71 void registerMode(px4_ros2::ModeBase & mode,
const std::string & mode_name);
85 void registerMode(px4_ros2::ModeExecutorBase & executor,
const std::string & mode_name);
104 void announce(
const std::string & mode_name, uint8_t nav_state);
106 const rclcpp::Node::SharedPtr node_ptr_;
107 auto_apms_px4_interfaces::msg::RegisteredMode registered_mode_msg_;
108 rclcpp::Publisher<auto_apms_px4_interfaces::msg::RegisteredMode>::SharedPtr registered_mode_pub_;
109 rclcpp::TimerBase::SharedPtr announce_timer_;
131template <
class ModeT>
132class ModeRegistrationFactory
135 ModeRegistrationFactory(
const std::string & mode_name,
const rclcpp::NodeOptions & options);
137 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr get_node_base_interface();
140 rclcpp::Node::SharedPtr node_ptr_;
141 std::unique_ptr<ModeT> mode_ptr_;
149template <
class ModeT>
150ModeRegistrationFactory<ModeT>::ModeRegistrationFactory(
151 const std::string & mode_name,
const rclcpp::NodeOptions & options)
152: node_ptr_(std::make_shared<rclcpp::Node>(mode_name +
"_node", options)),
153 mode_ptr_(std::make_unique<ModeT>(*node_ptr_, px4_ros2::ModeBase::Settings(mode_name))),
154 registration_handler_(node_ptr_)
157 std::is_base_of<px4_ros2::ModeBase, ModeT>::value,
158 "Template argument ModeT must publicly inherit px4_ros2::ModeBase.");
160 registration_handler_.
registerMode(*mode_ptr_, mode_name);
163template <
class ModeT>
164rclcpp::node_interfaces::NodeBaseInterface::SharedPtr ModeRegistrationFactory<ModeT>::get_node_base_interface()
166 return node_ptr_->get_node_base_interface();
Handles the registration of a PX4 mode with the FMU and announces its dynamically assigned nav_state.
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.
ModeRegistrationHandler(rclcpp::Node::SharedPtr node_ptr)
Constructor.
~ModeRegistrationHandler()
Stops announcing the mode (see stopModeAnnouncement()) if it was ever announced.
static constexpr auto TOPIC_NAME
Shared topic (relative to the node namespace) on which registered modes are announced.
void stopModeAnnouncement()
Stop announcing the mode registered with registerMode().
Implementation of PX4 mode peers offered by px4_ros2_cpp enabling integration with AutoAPMS.