|
|
@@ -1,13 +1,10 @@
|
|
|
/**
|
|
|
- @copyright (C) COPYRIGHT 2022 Fortiortech Shenzhen
|
|
|
- @file AddFunction.c
|
|
|
- @author Fortiortech Appliction Team
|
|
|
- @since Create:2022-07-13
|
|
|
- @date Last modify:2022-07-14
|
|
|
- @note Last modify author is Marcel He
|
|
|
- @brief This file contains main function used for Motor Control.
|
|
|
-*/
|
|
|
-
|
|
|
+ * @copyright None
|
|
|
+ * @file AddFunction.c
|
|
|
+ * @author Comment Vivre
|
|
|
+ * @date 2024-08-28
|
|
|
+ * @brief None
|
|
|
+ */
|
|
|
#include <MyProject.h>
|
|
|
|
|
|
/* Public variables --------------------------------------------------------- */
|
|
|
@@ -15,9 +12,11 @@
|
|
|
bit isCtrlPowOn = false; ///< 开关机控制
|
|
|
PWMINPUTCAL xdata mcPwmInput; ///< PWM捕获结构体变量
|
|
|
FOCCTRL xdata mcFocCtrl; ///< FOC电机控制相关结构体变量
|
|
|
-MCRAMP data mcRefRamp; ///< 控制指令爬坡结构体相关变量
|
|
|
debugONOFFTypeDef xdata debug_ONOFFTest; ///< ONOFF启停测试小工具结构体变量
|
|
|
|
|
|
+
|
|
|
+RefRamp data LoopRefRamp; ///< 控制指令爬坡结构体相关变量
|
|
|
+
|
|
|
/**
|
|
|
@brief 对变量取16位的绝对值
|
|
|
@param[in] value
|
|
|
@@ -315,8 +314,7 @@ void LoopResponse(void)
|
|
|
{
|
|
|
static int16 refRampOut = 0;
|
|
|
|
|
|
- if ((mcState == mcRun) || (mcState == mcStop))
|
|
|
- {
|
|
|
+
|
|
|
switch (mcFocCtrl.CtrlMode)
|
|
|
{
|
|
|
case 0:
|
|
|
@@ -334,17 +332,17 @@ void LoopResponse(void)
|
|
|
// FOC_THECOMP = _Q15(-25.0 / 180.0); // SMO 估算补偿角
|
|
|
// 启动电流环与外环给定衔接
|
|
|
#if (MOTOR_CTRL_MODE == SPEED_LOOP_CONTROL)
|
|
|
- mcRefRamp.OutValue_float = mcFocCtrl.SpeedFlt;
|
|
|
+ LoopRefRamp.Out = mcFocCtrl.SpeedFlt;
|
|
|
#elif (MOTOR_CTRL_MODE == POWER_LOOP_CONTROL)
|
|
|
- mcRefRamp.OutValue_float = mcFocCtrl.Power;
|
|
|
+ LoopRefRamp.Out = mcFocCtrl.Power;
|
|
|
#elif (MOTOR_CTRL_MODE == UQ_LOOP_CONTROL)
|
|
|
- mcRefRamp.OutValue_float = mcFocCtrl.UqFlt;
|
|
|
+ LoopRefRamp.Out = mcFocCtrl.UqFlt;
|
|
|
#elif (MOTOR_CTRL_MODE == UQ_POWER_CONTROL)
|
|
|
- mcRefRamp.OutValue_float = mcFocCtrl.UqFlt;
|
|
|
+ LoopRefRamp.Out = mcFocCtrl.UqFlt;
|
|
|
#endif
|
|
|
mcFocCtrl.LoopTime = LOOP_TIME;
|
|
|
- mcRefRamp.IncValue = RAMP_INC;
|
|
|
- mcRefRamp.DecValue = RAMP_DEC;
|
|
|
+ LoopRefRamp.Inc = RAMP_INC;
|
|
|
+ LoopRefRamp.Dec = RAMP_DEC;
|
|
|
mcFocCtrl.IqRef = FOC_IQREF;
|
|
|
FOC_IDREF = ID_RUN_CURRENT; // D轴启动电流
|
|
|
PI1_UKH = mcFocCtrl.IqRef;
|
|
|
@@ -376,7 +374,7 @@ void LoopResponse(void)
|
|
|
if (mcFocCtrl.LoopTime >= LOOP_TIME)
|
|
|
{
|
|
|
mcFocCtrl.LoopTime = 0;
|
|
|
- refRampOut = Motor_Ramp(mcFocCtrl.Ref); // 控制命令爬坡函数,用于实现调速信号之间平滑过渡
|
|
|
+ refRampOut = LoopRamp(mcFocCtrl.Ref); // 控制命令爬坡函数,用于实现调速信号之间平滑过渡
|
|
|
#if (MOTOR_CTRL_MODE == CURRENT_LOOP_CONTROL)
|
|
|
{
|
|
|
mcFocCtrl.IqRef = refRampOut;
|
|
|
@@ -437,7 +435,6 @@ void LoopResponse(void)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -448,34 +445,17 @@ void LoopResponse(void)
|
|
|
@return 爬坡结果(int16)
|
|
|
@date 2022-07-14
|
|
|
*/
|
|
|
-int16 Motor_Ramp(int16 ref)
|
|
|
+int16 LoopRamp(int16 Xn0)
|
|
|
{
|
|
|
- mcRefRamp.RefValue = ref; // 爬坡函数输入
|
|
|
+ LoopRefRamp.In = Xn0; // 爬坡函数输入
|
|
|
|
|
|
- if (mcRefRamp.OutValue_float < mcRefRamp.RefValue)
|
|
|
- {
|
|
|
- if (mcRefRamp.OutValue_float + mcRefRamp.IncValue < mcRefRamp.RefValue)
|
|
|
- {
|
|
|
- mcRefRamp.OutValue_float += mcRefRamp.IncValue;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- mcRefRamp.OutValue_float = mcRefRamp.RefValue;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (mcRefRamp.OutValue_float - mcRefRamp.DecValue > mcRefRamp.RefValue)
|
|
|
- {
|
|
|
- mcRefRamp.OutValue_float -= mcRefRamp.DecValue;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- mcRefRamp.OutValue_float = mcRefRamp.RefValue;
|
|
|
- }
|
|
|
- }
|
|
|
+ // 数据爬坡处理
|
|
|
+ if ((LoopRefRamp.Out + LoopRefRamp.Inc) < LoopRefRamp.In)
|
|
|
+ { LoopRefRamp.Out += LoopRefRamp.Inc; }
|
|
|
+ else if ((LoopRefRamp.Out - LoopRefRamp.Dec) > LoopRefRamp.In)
|
|
|
+ { LoopRefRamp.Out -= LoopRefRamp.Dec; }
|
|
|
|
|
|
- return (int16)mcRefRamp.OutValue_float; // 输出浮点数取整
|
|
|
+ return (int16)LoopRefRamp.Out;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -484,29 +464,26 @@ int16 Motor_Ramp(int16 ref)
|
|
|
*/
|
|
|
void ATORamp(void)
|
|
|
{
|
|
|
- if (mcState == mcRun)
|
|
|
+ if (mcFocCtrl.State_Count == (ATO_RAMP_PERIOD << 2))
|
|
|
{
|
|
|
- if (mcFocCtrl.State_Count == (ATO_RAMP_PERIOD << 2))
|
|
|
- {
|
|
|
- FOC_EKP = OBSW_KP_GAIN_RUN1; // 估算器里的PI的KP
|
|
|
- FOC_EKI = OBSW_KI_GAIN_RUN1; // 估算器里的PI的KI
|
|
|
- }
|
|
|
- else if (mcFocCtrl.State_Count == ((ATO_RAMP_PERIOD << 1) + ATO_RAMP_PERIOD))
|
|
|
- {
|
|
|
- FOC_EKP = OBSW_KP_GAIN_RUN2; // 估算器里的PI的KP
|
|
|
- FOC_EKI = OBSW_KI_GAIN_RUN2; // 估算器里的PI的KI
|
|
|
- }
|
|
|
- else if (mcFocCtrl.State_Count == (ATO_RAMP_PERIOD << 1))
|
|
|
- {
|
|
|
- FOC_EKP = OBSW_KP_GAIN_RUN3; // 估算器里的PI的KP
|
|
|
- FOC_EKI = OBSW_KI_GAIN_RUN3; // 估算器里的PI的KI
|
|
|
- }
|
|
|
- else if (mcFocCtrl.State_Count <= ATO_RAMP_PERIOD && mcFocCtrl.Flg_ATORampEnd == 0)
|
|
|
- {
|
|
|
- FOC_EKP = OBSW_KP_GAIN_RUN4; // 估算器里的PI的KP
|
|
|
- FOC_EKI = OBSW_KI_GAIN_RUN4; // 估算器里的PI的KI
|
|
|
- mcFocCtrl.Flg_ATORampEnd = 1; // ATO 爬坡结束
|
|
|
- }
|
|
|
+ FOC_EKP = OBSW_KP_GAIN_RUN1; // 估算器里的PI的KP
|
|
|
+ FOC_EKI = OBSW_KI_GAIN_RUN1; // 估算器里的PI的KI
|
|
|
+ }
|
|
|
+ else if (mcFocCtrl.State_Count == ((ATO_RAMP_PERIOD << 1) + ATO_RAMP_PERIOD))
|
|
|
+ {
|
|
|
+ FOC_EKP = OBSW_KP_GAIN_RUN2; // 估算器里的PI的KP
|
|
|
+ FOC_EKI = OBSW_KI_GAIN_RUN2; // 估算器里的PI的KI
|
|
|
+ }
|
|
|
+ else if (mcFocCtrl.State_Count == (ATO_RAMP_PERIOD << 1))
|
|
|
+ {
|
|
|
+ FOC_EKP = OBSW_KP_GAIN_RUN3; // 估算器里的PI的KP
|
|
|
+ FOC_EKI = OBSW_KI_GAIN_RUN3; // 估算器里的PI的KI
|
|
|
+ }
|
|
|
+ else if (mcFocCtrl.State_Count <= ATO_RAMP_PERIOD && mcFocCtrl.Flg_ATORampEnd == 0)
|
|
|
+ {
|
|
|
+ FOC_EKP = OBSW_KP_GAIN_RUN4; // 估算器里的PI的KP
|
|
|
+ FOC_EKI = OBSW_KI_GAIN_RUN4; // 估算器里的PI的KI
|
|
|
+ mcFocCtrl.Flg_ATORampEnd = 1; // ATO 爬坡结束
|
|
|
}
|
|
|
}
|
|
|
|