集中所有外设初始化于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方法,配合主程序完成模块化初始化检查。
41 lines
790 B
C++
41 lines
790 B
C++
#ifndef _ADC_H
|
|
#define _ADC_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include "stdint.h"
|
|
constexpr u8 FILTER_SIZE = 6;
|
|
constexpr u8 BLOCK_SIZE = FILTER_SIZE * sizeof(float);
|
|
class sampler {
|
|
private:
|
|
float vbus_samples[FILTER_SIZE + 1];
|
|
float currU_samples[FILTER_SIZE + 1];
|
|
float currV_samples[FILTER_SIZE + 1];
|
|
float currW_samples[FILTER_SIZE + 1];
|
|
float mcu_temp_samples[FILTER_SIZE + 1];
|
|
float drv_temp_samples[FILTER_SIZE + 1];
|
|
u8 current_sample_index;
|
|
|
|
float tempora_sample;
|
|
|
|
public:
|
|
u8 init(void);
|
|
void update_mcu_temp(void);
|
|
void update_drv_temp(void);
|
|
void update_vbus_voltage(void);
|
|
void update_current(void);
|
|
|
|
float get_mcu_temp(void);
|
|
float get_drv_temp(void);
|
|
float get_vbus_voltage(void);
|
|
float get_current(char);
|
|
};
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|