新增了电流环控制功能,包括通过三相电流计算 Iq 的 `cal_Iq_Id` 方法,并在 `current_control` 中实现了基于 PID 的电流控制逻辑。同时对电压设置、占空比计算等部分进行了调整与优化。 refactor(filter): 移除冗余的电流卡尔曼滤波器实现 删除了 `Filter.cpp` 和 `Filter.h` 中关于 `CurrentKalman` 类的冗余代码,统一外部定义,简化结构。 refactor(health): 改进热量控制器算法和数据类型 将热累积计算改为更精确的分段处理方式,并引入 Q16.16 定点数提升运算精度与性能;增加对异常温度值的判断修正。 fix(CAN): 调整电流发送顺序及标志位设置位置 修改 CAN 发送中 V 相与 W 相电流打包顺序,确保通信正确性;调整发送标志设置逻辑至主循环任务内触发。 chore(headers): 清理无用头文件引用和结构调整 移除了多个源文件中不必要的头文件包含(如 `<cstdio>`、`<array>`),并对部分全局变量声明做了 extern 处理以避免重复定义问题。
88 lines
2.7 KiB
C++
88 lines
2.7 KiB
C++
#include "health.h"
|
|
#include "Can.h"
|
|
#include "DengFOC.h"
|
|
#include "adc.h"
|
|
#include <stdint.h>
|
|
|
|
extern sampler sampler;
|
|
extern CAN_transmiter CAN0_transmiter;
|
|
extern FOC_Controlroller FOC;
|
|
ThermalController thermalController; // 热量控制器初始化
|
|
|
|
#define max(a, b, c) \
|
|
((a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c)))
|
|
constexpr u16 PROTECT_TIME = 6000; // 过热保护时间,单位*10ms
|
|
/**
|
|
** @brief 热能计算
|
|
** @param None
|
|
** @retval 热量值
|
|
*/
|
|
u32 ThermalController::update() {
|
|
thermal_value = Q16_16_MUL(thermal_value, thermalRate);
|
|
// 添加温度积累
|
|
int drv_temp = (int)sampler.get_drv_temp();
|
|
int mcu_temp = (int)sampler.get_mcu_temp();
|
|
if (drv_temp == 255)
|
|
drv_temp = 0;
|
|
if (mcu_temp == 255)
|
|
mcu_temp = 0;
|
|
thermal_value += drv_temp * drv_temp + mcu_temp * mcu_temp;
|
|
|
|
if (remainingTime10Ms) {
|
|
// 过热停机状态
|
|
// 检查是否可以恢复
|
|
q16_16_t recovery_threshold =
|
|
Q16_16_MUL(thermal_capacity, recoveryRate);
|
|
if (thermal_value < recovery_threshold) {
|
|
remainingTime10Ms = 1; // 可以恢复工作
|
|
}
|
|
if (remainingTime10Ms == 1) { // 过热恢复
|
|
FOC.resume();
|
|
CAN0_transmiter.ThermalStatus = 0;
|
|
return --remainingTime10Ms;
|
|
}
|
|
return --remainingTime10Ms;
|
|
} else {
|
|
// 当前没有过热停机
|
|
// 添加电流热积累
|
|
u32 currents[3] = {(u32)(sampler.get_current('U') * 1000),
|
|
(u32)(sampler.get_current('V') * 1000),
|
|
(u32)(sampler.get_current('W') * 1000)};
|
|
|
|
// 找最大电流(原始ADC值)
|
|
current_max = max(currents[0], currents[1], currents[2]);
|
|
if (current_max < 2000) {
|
|
thermal_value += current_max * current_max * gapTimeMs *
|
|
0.00007f; // 计算当前电流热积累值
|
|
} else if (current_max > 3800) {
|
|
thermal_value += current_max * current_max * gapTimeMs *
|
|
0.01f; // 添加当前电流热积累值
|
|
} else if (current_max > 3400) {
|
|
thermal_value += current_max * current_max * gapTimeMs *
|
|
0.005f; // 计算当前电流热积累值
|
|
} else if (current_max > 3000) {
|
|
thermal_value += current_max * current_max * gapTimeMs *
|
|
0.0002f; // 计算当前电流热积累值
|
|
} else if (current_max > 2000) {
|
|
thermal_value += current_max * current_max * gapTimeMs *
|
|
0.0001f; // 计算当前电流热积累值
|
|
}
|
|
}
|
|
|
|
if (thermal_value > thermal_capacity) {
|
|
FOC.shut_down();
|
|
remainingTime10Ms = PROTECT_TIME; // 过热停机
|
|
CAN0_transmiter.ThermalStatus = 1;
|
|
return remainingTime10Ms;
|
|
}
|
|
return thermal_value;
|
|
}
|
|
/**
|
|
** @brief 温度检测
|
|
** @param None
|
|
*/
|
|
void angsens_MG_check(void) {
|
|
bool MGH = gpio_input_bit_get(GPIOB, GPIO_PIN_10);
|
|
bool MGL = gpio_input_bit_get(GPIOB, GPIO_PIN_11);
|
|
CAN0_transmiter.MagStatus = MGH or MGL;
|
|
} |