Files
Motor_v2/Robot_V2/device/ang_sensor.h
T
cbb 971374d8ec feat(FOC): 增加闭环速度控制算法
- 重构setPhaseVoltage函数实现,提高执行效率
- 增加update_power函数,动态更新电源电压
- 优化velocity_open_loop函数,调用、setPhaseVoltage避免重复代码
- 实现angle_control和velocity_control闭环控制函数
- 调整PID控制器参数初始化及增加参数设置接口
- 改进电流和编码器速度卡尔曼滤波器实现
- 更新CAN通信数据打包逻辑,增加测试字段
- 在定时器中断中集成多种控制模式切换逻辑
- 完善角度传感器数据处理,改进速度计算方法
- 减小速度滤波数组大小,提升响应速度
2025-11-06 02:07:15 +08:00

40 lines
800 B
C++

#ifndef _angsensor_H
#define _angsensor_H
#include <cstdio>
#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 = 3;
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;
protected:
void KTH7823_init(void);
bool m_firstUpdate;
float m_lastAngle;
float m_cumulativeAngle;
float m_lastcumulativeAngle;
float velocity[VEL_FILTER_SIZE] = {0.0f};
};
#ifdef __cplusplus
}
#endif
#endif