123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565 |
- /******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
- * File Name : MC_PID_regulators.c
- * Author : IMS Systems Lab
- * Date First Issued : 21/11/07
- * Description : This file contains the software implementation for the
- PI(D) regulators.
- ********************************************************************************
- * History:
- * 21/11/07 v1.0
- * 29/05/08 v2.0
- ********************************************************************************
- * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
- * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
- * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
- * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
- * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *
- * THIS SOURCE CODE IS PROTECTED BY A LICENSE.
- * FOR MORE INFORMATION PLEASE CAREFULLY READ THE LICENSE AGREEMENT FILE LOCATED
- * IN THE ROOT DIRECTORY OF THIS FIRMWARE PACKAGE.
- *******************************************************************************/
- /* Standard include ----------------------------------------------------------*/
- #include "MC_PID_regulators.h"
- #include "string.h"
- /*根据型号设置不同的PID参数*/
- //Volans PID参数
- const PID_Struct_t PID_Torque_InitStructure_Volans =
- {
- (int16_t)20000, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)3, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-100, //hLower_Limit_Output //电流环给微弱的负值,给转子施加反向扭矩让电机可以缓慢降速
- (int32_t)32767, //hUpper_Limit_Output
- (int32_t)(-32768 * 1024), //wLower_Limit_Integral
- (int32_t)(32767 * 1024), //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_Flux_InitStructure_Volans =
- {
- (int16_t)20000, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)3, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-32768, //hLower_Limit_Output
- (int32_t)32767, //hUpper_Limit_Output
- (int32_t)(-32768 * 1024), //wLower_Limit_Integral
- (int32_t)(32767 * 1024), //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_Weak_InitStructure_Volans =
- {
- (int16_t)64, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)3, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-262144, //hLower_Limit_Output
- (int32_t)0, //hUpper_Limit_Output
- (int32_t)-268435456, //wLower_Limit_Integral
- (int32_t)0, //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_ConstantPower_Volans =
- {
- (int16_t)30000, //hKp_Gain
- (uint16_t)256, //hKp_Divisor
- (int16_t)300, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-2100, //hLower_Limit_Output
- (int32_t)0, //hUpper_Limit_Output
- (int32_t)-2150400, //wLower_Limit_Integral
- (int32_t)0, //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_MotorSpd_Volans =
- {
- (int16_t)4096, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)1, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-100, //hLower_Limit_Output
- (int32_t)1050, //hUpper_Limit_Output
- (int32_t)-102400, //wLower_Limit_Integral
- (int32_t)1075200, //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_IMax_Volans =
- {
- (int16_t)30000, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)300, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-1050, //hLower_Limit_Output
- (int32_t)0, //hUpper_Limit_Output
- (int32_t)-1075200, //wLower_Limit_Integral
- (int32_t)0, //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- //Volans_Plus PID参数
- const PID_Struct_t PID_Torque_InitStructure_Volans_Plus =
- {
- (int16_t)20000, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)3, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-100, //hLower_Limit_Output //电流环给微弱的负值,给转子施加反向扭矩让电机可以缓慢降速
- (int32_t)32767, //hUpper_Limit_Output
- (int32_t)(-32768 * 1024), //wLower_Limit_Integral
- (int32_t)(32767 * 1024), //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_Flux_InitStructure_Volans_Plus =
- {
- (int16_t)20000, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)3, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-32768, //hLower_Limit_Output
- (int32_t)32767, //hUpper_Limit_Output
- (int32_t)(-32768 * 1024), //wLower_Limit_Integral
- (int32_t)(32767 * 1024), //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_Weak_InitStructure_Volans_Plus =
- {
- (int16_t)64, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)3, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-262144, //hLower_Limit_Output
- (int32_t)0, //hUpper_Limit_Output
- (int32_t)-268435456, //wLower_Limit_Integral
- (int32_t)0, //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_ConstantPower_Volans_Plus =
- {
- (int16_t)30000, //hKp_Gain
- (uint16_t)256, //hKp_Divisor
- (int16_t)300, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-2100, //hLower_Limit_Output
- (int32_t)0, //hUpper_Limit_Output
- (int32_t)-2150400, //wLower_Limit_Integral
- (int32_t)0, //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_MotorSpd_Volans_Plus =
- {
- (int16_t)4096, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)1, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-100, //hLower_Limit_Output
- (int32_t)1050, //hUpper_Limit_Output
- (int32_t)-102400, //wLower_Limit_Integral
- (int32_t)1075200, //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_IMax_Volans_Plus =
- {
- (int16_t)30000, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)300, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-1050, //hLower_Limit_Output
- (int32_t)0, //hUpper_Limit_Output
- (int32_t)-1075200, //wLower_Limit_Integral
- (int32_t)0, //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- //Pegasi PID参数
- const PID_Struct_t PID_Torque_InitStructure_Pegasi =
- {
- (int16_t)20000, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)3, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-100, //hLower_Limit_Output //电流环给微弱的负值,给转子施加反向扭矩让电机可以缓慢降速
- (int32_t)32767, //hUpper_Limit_Output
- (int32_t)(-32768 * 1024), //wLower_Limit_Integral
- (int32_t)(32767 * 1024), //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_Flux_InitStructure_Pegasi =
- {
- (int16_t)20000, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)3, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-32768, //hLower_Limit_Output
- (int32_t)32767, //hUpper_Limit_Output
- (int32_t)(-32768 * 1024), //wLower_Limit_Integral
- (int32_t)(32767 * 1024), //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_Weak_InitStructure_Pegasi =
- {
- (int16_t)64, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)3, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-262144, //hLower_Limit_Output
- (int32_t)0, //hUpper_Limit_Output
- (int32_t)-268435456, //wLower_Limit_Integral
- (int32_t)0, //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_ConstantPower_Pegasi =
- {
- (int16_t)30000, //hKp_Gain
- (uint16_t)256, //hKp_Divisor
- (int16_t)300, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-2100, //hLower_Limit_Output
- (int32_t)0, //hUpper_Limit_Output
- (int32_t)-2150400, //wLower_Limit_Integral
- (int32_t)0, //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_MotorSpd_Pegasi =
- {
- (int16_t)4096, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)1, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-100, //hLower_Limit_Output
- (int32_t)1050, //hUpper_Limit_Output
- (int32_t)-102400, //wLower_Limit_Integral
- (int32_t)1075200, //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_IMax_Pegasi =
- {
- (int16_t)30000, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)300, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-1050, //hLower_Limit_Output
- (int32_t)0, //hUpper_Limit_Output
- (int32_t)-1075200, //wLower_Limit_Integral
- (int32_t)0, //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- //Pegasi_Plus PID参数
- const PID_Struct_t PID_Torque_InitStructure_Pegasi_Plus =
- {
- (int16_t)20000, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)3, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-100, //hLower_Limit_Output //电流环给微弱的负值,给转子施加反向扭矩让电机可以缓慢降速
- (int32_t)32767, //hUpper_Limit_Output
- (int32_t)(-32768 * 1024), //wLower_Limit_Integral
- (int32_t)(32767 * 1024), //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_Flux_InitStructure_Pegasi_Plus =
- {
- (int16_t)20000, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)3, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-32768, //hLower_Limit_Output
- (int32_t)32767, //hUpper_Limit_Output
- (int32_t)(-32768 * 1024), //wLower_Limit_Integral
- (int32_t)(32767 * 1024), //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_Weak_InitStructure_Pegasi_Plus =
- {
- (int16_t)64, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)3, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-262144, //hLower_Limit_Output
- (int32_t)0, //hUpper_Limit_Output
- (int32_t)-268435456, //wLower_Limit_Integral
- (int32_t)0, //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_ConstantPower_Pegasi_Plus =
- {
- (int16_t)30000, //hKp_Gain
- (uint16_t)256, //hKp_Divisor
- (int16_t)300, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-2100, //hLower_Limit_Output
- (int32_t)0, //hUpper_Limit_Output
- (int32_t)-2150400, //wLower_Limit_Integral
- (int32_t)0, //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_MotorSpd_Pegasi_Plus =
- {
- (int16_t)4096, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)1, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-100, //hLower_Limit_Output
- (int32_t)1050, //hUpper_Limit_Output
- (int32_t)-102400, //wLower_Limit_Integral
- (int32_t)1075200, //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- const PID_Struct_t PID_IMax_Pegasi_Plus =
- {
- (int16_t)30000, //hKp_Gain
- (uint16_t)1024, //hKp_Divisor
- (int16_t)300, //hKi_Gain
- (uint16_t)1024, //hKi_Divisor
- (int16_t)0, //hKd_Gain
- (uint16_t)1024, //hKd_Divisor
- (int32_t)0, //wPreviousError
- (int32_t)-1050, //hLower_Limit_Output
- (int32_t)0, //hUpper_Limit_Output
- (int32_t)-1075200, //wLower_Limit_Integral
- (int32_t)0, //wUpper_Limit_Integral
- (int32_t)0 //wIntegral
- };
- /* 根据型号设置不同的PID参数 END */
- //PID控制变量定义
- PID_Struct_t PID_Torque_InitStructure; // q轴电流环闭环
- PID_Struct_t PID_Flux_InitStructure; // d轴电流环闭环
- PID_Struct_t PID_Weak_InitStructure; // 输出电压弱磁闭环
- PID_Struct_t PID_ConstantPower; // 恒定功率
- PID_Struct_t PID_MotorSpd; // 电机速度闭环
- PID_Struct_t PID_IMax; // 母线电流闭环
- /*******************************************************************************
- * Function Name : PID_Init
- * Description : Initialize PID coefficients for torque, flux and speed loop:
- Kp_Gain: proportional coeffcient
- Ki_Gain: integral coeffcient
- Kd_Gain: differential coeffcient
- * Input : Pointer 1 to Torque PI structure,
- Pointer 2 to Flux PI structure,
- Pointer 3 to Speed PI structure
- * Output : None
- * Return : None
- *******************************************************************************/
- void PID_Init (uint8_t SerialNum)
- {
- switch(SerialNum)
- {
- case 1://Volans
- {
- memcpy(&PID_Torque_InitStructure.hKp_Gain, &PID_Torque_InitStructure_Volans.hKp_Gain, sizeof(PID_Torque_InitStructure_Volans));
- memcpy(&PID_Flux_InitStructure.hKp_Gain, &PID_Flux_InitStructure_Volans.hKp_Gain, sizeof(PID_Flux_InitStructure_Volans));
- memcpy(&PID_Weak_InitStructure.hKp_Gain, &PID_Weak_InitStructure_Volans.hKp_Gain, sizeof(PID_Weak_InitStructure_Volans));
- memcpy(&PID_ConstantPower.hKp_Gain, &PID_ConstantPower_Volans.hKp_Gain, sizeof(PID_ConstantPower_Volans));
- memcpy(&PID_MotorSpd.hKp_Gain, &PID_MotorSpd_Volans.hKp_Gain, sizeof(PID_MotorSpd_Volans));
- memcpy(&PID_IMax.hKp_Gain, &PID_IMax_Volans.hKp_Gain, sizeof(PID_IMax_Volans));
- break;
- }
- case 2://Volans Plus
- {
- memcpy(&PID_Torque_InitStructure.hKp_Gain, &PID_Torque_InitStructure_Volans_Plus.hKp_Gain, sizeof(PID_Torque_InitStructure_Volans_Plus));
- memcpy(&PID_Flux_InitStructure.hKp_Gain, &PID_Flux_InitStructure_Volans_Plus.hKp_Gain, sizeof(PID_Flux_InitStructure_Volans_Plus));
- memcpy(&PID_Weak_InitStructure.hKp_Gain, &PID_Weak_InitStructure_Volans_Plus.hKp_Gain, sizeof(PID_Weak_InitStructure_Volans_Plus));
- memcpy(&PID_ConstantPower.hKp_Gain, &PID_ConstantPower_Volans_Plus.hKp_Gain, sizeof(PID_ConstantPower_Volans_Plus));
- memcpy(&PID_MotorSpd.hKp_Gain, &PID_MotorSpd_Volans_Plus.hKp_Gain, sizeof(PID_MotorSpd_Volans_Plus));
- memcpy(&PID_IMax.hKp_Gain, &PID_IMax_Volans_Plus.hKp_Gain, sizeof(PID_IMax_Volans_Plus));
- break;
- }
- case 3://Pegasi
- {
- memcpy(&PID_Torque_InitStructure.hKp_Gain, &PID_Torque_InitStructure_Pegasi.hKp_Gain, sizeof(PID_Torque_InitStructure_Pegasi));
- memcpy(&PID_Flux_InitStructure.hKp_Gain, &PID_Flux_InitStructure_Pegasi.hKp_Gain, sizeof(PID_Flux_InitStructure_Pegasi));
- memcpy(&PID_Weak_InitStructure.hKp_Gain, &PID_Weak_InitStructure_Pegasi.hKp_Gain, sizeof(PID_Weak_InitStructure_Pegasi));
- memcpy(&PID_ConstantPower.hKp_Gain, &PID_ConstantPower_Pegasi.hKp_Gain, sizeof(PID_ConstantPower_Pegasi));
- memcpy(&PID_MotorSpd.hKp_Gain, &PID_MotorSpd_Pegasi.hKp_Gain, sizeof(PID_MotorSpd_Pegasi));
- memcpy(&PID_IMax.hKp_Gain, &PID_IMax_Pegasi.hKp_Gain, sizeof(PID_IMax_Pegasi));
- break;
- }
- case 4://Pegasi Plus
- {
- memcpy(&PID_Torque_InitStructure.hKp_Gain, &PID_Torque_InitStructure_Pegasi_Plus.hKp_Gain, sizeof(PID_Torque_InitStructure_Pegasi_Plus));
- memcpy(&PID_Flux_InitStructure.hKp_Gain, &PID_Flux_InitStructure_Pegasi_Plus.hKp_Gain, sizeof(PID_Flux_InitStructure_Pegasi_Plus));
- memcpy(&PID_Weak_InitStructure.hKp_Gain, &PID_Weak_InitStructure_Pegasi_Plus.hKp_Gain, sizeof(PID_Weak_InitStructure_Pegasi_Plus));
- memcpy(&PID_ConstantPower.hKp_Gain, &PID_ConstantPower_Pegasi_Plus.hKp_Gain, sizeof(PID_ConstantPower_Pegasi_Plus));
- memcpy(&PID_MotorSpd.hKp_Gain, &PID_MotorSpd_Pegasi_Plus.hKp_Gain, sizeof(PID_MotorSpd_Pegasi_Plus));
- memcpy(&PID_IMax.hKp_Gain, &PID_IMax_Pegasi_Plus.hKp_Gain, sizeof(PID_IMax_Pegasi_Plus));
- break;
- }
- default://默认处理
- {
- memcpy(&PID_Torque_InitStructure.hKp_Gain, &PID_Torque_InitStructure_Volans.hKp_Gain, sizeof(PID_Torque_InitStructure_Volans));
- memcpy(&PID_Flux_InitStructure.hKp_Gain, &PID_Flux_InitStructure_Volans.hKp_Gain, sizeof(PID_Flux_InitStructure_Volans));
- memcpy(&PID_Weak_InitStructure.hKp_Gain, &PID_Weak_InitStructure_Volans.hKp_Gain, sizeof(PID_Weak_InitStructure_Volans));
- memcpy(&PID_ConstantPower.hKp_Gain, &PID_ConstantPower_Volans.hKp_Gain, sizeof(PID_ConstantPower_Volans));
- memcpy(&PID_MotorSpd.hKp_Gain, &PID_MotorSpd_Volans.hKp_Gain, sizeof(PID_MotorSpd_Volans));
- memcpy(&PID_IMax.hKp_Gain, &PID_IMax_Volans.hKp_Gain, sizeof(PID_IMax_Volans));
- break;
- }
- }
- }
- /*******************************************************************************
- * Function Name : PID_Regulator
- * Description : Compute the PI(D) output for a PI(D) regulation.
- * Input : Pointer to the PID settings (*PID_Flux)
- Speed in int16_t format
- * Output : int16_t
- * Return : None
- *******************************************************************************/
- /******************************PID 调节函数的说明******************************/
- int16_t PID_Regulator(int16_t hReference, int16_t hPresentFeedback, PID_Struct_t *PID_Struct)
- {
- int16_t wError;
- int32_t wProportional_Term,wIntegral_Term, houtput_32;
- int32_t dwAux;
-
- // error computation
- wError= hReference - hPresentFeedback; //取得需要误差量 delta_e <Q16
- // Proportional term computation
- wProportional_Term = PID_Struct->hKp_Gain * wError; // wP = Kp * delta_e <Q32
- // wP 为比例总调节量
- // Integral term computation
- if(PID_Struct->hKi_Gain == 0)
- {
- PID_Struct->wIntegral = 0;
- }
- else
- {
- wIntegral_Term = PID_Struct->hKi_Gain * wError; // wI = Ki * delta_e ,本次积分项
- dwAux = PID_Struct->wIntegral + wIntegral_Term; // 积分累积的调节量 = 以前的积分累积量 + 本次的积分项
- if(dwAux > PID_Struct->wUpper_Limit_Integral) //dwAux为当前积分累积项,下面测试积分饱和度
- {
- PID_Struct->wIntegral = PID_Struct->wUpper_Limit_Integral; // 超上限
- }
- else if(dwAux < PID_Struct->wLower_Limit_Integral) //超下限
- {
- PID_Struct->wIntegral = PID_Struct->wLower_Limit_Integral;
- }
- else
- {
- PID_Struct->wIntegral = dwAux; //不超限, 更新积分累积项为dwAux <Q32
- }
-
- }
- // Differential term computation
- houtput_32 = (wProportional_Term / PID_Struct->hKp_Divisor) + //不含微分环节的总调节量 <Q16
- (PID_Struct->wIntegral / PID_Struct->hKi_Divisor);
- if((houtput_32 < 0) && (houtput_32 < PID_Struct->hLower_Limit_Output)) //超下限
- {
- return(PID_Struct->hLower_Limit_Output);
- }
- if((houtput_32 > 0) && (houtput_32 >= PID_Struct->hUpper_Limit_Output)) //测试输出是否饱和,超上限
- {
- return(PID_Struct->hUpper_Limit_Output);
- }
- else
- {
- return houtput_32; //不超限。输出结果 houtput_32 <Q16
- }
- }
- /******************** (C) COPYRIGHT 2008 STMicroelectronics *******************/
|