From 44c4b8fa8574d8eda27358eb2179c1553b633dd0 Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Tue, 7 Jun 2022 18:20:34 +0200 Subject: [PATCH] Style refactoring related to safety button --- msg/vehicle_status.msg | 4 ++-- src/modules/commander/Commander.cpp | 5 ++--- src/modules/commander/Commander.hpp | 2 +- src/modules/commander/Safety.cpp | 8 ++------ src/modules/commander/Safety.hpp | 15 ++++++--------- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/msg/vehicle_status.msg b/msg/vehicle_status.msg index 19a9171aa6..902d07a478 100644 --- a/msg/vehicle_status.msg +++ b/msg/vehicle_status.msg @@ -117,5 +117,5 @@ uint64 armed_time # Arming timestamp (microseconds) uint64 takeoff_time # Takeoff timestamp (microseconds) -bool safety_button_available # Set to true if a safety button is connected -bool safety_off # Set to true if safety is off +bool safety_button_available # Set to true if a safety button is connected +bool safety_off # Set to true if safety is off diff --git a/src/modules/commander/Commander.cpp b/src/modules/commander/Commander.cpp index d5ebe203f6..46f510a52d 100644 --- a/src/modules/commander/Commander.cpp +++ b/src/modules/commander/Commander.cpp @@ -2298,12 +2298,11 @@ Commander::run() } /* safety button */ - bool safety_updated = _safety.safetyButtonHandler(); + const bool safety_changed = _safety.safetyButtonHandler(); _vehicle_status.safety_button_available = _safety.isButtonAvailable(); _vehicle_status.safety_off = _safety.isSafetyOff(); - if (safety_updated) { - + if (safety_changed) { set_health_flags(subsystem_info_s::SUBSYSTEM_TYPE_MOTORCONTROL, _safety.isButtonAvailable(), _safety.isSafetyOff(), _safety.isButtonAvailable(), _vehicle_status); diff --git a/src/modules/commander/Commander.hpp b/src/modules/commander/Commander.hpp index 3ad01dbdeb..6c631ea66a 100644 --- a/src/modules/commander/Commander.hpp +++ b/src/modules/commander/Commander.hpp @@ -402,7 +402,7 @@ private: vehicle_status_s _vehicle_status{}; vehicle_status_flags_s _vehicle_status_flags{}; - Safety _safety{}; + Safety _safety; WorkerThread _worker_thread; diff --git a/src/modules/commander/Safety.cpp b/src/modules/commander/Safety.cpp index 49ca905a04..6cb9bc1809 100644 --- a/src/modules/commander/Safety.cpp +++ b/src/modules/commander/Safety.cpp @@ -42,9 +42,7 @@ using namespace time_literals; Safety::Safety() { - /* - * Safety can be turned off with the CBRK_IO_SAFETY parameter. - */ + // Safety can be turned off with the CBRK_IO_SAFETY parameter. _safety_disabled = circuit_breaker_enabled("CBRK_IO_SAFETY", CBRK_IO_SAFETY_KEY); } @@ -67,10 +65,8 @@ bool Safety::safetyButtonHandler() } } - bool safety_changed = _previous_safety_off != _safety_off; - + const bool safety_changed = _previous_safety_off != _safety_off; _previous_safety_off = _safety_off; - return safety_changed; } diff --git a/src/modules/commander/Safety.hpp b/src/modules/commander/Safety.hpp index 4b06d7e26d..0092903517 100644 --- a/src/modules/commander/Safety.hpp +++ b/src/modules/commander/Safety.hpp @@ -43,23 +43,20 @@ class Safety { - public: - Safety(); ~Safety() = default; bool safetyButtonHandler(); void activateSafety(); - bool isButtonAvailable() { return _button_available;} - bool isSafetyOff() { return _safety_off;} + bool isButtonAvailable() { return _button_available; } + bool isSafetyOff() { return _safety_off; } private: - uORB::Subscription _safety_button_sub{ORB_ID::safety_button}; - bool _button_available{false}; //