iNav开源代码之FAILSAFE

news2025/1/11 18:34:51

iNav开源代码之FAILSAFE

  • 1. 源由
  • 2. `FAILSAFE`类别
  • 3. `FAILSAFE`配置
  • 4. `FAILSAFE`阶段&状态机
  • 5. 参考资料

1. 源由

最近因为炸机,百思不得其解。

关于炸鸡的过程,就不再展开,都是“泪”啊!想进一步了解的,请参阅前面的初步分析。

链接:iNav开源代码之严重炸机 – 危险隐患。

为了更清楚的搞清楚到底是哪里的问题,还是要从FAILSAFE的工作原理来分析,在相应FAILSAFE模式下代码逻辑是如何发生的。

先从FAILSAFE的类别,配置,阶段,以及状态机来看看是怎么个过程。

2. FAILSAFE类别

以下类别与Configurator中的Drop/Land/RTH一一对应,其中FAILSAFE_PROCEDURE_NONE是一个默认的状态,仅程序使用,GUI界面没有相关配置选项。

typedef enum {
    FAILSAFE_PROCEDURE_AUTO_LANDING = 0,
    FAILSAFE_PROCEDURE_DROP_IT,
    FAILSAFE_PROCEDURE_RTH,
    FAILSAFE_PROCEDURE_NONE
} failsafeProcedure_e;

3. FAILSAFE配置

配置参数默认在fc/settings.yaml文件中定义。在编译时,在目标板目录inav\build\src\main\target\target_name\target_name下生成settings_generated.c/h文件。

主要的配置参数如下所示:

typedef struct failsafeConfig_s {
    uint16_t failsafe_throttle_low_delay;       // Time throttle stick must have been below 'min_check' to "JustDisarm" instead of "full failsafe procedure" (TENTH_SECOND)
    uint8_t failsafe_delay;                     // Guard time for failsafe activation after signal lost. 1 step = 0.1sec - 1sec in example (10)
    uint8_t failsafe_recovery_delay;            // Time from RC link recovery to failsafe abort. 1 step = 0.1sec - 1sec in example (10)
    uint8_t failsafe_off_delay;                 // Time for Landing before motors stop in 0.1sec. 1 step = 0.1sec - 20sec in example (200)
    uint8_t failsafe_procedure;                 // selected full failsafe procedure is 0: auto-landing, 1: Drop it, 2: Return To Home (RTH)

    int16_t failsafe_fw_roll_angle;             // Settings to be applies during "LAND" procedure on a fixed-wing
    int16_t failsafe_fw_pitch_angle;
    int16_t failsafe_fw_yaw_rate;
    uint16_t failsafe_stick_motion_threshold;
    uint16_t failsafe_min_distance;             // Minimum distance required for failsafe procedure to be taken. 1 step = 1 centimeter. 0 = Regular failsafe_procedure always active (default)
    uint8_t failsafe_min_distance_procedure;    // selected minimum distance failsafe procedure is 0: auto-landing, 1: Drop it, 2: Return To Home (RTH)
    int16_t failsafe_mission_delay;             // Time delay before Failsafe triggered when WP mission in progress (s)
} failsafeConfig_t;

当前代码定义为:

  • SETTING_FAILSAFE_DELAY_DEFAULT // 0.5 sec
  • SETTING_FAILSAFE_RECOVERY_DELAY_DEFAULT, // 0.5 seconds (plus 200ms explicit delay)
  • SETTING_FAILSAFE_OFF_DELAY_DEFAULT, // 20sec
  • SETTING_FAILSAFE_THROTTLE_LOW_DELAY_DEFAULT, // 0, default throttle low delay for “just disarm” on failsafe condition
  • SETTING_FAILSAFE_PROCEDURE_DEFAULT, // 0, default full failsafe procedure
  • SETTING_FAILSAFE_FW_ROLL_ANGLE_DEFAULT, // 20 deg left
  • SETTING_FAILSAFE_FW_PITCH_ANGLE_DEFAULT, // 10 deg dive (yes, positive means dive)
  • SETTING_FAILSAFE_FW_YAW_RATE_DEFAULT, // 45 deg/s left yaw (left is negative, 8s for full turn)
  • SETTING_FAILSAFE_STICK_THRESHOLD_DEFAULT, // 50
  • SETTING_FAILSAFE_MIN_DISTANCE_DEFAULT, // 0, No minimum distance for failsafe by default
  • SETTING_FAILSAFE_MIN_DISTANCE_PROCEDURE_DEFAULT, // 1, default minimum distance failsafe procedure
  • SETTING_FAILSAFE_MISSION_DELAY_DEFAULT, // 0, Time delay before Failsafe activated during WP mission (s)

#define SETTING_FAILSAFE_DELAY_DEFAULT 5
#define SETTING_FAILSAFE_DELAY 88
#define SETTING_FAILSAFE_DELAY_MIN 0
#define SETTING_FAILSAFE_DELAY_MAX 200
#define SETTING_FAILSAFE_RECOVERY_DELAY_DEFAULT 5
#define SETTING_FAILSAFE_RECOVERY_DELAY 89
#define SETTING_FAILSAFE_RECOVERY_DELAY_MIN 0
#define SETTING_FAILSAFE_RECOVERY_DELAY_MAX 200
#define SETTING_FAILSAFE_OFF_DELAY_DEFAULT 200
#define SETTING_FAILSAFE_OFF_DELAY 90
#define SETTING_FAILSAFE_OFF_DELAY_MIN 0
#define SETTING_FAILSAFE_OFF_DELAY_MAX 200
#define SETTING_FAILSAFE_THROTTLE_LOW_DELAY_DEFAULT 0
#define SETTING_FAILSAFE_THROTTLE_LOW_DELAY 91
#define SETTING_FAILSAFE_THROTTLE_LOW_DELAY_MIN 0
#define SETTING_FAILSAFE_THROTTLE_LOW_DELAY_MAX 300
#define SETTING_FAILSAFE_PROCEDURE_DEFAULT 0
#define SETTING_FAILSAFE_PROCEDURE 92
#define SETTING_FAILSAFE_PROCEDURE_MIN 0
#define SETTING_FAILSAFE_PROCEDURE_MAX 0
#define SETTING_FAILSAFE_STICK_THRESHOLD_DEFAULT 50
#define SETTING_FAILSAFE_STICK_THRESHOLD 93
#define SETTING_FAILSAFE_STICK_THRESHOLD_MIN 0
#define SETTING_FAILSAFE_STICK_THRESHOLD_MAX 500
#define SETTING_FAILSAFE_FW_ROLL_ANGLE_DEFAULT -200
#define SETTING_FAILSAFE_FW_ROLL_ANGLE 94
#define SETTING_FAILSAFE_FW_ROLL_ANGLE_MIN -800
#define SETTING_FAILSAFE_FW_ROLL_ANGLE_MAX 800
#define SETTING_FAILSAFE_FW_PITCH_ANGLE_DEFAULT 100
#define SETTING_FAILSAFE_FW_PITCH_ANGLE 95
#define SETTING_FAILSAFE_FW_PITCH_ANGLE_MIN -800
#define SETTING_FAILSAFE_FW_PITCH_ANGLE_MAX 800
#define SETTING_FAILSAFE_FW_YAW_RATE_DEFAULT -45
#define SETTING_FAILSAFE_FW_YAW_RATE 96
#define SETTING_FAILSAFE_FW_YAW_RATE_MIN -1000
#define SETTING_FAILSAFE_FW_YAW_RATE_MAX 1000
#define SETTING_FAILSAFE_MIN_DISTANCE_DEFAULT 0
#define SETTING_FAILSAFE_MIN_DISTANCE 97
#define SETTING_FAILSAFE_MIN_DISTANCE_MIN 0
#define SETTING_FAILSAFE_MIN_DISTANCE_MAX 65000
#define SETTING_FAILSAFE_MIN_DISTANCE_PROCEDURE_DEFAULT 1
#define SETTING_FAILSAFE_MIN_DISTANCE_PROCEDURE 98
#define SETTING_FAILSAFE_MIN_DISTANCE_PROCEDURE_MIN 0
#define SETTING_FAILSAFE_MIN_DISTANCE_PROCEDURE_MAX 0
#define SETTING_FAILSAFE_MISSION_DELAY_DEFAULT 0
#define SETTING_FAILSAFE_MISSION_DELAY 99
#define SETTING_FAILSAFE_MISSION_DELAY_MIN -1
#define SETTING_FAILSAFE_MISSION_DELAY_MAX 600

static failsafeState_t failsafeState;

PG_REGISTER_WITH_RESET_TEMPLATE(failsafeConfig_t, failsafeConfig, PG_FAILSAFE_CONFIG, 3);

PG_RESET_TEMPLATE(failsafeConfig_t, failsafeConfig,
    .failsafe_delay = SETTING_FAILSAFE_DELAY_DEFAULT,                                   // 0.5 sec
    .failsafe_recovery_delay = SETTING_FAILSAFE_RECOVERY_DELAY_DEFAULT,                 // 0.5 seconds (plus 200ms explicit delay)
    .failsafe_off_delay = SETTING_FAILSAFE_OFF_DELAY_DEFAULT,                           // 20sec
    .failsafe_throttle_low_delay = SETTING_FAILSAFE_THROTTLE_LOW_DELAY_DEFAULT,         // default throttle low delay for "just disarm" on failsafe condition
    .failsafe_procedure = SETTING_FAILSAFE_PROCEDURE_DEFAULT,                           // default full failsafe procedure
    .failsafe_fw_roll_angle = SETTING_FAILSAFE_FW_ROLL_ANGLE_DEFAULT,                   // 20 deg left
    .failsafe_fw_pitch_angle = SETTING_FAILSAFE_FW_PITCH_ANGLE_DEFAULT,                 // 10 deg dive (yes, positive means dive)
    .failsafe_fw_yaw_rate = SETTING_FAILSAFE_FW_YAW_RATE_DEFAULT,                       // 45 deg/s left yaw (left is negative, 8s for full turn)
    .failsafe_stick_motion_threshold = SETTING_FAILSAFE_STICK_THRESHOLD_DEFAULT,
    .failsafe_min_distance = SETTING_FAILSAFE_MIN_DISTANCE_DEFAULT,                     // No minimum distance for failsafe by default
    .failsafe_min_distance_procedure = SETTING_FAILSAFE_MIN_DISTANCE_PROCEDURE_DEFAULT, // default minimum distance failsafe procedure
    .failsafe_mission_delay = SETTING_FAILSAFE_MISSION_DELAY_DEFAULT,                   // Time delay before Failsafe activated during WP mission (s)
);

4. FAILSAFE阶段&状态机

  • FAILSAFE_PROCEDURE_AUTO_LANDING:触发FAILSAFE_LANDING
  • FAILSAFE_PROCEDURE_DROP_IT:触发FAILSAFE_LANDED
  • FAILSAFE_PROCEDURE_RTH:触发FAILSAFE_RETURN_TO_HOME
typedef enum {
    FAILSAFE_IDLE = 0,
    /* Failsafe mode is not active. All other
     * phases indicate that the failsafe flight
     * mode is active.
     */
    FAILSAFE_RX_LOSS_DETECTED,
    /* In this phase, the connection from the receiver
     * has been confirmed as lost and it will either
     * transition into FAILSAFE_RX_LOSS_RECOVERED if the
     * RX link is recovered immediately or one of the
     * recovery phases otherwise (as configured via
     * failsafe_procedure) or into FAILSAFE_RX_LOSS_IDLE
     * if failsafe_procedure is NONE.
     */
    FAILSAFE_RX_LOSS_IDLE,
    /* This phase will just do nothing else than wait
     * until the RX connection is re-established and the
     * sticks are moved more than the failsafe_stick_threshold
     * settings and then transition to FAILSAFE_RX_LOSS_RECOVERED.
     * Note that this phase is only used when
     * failsafe_procedure = NONE.
     */
    FAILSAFE_RETURN_TO_HOME,
    /* Failsafe is executing RTH. This phase is the first one
     * enabled when failsafe_procedure = RTH if an RTH is
     * deemed possible (RTH might not be activated if e.g.
     * a HOME position was not recorded or some required
     * sensors are not working at the moment). If RTH can't
     * be started, this phase will transition to FAILSAFE_LANDING.
     */
    FAILSAFE_LANDING,
    /* Performs NAV Emergency Landing using controlled descent rate if
     * altitude sensors available.
     * Otherwise Emergency Landing performs a simplified landing procedure.
     * This is done by setting throttle and roll/pitch/yaw controls
     * to a pre-configured values that will allow aircraft
     * to reach ground in somewhat safe "controlled crash" way.
     * This is the first recovery phase enabled when
     * failsafe_procedure = LAND. Once timeout expires or if a
     * "controlled crash" can't be executed, this phase will
     * transition to FAILSAFE_LANDED.
     */
    FAILSAFE_LANDED,
    /* Failsafe has either detected that the model has landed and disabled
     * the motors or either decided to drop the model because it couldn't
     * perform an emergency landing. It will disarm, prevent re-arming
     * and transition into FAILSAFE_RX_LOSS_MONITORING immediately. This is
     * the first recovery phase enabled when failsafe_procedure = DROP.
     */
    FAILSAFE_RX_LOSS_MONITORING,
    /* This phase will wait until the RX connection is
     * working for some time and if and only if switch arming
     * is used and the switch is in the unarmed position
     * will allow rearming again.
     */
    FAILSAFE_RX_LOSS_RECOVERED
    /* This phase indicates that the RX link has been re-established and
     * it will immediately transition out of failsafe mode (phase will
     * transition to FAILSAFE_IDLE.)
     */
} failsafePhase_e;

在这里插入图片描述

5. 参考资料

【1】iNav开源代码之严重炸机 – 危险隐患
【2】BetaFlight模块设计之二十八:MainPidLoop任务分析

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/760286.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

科普一下Elasticsearch中BM25算法的使用

首先还是先了解几个概念,Elasticsearch是一个开源的分布式搜索和分析引擎,它使用一系列算法来计算文档的相关性分数(relevance score)。这些算法用于确定查询与文档的匹配程度,以便按相关性对搜索结果进行排序。以下是…

【C++】多线程编程一(初识并发和多线程)

目录 一、并发和并行的概念 1.并发 2.并行 3.并发和并行的区别 二、并发的途径 多进程并发 多线程并发 三、C11相关多线程编程的头文件 一、并发和并行的概念 1.并发 并发:指同一时刻只能有一条指令执行,但是多个进程指令被快速地轮换执行&#…

C语言--文件操作

文章目录 前言文件文件名 文件的打开和关闭文件指针文件的打开和关闭 文件的顺序读写fgetc、fputcfgets、fputsfprintf、fsanffread、fwrite 文件的随机读写fseekftellrewind 文本文件和二进制文件文件读取结束的判定feof 文件缓冲区 前言 在我们写完一个程序之后,…

【数据结构】树二叉树的概念以及堆的详解

⭐️ 往期相关文章 ✨链接1:【数据结构】顺序表 ✨链接2:【数据结构】单链表 ✨链接3:【数据结构】双向带头循环链表 ✨链接4:【数据结构】栈和队列 ⭐️ 树的概念 百度百科的解释:树是一种非线性的数据结构&#xf…

Jmeter四种关联方法讲解

目录 方法一,从前一个请求中取,用正则表达式提取器。 二、json path extractor 三、json extractor 四、XPath Extractor 方法一,从前一个请求中取,用正则表达式提取器。 具体方法,在需要获得数据的请求上右击添加…

【09】STM32·HAL库-新建HAL库版本MDK工程 | 下载STM32固件库

目录 1,新建工程前的准备工作(了解)1.1下载相关STM32Cube 官方固件包(F1/F4/F7/H7) 2,新建HAL库版本MDK工程步骤(熟悉)2.1新建工程文件夹2.1.1Drivers文件夹2.1.2Middlewares文件夹2…

基数排序(Radix_Sort)

基数排序 (Radix Sort)-20230715 前言 基数排序适用于多关键字排序,与前述的比较排序不同,实现基数排序不需要对关键字进行比较和移动。简而言之,基数排序是一类借助多关键字排序的思想对单逻辑关键字实现排序的方法。 多关键字排序 先看…

SwiftUI 原生或利用 Vision 检测限定高度的 Text 视图能否完整显示文本的方法

功能需求 在 SwiftUI 开发中,为了节省空间我们往往会为内容很长的文本视图(Text)限定一个高度,然后让用户决定是否展开显示其完整内容。 如上图所示,为了节省空间我们对 Text 视图高度做了限制,然后根据文本长度自动显示或隐藏展开按钮,用户点击该按钮即可展开显示完整…

FL Studio21入门版编曲 2023年免费小白新手编曲工具

全能数字音乐工作站(DAW)编曲、剪辑、录音、混音,有了它就能把你的笔记本电脑变成全功能音乐工作室。 内置丰富插件,满足不同风格创作拥有强大的采样引擎,自带高品质打击乐、钢琴、弦乐、吉他等107种乐器效果。 流行…

C++-把字符串转换成整数

题目来源:牛客网 题目描述: 将一个字符串转换成一个整数,要求不能使用字符串转换整数的库函数。 数值为 0 或者字符串不是一个合法的数值则返回 0 数据范围:字符串长度满足 0≤n≤100 进阶:空间复杂度 O(1) O(1) &…

Mybatis执行SQL过程

文章目录 1. 相关代码2. 创建SqlSession3. 创建Mapper代理对象4.sql的执行4.1 MapperProxy.invoke()4.2 mapperMethod.execute()4.3 sqlSession.selectOne4.4 CachingExecutor.query()4.5 BaseExecutor.query方法4.6 SimpleExecutor.doQuery方法 1. 相关代码 Testpublic void …

其他形式转欧拉角形式

1. 坐标系轴方向问题 3D数学基础中约定使用左手坐标系 左手坐标系 右手坐标系 左手正方向:x正向右平移,y向上平移,z向前平移. 右手正方向:x正向左平移&#xff0…

漫谈大数据时代的个人信息安全(二)——“逢脸造戏”

大数据时代的个人信息安全系列二:“逢脸造戏” 1. 逢脸造戏2. 生物识别信息安全2.1 生物识别信息被大量获取2.2 生物识别信息被非法滥用 3. 各国加强对深度合成监管4. 个人信息保护小贴士 互联网就像公路,用户使用它,就会留下脚印。 每个人都…

文件IO_复制文件描述符(附Linux-5.15.10内核源码分析)

目录 1.文件描述符复制简介 2.dup函数原型 2.1 dup函数 2.2 dup函数工作原理 2.3 dup函数内核源码分析 2.4 dup函数示例代码 3.dup2函数原型 3.1 dup2函数 3.2 dup2函数工作原理 3.3 dup2函数内核源码分析 3.4 dup2函数示例代码 4.dup3函数原型 4.1 dup3函数 4.2…

rv1126人脸识别的相关操作

目录 一、代码的改写Makeflierkmedia_rockx_face_insert.cpprkmedia_rockx_face_rga_rtsp_main.cpprkmedia_rockx_face_two_rkisp_rtsp_main.cppsqlite3_operation.cpp二、在ubuntu上交叉编译三、板子上的相关操作一、代码的改写 Makeflie 修改交叉编译工具链 rkmedia_rockx_fa…

2023年NOC决赛-加码未来编程赛项决赛模拟题-Python模拟题--卷5

第一题 题目:输入一个整数n,计算其各位上数字之和,并用汉语写出每一位数字并输出。 【输入格式】一个整数 【输出格式】再一行内输出数字之和的每一位对应的汉字 【输入样例】1234 【输出样例】一零 第二题 题目:小溪使用 Excel 将任意 2 组数字中相同的数按照从小到…

终于有人把软件测试用例讲清楚了(一定要收藏)

目录 1:公司流程 1.1. 测试用例的4个特性 1.1. 测试用例通常包括以下几个组成元素: 1. 编写测试用例的基本方法 1.1.1. 概念 1.1.1. 示例 1.1练习案例: 1.1. 边界值法 1.1.1. 确定边界值的方法() 1.1. 因果图法 1.1.1.…

keil5软件仿真stm32设置 和 调试技巧

keil5软件仿真stm32设置 和 调试技巧 文章目录 keil5软件仿真stm32设置 和 调试技巧前言一、设置二、调试1.串口显示 总结 前言 不想用板子的时候或没有板子的时候,软件仿真更方便调试快速验证; 提示:以下是本篇文章正文内容,下面…

LeetCode 周赛上分之旅 #33 摩尔投票派上用场

⭐️ 本文已收录到 AndroidFamily,技术和职场问题,请关注公众号 [彭旭锐] 和 [BaguTree Pro] 知识星球提问。 学习数据结构与算法的关键在于掌握问题背后的算法思维框架,你的思考越抽象,它能覆盖的问题域就越广,理解难…

【简单认识MySQL数据库存储引擎】

文章目录 一、存储引擎概念介绍二、MyISAM存储引擎1.特点详解2.适用生产环境 三、InnoDB存储引擎1.特点详解2.适用生产环境 四、数据库存储引擎操作1.查看数据库支持的存储引擎2.查看数据库存储引擎3.修改数据库表的存储引擎 五、行锁和表锁1.InnoDB使用行锁和表锁的场景2.行锁…