永磁同步电机采用FOC算法实现电机控制,FOC算法的控制框图如下:
软件实现,ADC采样触发实现算法的软件流程图如下:
PARK变换模块宏定义代码如下:
typedef struct {
_iq Alpha; // Input: stationary d-axis stator variable
_iq Beta; // Input: stationary q-axis stator variable
_iq Angle; // Input: rotating angle (pu)
_iq Ds; // Output: rotating d-axis stator variable
_iq Qs; // Output: rotating q-axis stator variable
_iq Sine;
_iq Cosine;
} PARK;
/*-----------------------------------------------------------------------------
Default initalizer for the PARK object.
-----------------------------------------------------------------------------*/
#define PARK_DEFAULTS {
0, \
0, \
0, \
0, \
0, \
0, \
0, \
}
/*------------------------------------------------------------------------------
PARK Transformation Macro Definition
------------------------------------------------------------------------------*/
#define PARK_MACRO(v) \
\
v.Ds = _IQmpy(v.Alpha,v.Cosine) + _IQmpy(v.Beta,v.Sine); \
v.Qs = _IQmpy(v.Beta,v.Cosine) - _IQmpy(v.Alpha,v.Sine);
#endif // __PARK_H__
CLARKE变换模块宏定义代码如下:
typedef struct {
_iq As; // Input: phase-a stator variable
_iq Bs;// Input: phase-b stator variable
_iq Cs;// Input: phase-c stator variable
_iq Alpha;// Output: stationary d-axis stator variable
_iq Beta;// Output: stationary q-axis stator variable
} CLARKE;
/*-----------------------------------------------------------------------------
Default initalizer for the CLARKE object.
-----------------------------------------------------------------------------*/
#define CLARKE_DEFAULTS {
0, \
0, \
0, \
0, \
0, \
}
/*------------------------------------------------------------------------------
CLARKE Transformation Macro Definition
------------------------------------------------------------------------------*/
#define CLARKE_MACRO(v)\
\
v.Alpha = v.As;\
v.Beta = _IQmpy((v.As +_IQmpy2(v.Bs)),_IQ(0.57735026918963));\
// 1/sqrt(3) = 0.57735026918963
#endif // __CLARKE_H__
IPARK变换模块宏定义代码如下:
typedef struct {
_iq Alpha; // Output: stationary d-axis stator variable
_iq Beta; // Output: stationary q-axis stator variable
_iq Angle; // Input: rotating angle (pu)
_iq Ds; // Input: rotating d-axis stator variable
_iq Qs; // Input: rotating q-axis stator variable
_iq Sine; // Input: Sine term
_iq Cosine; // Input: Cosine term
} IPARK;
/*-----------------------------------------------------------------------------
Default initalizer for the IPARK object.
-----------------------------------------------------------------------------*/
#define IPARK_DEFAULTS {
0, \
0, \
0, \
0, \
0, \
0, \
0, \
}
/*------------------------------------------------------------------------------
Inverse PARK Transformation Macro Definition
------------------------------------------------------------------------------*/
#define IPARK_MACRO(v) \
\
v.Alpha = _IQmpy(v.Ds,v.Cosine) - _IQmpy(v.Qs,v.Sine); \
v.Beta = _IQmpy(v.Qs,v.Cosine) + _IQmpy(v.Ds,v.Sine);
#endif // __IPARK_H__
滑模观测器参考代码如下:
// 定义系统参数
R = 1.0; // 电机内阻
L = 0.1; // 电机电感
Ke = 0.01; // 电机电动势常数
Kt = 0.02 ; // 电机转矩常数
/ /定义控制器参数
Kp = 0.5 ; //比例增益
Ki = 0.1 ; // 积分增益
// 定义变量
theta_hat = 0.0; // 转子位置估计值
theta_dot_hat = 0.0 ; // 转子速度估计值
theta_ref = 0.0 ; //目标转子位置
theta_dot_ref = 0.0 ; // 目标转子速度
u = 0.0 ; // 控制输入
e_int = 0.0 ; // 积分误差
//定义滑模观测器参数
lambda1 = 1.0;
lambda2 = 1.0;
#define SMO_MACRO(v) \
\
Te = Kt * (i_a * sin(theta_hat) - i_b * cos(theta_hat));\ //计算电机电磁转矩
s1 = theta_dot_hat - lambda1 * Te;\ // 计算滑模观测器误差
s2 = theta_hat - theta_ref;\
u = -Kp * s1 - Ki * e_int ;\ // 计算控制器输出
theta_dot_hat += (R / L) * i_a - (Ke / L) * sin(theta_hat) * u theta_hat += theta_dot_hat;\ //更新状态估计
e_int += s2;\ //更新积分误差
#endif // __SMO_H__
申明:由于本人水平一般,分享的知识有误,或者采用的方案不够好的,欢迎各路大神指正批评,给大家带来的不便,敬请谅解,本文观点仅供参考。