mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-22 03:23:37 +08:00
refactor vehicle_status_flags: rename to failsafe_flags
This commit is contained in:
@@ -31,20 +31,20 @@
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Extract information from status msg file
|
||||
set(status_msg_file ${PX4_SOURCE_DIR}/msg/vehicle_status_flags.msg)
|
||||
# Extract information from failsafe msg file
|
||||
set(failsafe_flags_msg_file ${PX4_SOURCE_DIR}/msg/failsafe_flags.msg)
|
||||
set(generated_uorb_struct_field_mapping_header ${PX4_BINARY_DIR}/generated_uorb_struct_field_mapping.h)
|
||||
set(html_template_file ${CMAKE_CURRENT_SOURCE_DIR}/emscripten_template.html)
|
||||
set(html_output_file ${PX4_BINARY_DIR}/failsafe_html_template.html)
|
||||
add_custom_command(OUTPUT ${generated_uorb_struct_field_mapping_header} ${html_output_file}
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/parse_flags_from_msg.py
|
||||
${status_msg_file} ${generated_uorb_struct_field_mapping_header}
|
||||
${failsafe_flags_msg_file} ${generated_uorb_struct_field_mapping_header}
|
||||
${html_template_file} ${html_output_file}
|
||||
DEPENDS
|
||||
${status_msg_file}
|
||||
${failsafe_flags_msg_file}
|
||||
${html_template_file}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/parse_flags_from_msg.py
|
||||
COMMENT "Extracting info from status msg file"
|
||||
COMMENT "Extracting info from failsafe flags msg file"
|
||||
)
|
||||
add_custom_target(failsafe_uorb_struct_header DEPENDS ${generated_uorb_struct_field_mapping_header})
|
||||
|
||||
|
||||
@@ -167,7 +167,7 @@ void set_param_value_float(const std::string &name, float value)
|
||||
|
||||
int failsafe_update(bool armed, bool vtol_in_transition_mode, bool mission_finished,
|
||||
bool user_override, uint8_t user_intended_mode, uint8_t vehicle_type,
|
||||
vehicle_status_flags_s status_flags)
|
||||
failsafe_flags_s status_flags)
|
||||
{
|
||||
uint64_t time_ms = emscripten_date_now();
|
||||
FailsafeBase::State state{};
|
||||
@@ -203,7 +203,7 @@ std::string action_str(int action)
|
||||
|
||||
EMSCRIPTEN_BINDINGS(failsafe)
|
||||
{
|
||||
class_<vehicle_status_flags_s>("state")
|
||||
class_<failsafe_flags_s>("state")
|
||||
.constructor<>()
|
||||
UORB_STRUCT_FIELD_MAPPING
|
||||
;
|
||||
|
||||
@@ -324,7 +324,7 @@ FailsafeBase::Action Failsafe::fromOffboardLossActParam(int param_value, uint8_t
|
||||
}
|
||||
|
||||
void Failsafe::checkStateAndMode(const hrt_abstime &time_us, const State &state,
|
||||
const vehicle_status_flags_s &status_flags)
|
||||
const failsafe_flags_s &status_flags)
|
||||
{
|
||||
updateArmingState(time_us, state.armed, status_flags);
|
||||
|
||||
@@ -445,7 +445,7 @@ void Failsafe::checkStateAndMode(const hrt_abstime &time_us, const State &state,
|
||||
ActionOptions(mode_fallback_action).allowUserTakeover(UserTakeoverAllowed::Always));
|
||||
}
|
||||
|
||||
void Failsafe::updateArmingState(const hrt_abstime &time_us, bool armed, const vehicle_status_flags_s &status_flags)
|
||||
void Failsafe::updateArmingState(const hrt_abstime &time_us, bool armed, const failsafe_flags_s &status_flags)
|
||||
{
|
||||
if (!_was_armed && armed) {
|
||||
_armed_time = time_us;
|
||||
@@ -459,7 +459,7 @@ void Failsafe::updateArmingState(const hrt_abstime &time_us, bool armed, const v
|
||||
_was_armed = armed;
|
||||
}
|
||||
|
||||
FailsafeBase::Action Failsafe::checkModeFallback(const vehicle_status_flags_s &status_flags,
|
||||
FailsafeBase::Action Failsafe::checkModeFallback(const failsafe_flags_s &status_flags,
|
||||
uint8_t user_intended_mode) const
|
||||
{
|
||||
Action action = Action::None;
|
||||
|
||||
@@ -44,14 +44,14 @@ public:
|
||||
protected:
|
||||
|
||||
void checkStateAndMode(const hrt_abstime &time_us, const State &state,
|
||||
const vehicle_status_flags_s &status_flags) override;
|
||||
Action checkModeFallback(const vehicle_status_flags_s &status_flags, uint8_t user_intended_mode) const override;
|
||||
const failsafe_flags_s &status_flags) override;
|
||||
Action checkModeFallback(const failsafe_flags_s &status_flags, uint8_t user_intended_mode) const override;
|
||||
|
||||
uint8_t modifyUserIntendedMode(Action previous_action, Action current_action,
|
||||
uint8_t user_intended_mode) const override;
|
||||
|
||||
private:
|
||||
void updateArmingState(const hrt_abstime &time_us, bool armed, const vehicle_status_flags_s &status_flags);
|
||||
void updateArmingState(const hrt_abstime &time_us, bool armed, const failsafe_flags_s &status_flags);
|
||||
|
||||
enum class ManualControlLossExceptionBits : int32_t {
|
||||
Mission = (1 << 0),
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
protected:
|
||||
|
||||
void checkStateAndMode(const hrt_abstime &time_us, const State &state,
|
||||
const vehicle_status_flags_s &status_flags) override
|
||||
const failsafe_flags_s &status_flags) override
|
||||
{
|
||||
CHECK_FAILSAFE(status_flags, manual_control_signal_lost,
|
||||
ActionOptions(Action::RTL).clearOn(ClearCondition::OnModeChangeOrDisarm));
|
||||
@@ -65,7 +65,7 @@ protected:
|
||||
&& status_flags.fd_critical_failure, Action::Terminate);
|
||||
}
|
||||
|
||||
Action checkModeFallback(const vehicle_status_flags_s &status_flags, uint8_t user_intended_mode) const override
|
||||
Action checkModeFallback(const failsafe_flags_s &status_flags, uint8_t user_intended_mode) const override
|
||||
{
|
||||
return Action::None;
|
||||
}
|
||||
@@ -96,7 +96,7 @@ TEST_F(FailsafeTest, general)
|
||||
{
|
||||
FailsafeTester failsafe(nullptr);
|
||||
|
||||
vehicle_status_flags_s failsafe_flags{};
|
||||
failsafe_flags_s failsafe_flags{};
|
||||
FailsafeBase::State state{};
|
||||
state.armed = true;
|
||||
state.user_intended_mode = vehicle_status_s::NAVIGATION_STATE_POSCTL;
|
||||
@@ -153,7 +153,7 @@ TEST_F(FailsafeTest, takeover)
|
||||
{
|
||||
FailsafeTester failsafe(nullptr);
|
||||
|
||||
vehicle_status_flags_s failsafe_flags{};
|
||||
failsafe_flags_s failsafe_flags{};
|
||||
FailsafeBase::State state{};
|
||||
state.armed = true;
|
||||
state.user_intended_mode = vehicle_status_s::NAVIGATION_STATE_POSCTL;
|
||||
@@ -210,7 +210,7 @@ TEST_F(FailsafeTest, takeover_denied)
|
||||
{
|
||||
FailsafeTester failsafe(nullptr);
|
||||
|
||||
vehicle_status_flags_s failsafe_flags{};
|
||||
failsafe_flags_s failsafe_flags{};
|
||||
FailsafeBase::State state{};
|
||||
state.armed = true;
|
||||
state.user_intended_mode = vehicle_status_s::NAVIGATION_STATE_POSCTL;
|
||||
|
||||
@@ -52,7 +52,7 @@ FailsafeBase::FailsafeBase(ModuleParams *parent) : ModuleParams(parent)
|
||||
|
||||
uint8_t FailsafeBase::update(const hrt_abstime &time_us, const State &state, bool user_intended_mode_updated,
|
||||
bool rc_sticks_takeover_request,
|
||||
const vehicle_status_flags_s &status_flags)
|
||||
const failsafe_flags_s &status_flags)
|
||||
{
|
||||
if (_last_update == 0) {
|
||||
_last_update = time_us;
|
||||
@@ -390,7 +390,7 @@ void FailsafeBase::removeNonActivatedActions()
|
||||
}
|
||||
|
||||
|
||||
void FailsafeBase::getSelectedAction(const State &state, const vehicle_status_flags_s &status_flags,
|
||||
void FailsafeBase::getSelectedAction(const State &state, const failsafe_flags_s &status_flags,
|
||||
bool user_intended_mode_updated,
|
||||
bool rc_sticks_takeover_request,
|
||||
SelectedActionState &returned_state) const
|
||||
@@ -566,7 +566,7 @@ bool FailsafeBase::actionAllowsUserTakeover(Action action) const
|
||||
}
|
||||
|
||||
void FailsafeBase::clearDelayIfNeeded(const State &state,
|
||||
const vehicle_status_flags_s &status_flags)
|
||||
const failsafe_flags_s &status_flags)
|
||||
{
|
||||
// Clear delay if one of the following is true:
|
||||
// - Already in a failsafe
|
||||
@@ -611,7 +611,7 @@ uint8_t FailsafeBase::modeFromAction(const Action &action, uint8_t user_intended
|
||||
return user_intended_mode;
|
||||
}
|
||||
|
||||
bool FailsafeBase::modeCanRun(const vehicle_status_flags_s &status_flags, uint8_t mode)
|
||||
bool FailsafeBase::modeCanRun(const failsafe_flags_s &status_flags, uint8_t mode)
|
||||
{
|
||||
uint32_t mode_mask = 1u << mode;
|
||||
return
|
||||
|
||||
@@ -33,14 +33,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <uORB/topics/vehicle_status_flags.h>
|
||||
#include <uORB/topics/failsafe_flags.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <px4_platform_common/module_params.h>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#define CHECK_FAILSAFE(status_flags, flag_name, options) \
|
||||
checkFailsafe((int)offsetof(vehicle_status_flags_s, flag_name), lastStatusFlags().flag_name, status_flags.flag_name, options)
|
||||
checkFailsafe((int)offsetof(failsafe_flags_s, flag_name), lastStatusFlags().flag_name, status_flags.flag_name, options)
|
||||
|
||||
class FailsafeBase: public ModuleParams
|
||||
{
|
||||
@@ -139,7 +139,7 @@ public:
|
||||
*/
|
||||
uint8_t update(const hrt_abstime &time_us, const State &state, bool user_intended_mode_updated,
|
||||
bool rc_sticks_takeover_request,
|
||||
const vehicle_status_flags_s &status_flags);
|
||||
const failsafe_flags_s &status_flags);
|
||||
|
||||
bool inFailsafe() const { return _selected_action != Action::None; }
|
||||
|
||||
@@ -185,21 +185,21 @@ protected:
|
||||
};
|
||||
|
||||
virtual void checkStateAndMode(const hrt_abstime &time_us, const State &state,
|
||||
const vehicle_status_flags_s &status_flags) = 0;
|
||||
virtual Action checkModeFallback(const vehicle_status_flags_s &status_flags, uint8_t user_intended_mode) const = 0;
|
||||
const failsafe_flags_s &status_flags) = 0;
|
||||
virtual Action checkModeFallback(const failsafe_flags_s &status_flags, uint8_t user_intended_mode) const = 0;
|
||||
|
||||
const vehicle_status_flags_s &lastStatusFlags() const { return _last_status_flags; }
|
||||
const failsafe_flags_s &lastStatusFlags() const { return _last_status_flags; }
|
||||
|
||||
bool checkFailsafe(int caller_id, bool last_state_failure, bool cur_state_failure, const ActionOptions &options);
|
||||
|
||||
virtual void getSelectedAction(const State &state, const vehicle_status_flags_s &status_flags,
|
||||
virtual void getSelectedAction(const State &state, const failsafe_flags_s &status_flags,
|
||||
bool user_intended_mode_updated,
|
||||
bool rc_sticks_takeover_request,
|
||||
SelectedActionState &returned_state) const;
|
||||
|
||||
int genCallerId() { return ++_next_caller_id; }
|
||||
|
||||
static bool modeCanRun(const vehicle_status_flags_s &status_flags, uint8_t mode);
|
||||
static bool modeCanRun(const failsafe_flags_s &status_flags, uint8_t mode);
|
||||
|
||||
/**
|
||||
* Allows to modify the user intended mode. Use only in limited cases.
|
||||
@@ -228,7 +228,7 @@ private:
|
||||
void updateDelay(const hrt_abstime &elapsed_us);
|
||||
void notifyUser(uint8_t user_intended_mode, Action action, Action delayed_action, Cause cause);
|
||||
|
||||
void clearDelayIfNeeded(const State &state, const vehicle_status_flags_s &status_flags);
|
||||
void clearDelayIfNeeded(const State &state, const failsafe_flags_s &status_flags);
|
||||
|
||||
bool actionAllowsUserTakeover(Action action) const;
|
||||
|
||||
@@ -240,7 +240,7 @@ private:
|
||||
hrt_abstime _last_update{};
|
||||
bool _last_armed{false};
|
||||
uint8_t _last_user_intended_mode{0};
|
||||
vehicle_status_flags_s _last_status_flags{};
|
||||
failsafe_flags_s _last_status_flags{};
|
||||
Action _selected_action{Action::None};
|
||||
bool _user_takeover_active{false};
|
||||
bool _notification_required{false};
|
||||
@@ -248,7 +248,7 @@ private:
|
||||
hrt_abstime _current_start_delay{0}; ///< _current_delay is set to this value when starting the delay
|
||||
hrt_abstime _current_delay{0}; ///< If > 0, stay in Hold, and take action once delay reaches 0
|
||||
|
||||
int _next_caller_id{sizeof(vehicle_status_flags_s) + 1};
|
||||
int _next_caller_id{sizeof(failsafe_flags_s) + 1};
|
||||
bool _duplicate_reported_once{false};
|
||||
|
||||
orb_advert_t _mavlink_log_pub{nullptr};
|
||||
|
||||
@@ -12,7 +12,7 @@ import re
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description='Extract fields from .msg files')
|
||||
parser.add_argument('msg_file', help='vehicle_status_flags.msg file')
|
||||
parser.add_argument('msg_file', help='failsafe_flags.msg file')
|
||||
parser.add_argument('header_file', help='generated_uorb_struct_field_mapping.h')
|
||||
parser.add_argument('html_template', help='HTML template input file')
|
||||
parser.add_argument('html_output', help='HTML output file')
|
||||
|
||||
Reference in New Issue
Block a user