#include <MyProject.h>


FOCCTRL xdata mcFocCtrl;

/**
    @brief        对变量取16位的绝对值
    @param[in]    value
    @return       绝对值
    @date         2022-07-13
*/
uint16_t Abs_F16(int16_t value)
{
    if (value < 1)
    { return (-value); }
    else
    { return (value); }
}






/**
    @brief        启动ATO爬坡函数，用于静止启动时候对ATO进行爬坡，提高启动可靠性
    @date         2022-07-14
*/
void ATORamp(void)
{
    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 爬坡结束
    }
}
