8 #include <rclcpp/rclcpp.hpp>
9 #include <px4_ros2/components/mode.hpp>
10 #include <px4_ros2/components/wait_for_fmu.hpp>
31 template<
typename ModeT>
35 std::is_base_of<ModeBase, ModeT>::value,
36 "Template type ModeT must be derived from px4_ros2::ModeBase");
39 explicit NodeWithMode(std::string node_name,
bool enable_debug_output =
false)
42 if (enable_debug_output) {
44 rcutils_logging_set_logger_level(get_logger().get_name(), RCUTILS_LOG_SEVERITY_DEBUG);
46 if (ret != RCUTILS_RET_OK) {
47 RCLCPP_ERROR(get_logger(),
"Error setting severity: %s", rcutils_get_error_string().str);
48 rcutils_reset_error();
52 _mode = std::make_unique<ModeT>(*
this);
54 if (!_mode->doRegister()) {
55 throw std::runtime_error(
"Registration failed");
59 ModeT & getMode()
const
65 std::unique_ptr<ModeT> _mode;
86 template<
typename ModeExecutorT,
typename ModeT>
90 std::is_base_of<ModeExecutorBase, ModeExecutorT>::value,
91 "Template type ModeExecutorT must be derived from px4_ros2::ModeExecutorBase");
93 std::is_base_of<ModeBase, ModeT>::value,
94 "Template type ModeT must be derived from px4_ros2::ModeBase");
100 if (enable_debug_output) {
102 rcutils_logging_set_logger_level(get_logger().get_name(), RCUTILS_LOG_SEVERITY_DEBUG);
104 if (ret != RCUTILS_RET_OK) {
105 RCLCPP_ERROR(get_logger(),
"Error setting severity: %s", rcutils_get_error_string().str);
106 rcutils_reset_error();
110 _mode = std::make_unique<ModeT>(*
this);
111 _mode_executor = std::make_unique<ModeExecutorT>(*
this, *_mode);
113 if (!_mode_executor->doRegister()) {
114 throw std::runtime_error(
"Registration failed");
118 ModeT & getMode()
const
124 std::unique_ptr<ModeExecutorT> _mode_executor;
125 std::unique_ptr<ModeT> _mode;
A ROS2 node which instantiates a mode executor and its owned mode, and handles their registration wit...
Definition: node_with_mode.hpp:88
A ROS2 node which instantiates a control mode and handles its registration with PX4.
Definition: node_with_mode.hpp:33