refactor(main): 统一外设初始化流程

集中所有外设初始化于main函数起始处,通过返回值确认各模块是否成功启动;
refactor(adc): 修改采样器初始化返回值
将sampler构造函数替换为带返回值的init方法,在main函数中加入初始化结果判断,
确保系统启动时硬件配置正确加载。

feat(motor): 引入motor模块并重构电机控制逻辑
将GPIO操作封装进motor_sleep和motor_resume函数,提升代码可读性和维护性。
引入motor.h头文件,并在main.cpp中进行电机初始化统一管理。
修改FOC控制器中的shutdown与resume方法调用新接口。

refactor(filter): 优化卡尔曼滤波器实现
重命名状态变量xp为x,简化访问逻辑;移除冗余注释及未使用的getlastAngle方法;
调整getVelocity计算系数,提高速度估算精度;增加init方法支持初始状态设置。

refactor(angle_sensor): 移除冗余速度计算功能
删除传感器内部的速度估算相关数组和方法,交由外部滤波器处理以降低耦合度。
更新SPI片选宏定义以区分不同设备,并增强错误处理机制。

refactor(can): 调整CAN通信ID及初始化流程
更改状态与配置帧的标识符ID,添加对特定命令ID的响应处理如电机复位指令。
将CAN_transmiter构造函数改为init方法,配合主程序完成模块化初始化检查。
This commit is contained in:
cbb
2025-12-08 02:48:59 +08:00
parent 93cbf18f1f
commit 839a32ff04
16 changed files with 164 additions and 132 deletions
-16
View File
@@ -1,15 +1,7 @@
#include "initial.h"
#include "Timer.h"
#include "ang_sensor.h"
#include <stdint.h>
void GPIO_config(void) {
// 使能GPIOB时钟
rcu_periph_clock_enable(RCU_GPIOB);
// 配置PB2为输入引脚,用于读取电机状态
gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_2);
}
/* retarget the C library printf function to the USART */
u8 USART0_init() {
@@ -33,14 +25,6 @@ u8 watchdog_init(u32 time) {
}
/**
* @brief driver输出初始化
*/
void driver_init(void) {
timer1_gpio_config();
timer1_pwm_config();
}
int fputc(int ch, FILE *f) throw() {
usart_data_transmit(EVAL_COM0, (uint8_t)ch);
while (RESET == usart_flag_get(EVAL_COM0, USART_FLAG_TBE))
-2
View File
@@ -17,10 +17,8 @@ void rcu_config(void);
static volatile uint32_t timer_delay_count = 0; // volatile 很重要!
int fputc(int ch, FILE *f); // 声明fputc函数以重载标准库实现
u8 tle5210b_init(void);
u8 USART0_init(void);
u8 watchdog_init(u32 time);
void driver_init(void);
// 任务标志定义
typedef enum {
TASK_MOTOR_CONTROL = 0,