10#include <px4_msgs/msg/arming_check_reply.hpp>
11#include <px4_msgs/msg/arming_check_request.hpp>
12#include <px4_ros2/common/requirement_flags.hpp>
13#include <rclcpp/rclcpp.hpp>
24 : _arming_check_reply(arming_check_reply)
28 template <
typename... Args>
29 void armingCheckFailureExt(uint32_t event_id, events::Log log_level,
const char* message,
32 const uint16_t navigation_mode_groups{};
33 const uint8_t health_component_index{};
35 _arming_check_reply.can_arm_and_run =
false;
37 if (!addEvent(event_id, log_level, message, navigation_mode_groups, health_component_index,
39 printf(
"Error: too many events\n");
43 void setHealth(uint8_t health_component_index,
bool is_present,
bool warning,
bool error);
46 template <
typename... Args>
47 bool addEvent(uint32_t event_id,
const events::LogLevels& log_levels,
const char* message,
50 px4_msgs::msg::ArmingCheckReply& _arming_check_reply;
53template <
typename... Args>
54bool HealthAndArmingCheckReporter::addEvent(uint32_t event_id,
const events::LogLevels& log_levels,
55 const char* message, Args... args)
57 if (_arming_check_reply.num_events >= _arming_check_reply.events.size()) {
61 events::EventType& e = _arming_check_reply.events[_arming_check_reply.num_events];
63 (
static_cast<uint8_t
>(log_levels.internal) << 4) |
static_cast<uint8_t
>(log_levels.external);
65 static_assert(events::util::sizeofArguments(args...) <=
sizeof(e.arguments),
66 "Too many arguments");
67 events::util::fillEventArguments(
static_cast<uint8_t*
>(e.arguments.data()), args...);
68 ++_arming_check_reply.num_events;
72inline void HealthAndArmingCheckReporter::setHealth(uint8_t health_component_index,
bool is_present,
73 bool warning,
bool error)
75 _arming_check_reply.health_component_index = health_component_index;
76 _arming_check_reply.health_component_is_present = is_present;
77 _arming_check_reply.health_component_warning = warning;
78 _arming_check_reply.health_component_error = error;
84 using WatchdogTimeoutCallback = std::function<void()>;
87 const std::string& topic_namespace_prefix =
"");
100 _mode_requirements = mode_requirements;
105 void disableWatchdogTimer() { _watchdog_timer =
nullptr; }
118 void overrideRegistration(
const std::shared_ptr<Registration>& registration);
120 void watchdogTimerUpdate();
123 std::shared_ptr<Registration> _registration;
124 CheckCallback _check_callback;
125 bool _check_triggered{
true};
126 bool _first_request{
true};
128 rclcpp::Subscription<px4_msgs::msg::ArmingCheckRequest>::SharedPtr _arming_check_request_sub;
129 rclcpp::Publisher<px4_msgs::msg::ArmingCheckReply>::SharedPtr _arming_check_reply_pub;
131 RequirementFlags _mode_requirements{};
132 rclcpp::TimerBase::SharedPtr _watchdog_timer;
133 bool _shutdown_on_timeout{
true};
134 WatchdogTimeoutCallback _watchdog_timeout_callback;
Definition health_and_arming_checks.hpp:21
Definition health_and_arming_checks.hpp:81
void setWatchdogTimeoutCallback(WatchdogTimeoutCallback callback)
bool doRegister(const std::string &name)
Base class for a mode.
Definition mode.hpp:74
Base class for a mode executor.
Definition mode_executor.hpp:29
Requirement flags used by modes.
Definition requirement_flags.hpp:15