修正了FOC控制器中电气角度计算的符号错误(减法改为加法), 移除了不必要的空行,并优化了velocity_open_loop函数中的注释 格式。同时修正了角度控制中PID计算的目标角度差值顺序。 BREAKING CHANGE: 角度校准参数从硬编码值改为配置常量。
42 lines
886 B
C++
42 lines
886 B
C++
#ifndef _angsensor_H
|
|
#define _angsensor_H
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
#include "gd32c10x_eval.h"
|
|
#include <cstring>
|
|
#include "config.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);
|
|
|
|
|
|
class angle_sensor {
|
|
public:
|
|
float calibration_angle = ANGLESENS_CALIBRATION_ANGLE;
|
|
u8 init(void);
|
|
float read_sensorAngle(void);
|
|
float update(void);
|
|
void reset(void);
|
|
float getAngle(void) const;
|
|
float getRawAngle(void) const;
|
|
float getcurrent_sensorangle(void) const;
|
|
u8 angle_set(float angle);
|
|
u8 set_calibration(float angle);
|
|
|
|
protected:
|
|
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 |