feat(FOC): 重构FOC控制器实现并修复SVPWM算法支持

- 修复类名拼写错误:FOC_Controlroller -> FOC_Controller
- 移除不必要的角度归一化函数,直接使用fmod优化性能
- 添加完整的SVPWM算法实现,提高电机控制效率
- 重构PID参数配置,使用动态参数调整机制
- 增加电流反馈功能,实时监测电机运行状态
- 优化电压安全限制,提高系统稳定性
- 更新控制模式映射,支持更多控制策略
- 改进CAN通信协议,增加电流反馈传输
This commit is contained in:
cbb
2026-02-02 02:23:16 +08:00
parent 25e2edfd0c
commit 173fadadd2
14 changed files with 386 additions and 233 deletions
+19 -12
View File
@@ -6,6 +6,7 @@
extern "C" {
#endif
#include <cstdint>
#include "gd32c10x_can.h"
// 定义一个联合体类型用于float和byte数组之间的转换
@@ -72,24 +73,29 @@ class CAN_transmiter {
private:
bool is_sleep = false; // 是否休眠
u8 controller_Mode = 0; // 电机模式
float_union_t limit_velocity_union = {0}; // 限制速度
u16 limit_voltage = 0; // 限制电压
short mcu_temp = 0; // MCU温度
short motor_temp = 0; // 电机温度
u16 Power_Voltage = 0; // 电源电压
float_union_t rt_angle_union = {0}; // 实时角度
float_union_t rt_velocity_union = {0}; // 实时速度
bool MotorStatus = 0; // 电机状态码
u8 Target_Control_Mode = 0; // 目标控制模式
u8 controller_Mode = 0; // 当前模式
short mcu_temp = 0; // MCU温度
short motor_temp = 0; // 电机温度
u16 Power_Voltage = 0; // 电源电压
u16 limit_voltage = 0; // 限制电压
float_union_t rt_angle_union = {0}; // 实时角度
float_union_t rt_velocity_union = {0}; // 实时速度
float_union_t rt_current_union = {0}; // 实时电流
float_union_t target_angle_union = {0}; // 目标角度
u8 Target_Control_Mode = 0; // 目标控制模式
u8 EEPROMStatus = 0; // EEPROM状态码
float_union_t target_velocity_union = {0}; // 目标速度
float_union_t target_current_union = {0};
float_union_t target_current_union = {0}; // 目标电流
float_union_t u_current_union = {0}; // U相电流
float_union_t w_current_union = {0}; // W相电流
float_union_t v_current_union = {0}; // V相电流
bool MotorStatus = 0; // 电机状态码
u8 EEPROMStatus = 0; // EEPROM状态码
can_trasnmit_message_struct transmit_message; // 发送消息结构体
u8 transmit_mailbox = CAN_NOMAILBOX; // 初始化为无mailbox状态
u8 transmit_data[64]; // CANFD最大64字节
@@ -106,6 +112,7 @@ class CAN_transmiter {
FlagStatus can0_receive_flag; // CAN0接收标志
FlagStatus can0_send_flag; // CAN0发送标志
float_union_t testfloat_union = {0}; // 测试用
u16 test_u16 = 0;
bool MagStatus = 0; // 磁状态码
bool ThermalStatus = 0; // 热能状态码