Files
Motor_v2/Robot_V2/device/ang_sensor.h
T
cbb 99cc397931 feat(FOC): 优化SVPWM算法并重构角度控制逻辑
- 引入新的三值约束宏 `_constrain3` 用于SVPWM计算优化
- 修改 `setPhaseVoltage` 函数签名,移除冗余的角度参数,内部自动计算电气角度
- 调整PWM占空比计算方式,提高电压利用率和控制精度
- 移除旧的DEG2RAD和RAD2DEG常量定义,改由initial.h统一管理
- 在initial.h中新增减速比常量REDUCTION_RATIO,并修正拼写错误
- 为角度传感器类更新速度滤波器尺寸,提升速度估算稳定性
- 更新PID控制器时间片常量,简化dt计算逻辑,提高执行效率
- 切换角度闭环控制至新NPID版本,增强系统响应性能
- 修正CAN通信中的目标角度解析逻辑,确保指令正确应用
2025-11-08 02:15:14 +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 = 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;
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