refactor(angle): 引入角度卡尔曼滤波器 EncoderAngleKalman
新增 EncoderAngleKalman 类以处理编码器角度噪声,改善角度反馈质量,并配合速度滤波器提供更准确的速度估算。 perf(CAN): 优化CAN数据打包与状态标识字段 改进 pack_u16_to_bytes 等函数实现方式,使用 reinterpret_cast 提高效率; 扩展 Status_code 为多个独立状态位,增强诊断能力。 feat(FOC): 添加电机锁止和停止功能 新增 drv_stop 和 drv_hold 方法用于控制电机占空比,支持紧急制动与角度保持。优化了FOC控制器的接口设计,提升安全性和可控性。 fix(filter): 修正中值滤波器数组大小动态分配问题 将 medium_filter 函数中的排序数组改为使用传入参数 size 动态定义,避免固定大小带来的资源浪费或越界风险,提高滤波精度和稳定性。 chore(project): 移除冗余文件及代码清理 移除了 thermal.cpp/h 文件及相关引用,调整项目结构,删除未使用的全局变量定义、注释和头文件包含,精简系统初始化流程。
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
#include "health.h"
|
||||
#include "Can.h"
|
||||
#include "DengFOC.h"
|
||||
#include "adc.h"
|
||||
|
||||
extern sampler sampler;
|
||||
extern CAN_transmiter CAN0_transmiter;
|
||||
extern FOC_Controlroller FOC;
|
||||
ThermalController thermalController; // 热量控制器初始化
|
||||
#define SQUARE(x) ((x) * (x))
|
||||
#define max(a, b, c) \
|
||||
((a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c)))
|
||||
|
||||
constexpr u16 PROTECT_TIME = 3000; // 过热保护时间,单位*10ms
|
||||
/**
|
||||
** @brief 热能计算
|
||||
** @param None
|
||||
** @retval 热量值
|
||||
*/
|
||||
u32 ThermalController::update() {
|
||||
thermal_value = thermal_value * thermalRate;
|
||||
thermal_value +=
|
||||
SQUARE(sampler.get_drv_temp()) + SQUARE(sampler.get_mcu_temp());
|
||||
|
||||
if (remainingTime10Ms) { // 当前已经过热停机,正在停机自然散热
|
||||
if (thermal_value < thermal_capacity * recoveryRate) {
|
||||
remainingTime10Ms = 1; // 可以恢复工作
|
||||
}
|
||||
if (remainingTime10Ms == 1) { // 过热恢复
|
||||
FOC.resume();
|
||||
CAN0_transmiter.ThermalStatus = 0;
|
||||
return --remainingTime10Ms;
|
||||
}
|
||||
return --remainingTime10Ms;
|
||||
} else { // 当前没有过热停机
|
||||
current_max =
|
||||
1000 * max(sampler.get_current('U'), sampler.get_current('V'),
|
||||
sampler.get_current('W')); // 获取电流最大值
|
||||
thermal_value +=
|
||||
SQUARE(current_max) * gapTimeMs / 100000; // 计算当前电流热积累值
|
||||
}
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef _HEALTH_H
|
||||
#define _HEALTH_H
|
||||
|
||||
#include "stdint.h"
|
||||
class ThermalController {
|
||||
private:
|
||||
u8 temperature;
|
||||
u16 current_max;
|
||||
|
||||
float thermalRate = 0.995f; // 热耗散系数(每单位时间散热比例)
|
||||
float recoveryRate = 0.6f; // 自然恢复率(散热到多少以下开始工作)
|
||||
|
||||
u32 thermal_value = 0;
|
||||
u32 thermal_capacity = 2250000; // 热容量
|
||||
|
||||
u16 gapTimeMs = 10; // 单次计算间隔ms
|
||||
u16 remainingTime10Ms = 0; // 过热冷却剩余ms
|
||||
public:
|
||||
u32 update();
|
||||
void reset() {
|
||||
thermal_value = 0;
|
||||
remainingTime10Ms = 0;
|
||||
}
|
||||
};
|
||||
|
||||
void angsens_MG_check(void);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "ang_sensor.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
void GPIO_config(void) {
|
||||
// 使能GPIOB时钟
|
||||
rcu_periph_clock_enable(RCU_GPIOB);
|
||||
@@ -31,11 +32,7 @@ u8 watchdog_init(u32 time) {
|
||||
return status;
|
||||
}
|
||||
|
||||
void angsens_MG_test(void) {
|
||||
u8 MGH = gpio_input_bit_get(GPIOB, GPIO_PIN_10);
|
||||
u8 MGL = gpio_input_bit_get(GPIOB, GPIO_PIN_11);
|
||||
std::printf("MGH:%d MGL:%d\r\n", MGH, MGL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief driver输出初始化
|
||||
*/
|
||||
|
||||
@@ -21,7 +21,6 @@ u8 tle5210b_init(void);
|
||||
u8 USART0_init(void);
|
||||
u8 watchdog_init(u32 time);
|
||||
void driver_init(void);
|
||||
void angsens_MG_test(void);
|
||||
// 任务标志定义
|
||||
typedef enum {
|
||||
TASK_MOTOR_CONTROL = 0,
|
||||
@@ -33,6 +32,7 @@ typedef enum {
|
||||
TASK_VBUS_UPDATE,
|
||||
TASK_THERMAL_CONTROL,
|
||||
TASK_CAN_TRANSMIT,
|
||||
TASK_MAGNETIC_CHECK,
|
||||
TASK_COUNT
|
||||
} SystemTask;
|
||||
|
||||
|
||||
@@ -94,4 +94,24 @@ void delay_decrement(void)
|
||||
if (0U != delay){
|
||||
delay--;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief system soft reset
|
||||
\param[in] none
|
||||
\param[out] none
|
||||
\retval none
|
||||
*/
|
||||
void system_soft_reset(void)
|
||||
{
|
||||
/* Set the software reset bit */
|
||||
SCB->AIRCR = (0x05FA0000U | (SCB->AIRCR & (0x700U)) | (1U << 2));
|
||||
|
||||
/* Data Synchronization Barrier */
|
||||
__DSB();
|
||||
|
||||
/* Wait for reset */
|
||||
while (1){
|
||||
__NOP();
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,8 @@ void delay_decrement(void);
|
||||
void idle_task_count(void);
|
||||
/* 获取CPU使用率 */
|
||||
uint8_t get_cpu_usage(void);
|
||||
/* 系统软复位 */
|
||||
void system_soft_reset(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user