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:
@@ -1,4 +1,5 @@
|
||||
#include "Timer.h"
|
||||
#include "Can.h"
|
||||
#include "DengFOC.h"
|
||||
#include "Timer.h"
|
||||
#include "gd32c10x.h"
|
||||
@@ -28,6 +29,7 @@ static u32 total_us100_counter = 0; // 总计数器,每100微秒增加1
|
||||
extern u16 adc_value[7];
|
||||
extern FOC_Controlroller FOC;
|
||||
extern TaskScheduler scheduler;
|
||||
extern CAN_transmiter CAN0_transmiter;
|
||||
// 添加系统运行时间计数器
|
||||
static volatile std::u64 system_runtime_us = 0;
|
||||
|
||||
@@ -179,6 +181,7 @@ void TIMER2_IRQHandler(void) {
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
CAN0_transmiter.can0_send_flag = SET;
|
||||
scheduler.taskFlags |= (1 << TASK_CAN_TRANSMIT);
|
||||
break;
|
||||
}
|
||||
@@ -198,6 +201,7 @@ void TIMER2_IRQHandler(void) {
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
scheduler.taskFlags |= (1 << TASK_MAGNETIC_CHECK);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -275,7 +279,7 @@ void timer1_gpio_config(void) {
|
||||
gpio_bit_set(GPIOB, GPIO_PIN_0);
|
||||
gpio_bit_set(GPIOB, GPIO_PIN_12);
|
||||
|
||||
/* 配置TIMER1完全重映射 - 应该使用DISABLE,因为我们使用的是默认引脚 */
|
||||
/* 配置TIMER1完全重映射*/
|
||||
gpio_pin_remap_config(GPIO_TIMER1_FULL_REMAP, DISABLE);
|
||||
}
|
||||
|
||||
@@ -358,7 +362,6 @@ extern "C" void TIMER1_IRQHandler(void) {
|
||||
timer_interrupt_flag_clear(TIMER1, TIMER_INT_FLAG_CH3);
|
||||
|
||||
scheduler.taskFlags |= (1 << TASK_CURRENT_UPDATE);
|
||||
// 在这里添加需要在PWM周期90%位置执行的代码
|
||||
// 例如触发ADC采样或其他操作
|
||||
}
|
||||
}
|
||||
@@ -391,10 +394,8 @@ void Set_Pwm(u16 channel, float duty_cycle) {
|
||||
\note The channel parameter must be between 0 and 3 inclusive.
|
||||
*/
|
||||
void Set_3Pwm(float duty_cycle0, float duty_cycle1, float duty_cycle2) {
|
||||
timer_channel_output_pulse_value_config(TIMER1, TIMER_CH_0,
|
||||
duty_cycle0 * TIMER1_PERIOD);
|
||||
timer_channel_output_pulse_value_config(TIMER1, TIMER_CH_1,
|
||||
duty_cycle1 * TIMER1_PERIOD);
|
||||
timer_channel_output_pulse_value_config(TIMER1, TIMER_CH_2,
|
||||
duty_cycle2 * TIMER1_PERIOD);
|
||||
// 直接写寄存器
|
||||
TIMER_CH0CV(TIMER1) = (uint32_t)(duty_cycle0 * TIMER1_PERIOD);
|
||||
TIMER_CH1CV(TIMER1) = (uint32_t)(duty_cycle1 * TIMER1_PERIOD);
|
||||
TIMER_CH2CV(TIMER1) = (uint32_t)(duty_cycle2 * TIMER1_PERIOD);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user