feat(FOC): 集成ARM数学库优化FOC算法实现

- 引入arm_math.h库以使用ARM优化的数学函数
- 将角度归一化从弧度制改为角度制,使用360.0f替代2*PI
- 使用arm_sin_cos_f32替代查找表实现正弦余弦计算
- 移除注释中的ARM Clark和Park变换函数调用
- 修正机械角度计算中的时间常量为TIMER2_FREQUENCY倒数
- 移除传感器角度到弧度的转换,保持原始角度值
- 激活电流环控制中的Iq/Id计算并发送CAN数据
This commit is contained in:
cbb
2026-01-07 23:13:21 +08:00
parent fccb93dd41
commit 72506ce87d
14 changed files with 133 additions and 452 deletions
+6 -5
View File
@@ -3,7 +3,7 @@
#include <stdint.h>
// 如果使用CMSIS DSP库,需要定义ARM_MATH_CM4
// #define ARM_MATH_CM4
#define ARM_MATH_CM4
#define EEP_DEBUG 1
#define OTA_DEBUG 1
@@ -39,9 +39,9 @@ constexpr u8 SIZE_FLOAT = sizeof(float);
constexpr u8 SIZE_U32 = sizeof(uint32_t);
constexpr float ADC_MAX = 65536.0f;
constexpr float PI = 3.14159265358979323846f;
constexpr float ANGLE_FACTOR = 25.0f / 360.0f * 2.0f * PI;
constexpr float DEG2RAD = 1.0f / 360.0f * 2 * PI;
constexpr float RAD2DEG = 360.0f / 2 * PI;
constexpr float ANGLE_FACTOR = 25.0f / 180.0f * PI;
constexpr float DEG2RAD = 1.0f / 180.0f * PI;
constexpr float RAD2DEG = 180.0f / PI; // 修正RAD2DEG定义,应该是180/π
constexpr float _1_SQRT3 = 0.57735026919f; // 1/sqrt(3)
constexpr float sqrt3dv2 = 0.86602540378f; // sqrt(3)/2的预计算值
constexpr u8 DEFAULT_VALUE = 0;
@@ -89,7 +89,8 @@ constexpr float ANGLESENS_FACTOR = 1.0f / ADC_MAX * 360.0f;
// TIMER2-任务调度
constexpr int TIMER2_PRESCALER = 119; // 120MHz / 120 = 1MHz
constexpr int TIMER2_PERIOD = 99; // 1MHz / 100 = 100us
constexpr int TIMER2_PERIOD = 49; // 1MHz / 50 = 50us
constexpr float TIMER2_FREQUENCY = 1 / 5e-5;
// TIMER1-PWM
constexpr int TIMER1_PRESCALER = 0; // 不分频,计数器时钟为120MHz