通过定义 `TaskScheduler` 结构体和相关枚举类型, 将原TIMER2中断中耦合的操作解耦成多个独立任务标志, 便于后续维护和扩展,并提高系统实时响应能力。 feat(FOC): 优化电压安全范围与PID参数配置 将电压计算中的 `voltage_power_supply` 替换为更安全的 `v_safe`, 并引入电压有效性检测逻辑。同时调整PID控制器参数以适配12V供电场景。 此外,统一布尔变量初始化方式,提升代码可读性和安全性。 chore(build): 更新CMSIS工具链版本依赖 更新vcpkg配置文件中CMSIS Toolbox的版本要求, 从2.11.0升级至2.12.0,确保构建环境兼容最新功能及修复。
42 lines
877 B
C++
42 lines
877 B
C++
#ifndef _angsensor_H
|
|
#define _angsensor_H
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
#include "gd32c10x_eval.h"
|
|
#include "stdio.h"
|
|
|
|
u16 spi_rw_half_word(u32 spi_periph, const u16 i_HalfWord);
|
|
int spi_rw_half_word_dma(uint32_t spi_periph, uint16_t tx_data,
|
|
uint16_t *rx_data);
|
|
|
|
constexpr u16 VEL_FILTER_SIZE = 4;
|
|
|
|
class angle_sensor {
|
|
public:
|
|
angle_sensor();
|
|
float read_sensorAngle(void);
|
|
float update(void);
|
|
void reset(void);
|
|
float getAngle(void) const;
|
|
float getRawAngle(void) const;
|
|
float getVelocity(void) const;
|
|
float getRawVelocity(void) const;
|
|
float getcurrent_sensorangle(void) const;
|
|
|
|
protected:
|
|
void KTH7823_init(void);
|
|
float m_cumulativeAngle;
|
|
float current_angle_deg;
|
|
float current_angle_rad;
|
|
bool m_firstUpdate;
|
|
float m_lastAngle;
|
|
float m_lastcumulativeAngle;
|
|
float velocity[VEL_FILTER_SIZE] = {0.0f};
|
|
};
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif |