feat(motor): 引入运行禁止机制重构电机控制安全系统

- 添加 run_inhibit.h/cpp 模块作为全局运行闸门,统一管理所有停机/唤醒逻辑
- 移除 FOC 控制器中的 5 个相互引用的开关机函数(shut_down/resume 等)
- 将 nFAULT 硬件故障检测从仅上报改为运行门控制,连续采样故障时申请禁止位
- 改进电压检测逻辑,欠压判定现在通过 run_inhibit 统一执行停机动作
- 修正 PB2(nFAULT) 引脚配置为内部上拉输入,避免浮空误读导致系统锁死
- 在 CAN 状态帧中新增 RunInhibit 位图(字节 36-39),实时反映禁止运行的故障源
- 电流采样失效、过热故障现在通过禁止位管理而非直接操作驱动状态
- 校准函数增加运行许可检查,防止在停机状态下意外唤醒驱动
This commit is contained in:
cbb
2026-10-13 00:47:52 +08:00
parent 72cc10b40d
commit 86ca7666fa
11 changed files with 255 additions and 144 deletions
+9 -5
View File
@@ -10,6 +10,7 @@
#include "adc.h"
#include "ang_sensor.h"
#include "health.h"
#include "run_inhibit.h"
#include "systick.h"
#include "gd32c10x.h"
@@ -102,15 +103,18 @@ static void run_motor_control_task(void) {
FOC.fast_voltage_check();
}
// 运行闸门:全工程唯一执行停机/唤醒功率级的地方。放在模式判断之前,
// 这样即使 control_mode 非法(>=8)也照样封住输出。
run_inhibit.update();
if (!run_inhibit.ready()) {
return; // 被禁止运行,或刚解除还在驱动唤醒建立期(输出已由闸门保持 0)
}
if (FOC.control_mode >= 8) return;
// 模式合法时再派发控制函数,防止数组越界。
reset_control_loops_on_mode_change();
if (!FOC.is_shut_down) {
(FOC.*control_functions[FOC.control_mode])();
} else {
FOC.drv_stop();
}
(FOC.*control_functions[FOC.control_mode])();
}
/**