spdflxwkn.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * @file spdflxwkn.c
  3. * @author xu, haifeng(xuhf58@midea.com)
  4. * @brief
  5. * @version 0.1
  6. * @date 2024-01-17
  7. *
  8. * @copyright Copyright (c) 2024
  9. *
  10. */
  11. #include "spdflxwkn.h"
  12. /******************************
  13. *
  14. * Variable Define and Initial
  15. *
  16. ******************************/
  17. SPDFW_CTRL_COEFIN spdflx_stCtrlCoefIn = {0};
  18. SPDFW_CTRL_COEF spdflx_stCtrlCoef = SPDFW_CTRL_COEF_DEFAULT;
  19. SPDFW_CTRL_IN spdflx_stCtrlIn = {0};
  20. SPDFW_CTRL_OUT spdflx_stCtrlOut = SPDFW_CTRL_OUT_DEFAULT;
  21. /******************************
  22. *
  23. * Function Statement
  24. *
  25. ******************************/
  26. void spdflx_voInit(void);
  27. void spdflx_voCoef(SPDFW_CTRL_COEFIN *in, SPDFW_CTRL_COEF *out);
  28. void spdflx_voCtrl(SPDFW_CTRL_IN *in, SPDFW_CTRL_COEF *coef, SPDFW_CTRL_OUT *out);
  29. /**
  30. * @brief Spd FluxWeak Module Init
  31. *
  32. * @param void
  33. * @return void
  34. */
  35. void spdflx_voInit(void)
  36. {
  37. spdflx_stCtrlOut.swIdRefPu = 0;
  38. spdflx_stCtrlOut.swIqLimPu = spdflx_stCtrlCoef.swIpeakMaxPu;
  39. }
  40. /**
  41. * @brief Spd FluxWeak Coefficient Init
  42. *
  43. * @param SPDFW_CTRL_COEFIN
  44. * @param SPDFW_CTRL_COEF
  45. * @return void
  46. */
  47. void spdflx_voCoef(SPDFW_CTRL_COEFIN *in, SPDFW_CTRL_COEF *out)
  48. {
  49. out->swFlxStartSpeedPu = in->swRSpeedPu >>1;
  50. out->swFlxStopSpeedPu = in->swRSpeedPu;
  51. out->swIdMinPu = in->swIdMinPu;
  52. out->swIpeakMaxPu = in->swIpeakMaxPu;
  53. out->slFlxKPu = ((SLONG) out->swIdMinPu<<15) /( out->swFlxStopSpeedPu - out->swFlxStartSpeedPu);
  54. }
  55. /**
  56. * @brief Spd FluxWeak Coefficient Calculate
  57. *
  58. * @param SPDFW_CTRL_IN
  59. * @param SPDFW_CTRL_COEF
  60. * @param SPDFW_CTRL_OUT
  61. * @return void
  62. */
  63. void spdflx_voCtrl(SPDFW_CTRL_IN *in, SPDFW_CTRL_COEF *coef, SPDFW_CTRL_OUT *out)
  64. {
  65. if(in->swSpdFbkLpfAbsPu < coef->swFlxStartSpeedPu)
  66. {
  67. out->swIdRefPu = 0;
  68. }
  69. else if(in->swSpdFbkLpfAbsPu < coef->swFlxStopSpeedPu)
  70. {
  71. out->swIdRefPu = (SWORD)(coef->slFlxKPu * ((SLONG)in->swSpdFbkLpfAbsPu - (SLONG)coef->swFlxStartSpeedPu) >>15);
  72. }
  73. else
  74. {
  75. out->swIdRefPu = coef->swIdMinPu;
  76. }
  77. out->swIqLimPu = mth_slSqrt(((SLONG)coef-> swIpeakMaxPu * (SLONG)coef-> swIpeakMaxPu) - ((SLONG)out->swIdRefPu * (SLONG)out->swIdRefPu));
  78. }