SOP.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #include "SOP.h"
  2. void SOP_Init(void)
  3. {
  4. sopd_flg_firstRun = true;
  5. }
  6. //-------------------------------------------------------------------------
  7. void SOP(void)
  8. {
  9. static real_T sopn_V_up;
  10. real_T sopn_I_currPred;
  11. real_T sopn_V_battPred10;
  12. real_T sopn_pct_socPred10;
  13. real_T ocv;
  14. real_T Ro;
  15. real_T RC;
  16. real_T Rp;
  17. real_T ileft;
  18. real_T iright;
  19. real_T imid;
  20. real_T sopn_V_battU;
  21. if(sopd_flg_firstRun)
  22. {
  23. sopn_V_up = 0;
  24. }
  25. ocv = (real_T)look1_u16tu16(socd_pct_battSoc, cmnm_pct_soc, cmnm_V_ocv, 13) * 0.001;
  26. Ro = (real_T)look1_u16tu16(socd_pct_battSoc, cmnm_pct_soc, cmnm_R_ohm, 13) * 0.001 * 0.001;
  27. Rp = (real_T)look1_u16tu16(socd_pct_battSoc, cmnm_pct_soc, cmnm_R_polar,13) * 0.001 * 0.001;
  28. RC = (real_T)look1_u16tu16(socd_pct_battSoc, cmnm_pct_soc, cmnm_F_polar,13) * 0.001;
  29. //printf("%f %f %f %f\n",ocv,Ro,Rp,RC);
  30. sopn_V_up = (real_T)sfmd_V_cellUAvrg * 0.001 - ocv - (real_T)sfmd_I_curr * 0.1 * Ro;
  31. //printf("soc:%d,I:%d,up:%f\n",socd_pct_battSoc,sfmd_I_curr,sopn_V_up);
  32. //充电功率
  33. sopn_I_currPred = 0;
  34. predSystem(ocv,Ro,Rp,RC,sopn_I_currPred,sopn_V_up,&sopn_pct_socPred10,&sopn_V_battPred10);
  35. if(sopn_V_battPred10 > (real_T)cmnc_V_chrgFul * 0.001 || sopn_pct_socPred10 > (real_T)socc_pct_battSocUp * 0.1)
  36. {
  37. sopn_I_currPred = 0;
  38. }
  39. else
  40. {
  41. sopn_I_currPred = (real_T)sopc_I_currUp * 0.1;
  42. predSystem(ocv,Ro,Rp,RC,sopn_I_currPred,sopn_V_up,&sopn_pct_socPred10,&sopn_V_battPred10);
  43. if(sopn_V_battPred10 < (real_T)cmnc_V_chrgFul * 0.001 && sopn_pct_socPred10 < (real_T)socc_pct_battSocUp * 0.1)
  44. {
  45. sopn_I_currPred = (real_T)sopc_I_currUp * 0.1;;
  46. }
  47. else
  48. {
  49. iright = (real_T) sopc_I_currUp * 0.1;
  50. ileft = 0;
  51. imid = (iright + ileft)/2;
  52. while(iright - ileft > 0.1)
  53. {
  54. predSystem(ocv,Ro,Rp,RC,imid,sopn_V_up,&sopn_pct_socPred10,&sopn_V_battPred10);
  55. if(sopn_V_battPred10 > (real_T)cmnc_V_chrgFul * 0.001 || sopn_pct_socPred10 > (real_T)socc_pct_battSocUp * 0.1)
  56. {
  57. iright = imid;
  58. }
  59. else
  60. {
  61. ileft = imid;
  62. }
  63. imid = (iright + ileft)/2;
  64. }
  65. sopn_I_currPred = ileft;
  66. }
  67. }
  68. sopn_V_battU = (ocv + sopn_I_currPred * Ro + sopn_V_up) * cmnc_num_cellUNum;
  69. sopd_I_chrgCurrMax = (int16_T)(sopn_I_currPred * 10);
  70. sopd_P_chrgPMax = (uint16_T)(sopn_V_battU * sopn_I_currPred);
  71. predSystem(ocv,Ro,Rp,RC,sopn_I_currPred,sopn_V_up,&sopn_pct_socPred10,&sopn_V_battPred10);
  72. //printf("%f, %f, %f\n\n",sopn_I_currPred,sopn_pct_socPred10,sopn_V_battPred10);
  73. //放电功率
  74. sopn_I_currPred = 0;
  75. predSystem(ocv,Ro,Rp,RC,sopn_I_currPred,sopn_V_up,&sopn_pct_socPred10,&sopn_V_battPred10);
  76. if(sopn_V_battPred10 < (real_T)cmnc_V_disChrgLim * 0.001 || sopn_pct_socPred10 < (real_T)socc_pct_battSocLow * 0.1)
  77. {
  78. sopn_I_currPred = 0;
  79. }
  80. else
  81. {
  82. sopn_I_currPred = (real_T)sopc_I_currLow * 0.1;
  83. predSystem(ocv,Ro,Rp,RC,sopn_I_currPred,sopn_V_up,&sopn_pct_socPred10,&sopn_V_battPred10);
  84. if(sopn_V_battPred10 > (real_T)cmnc_V_disChrgLim * 0.001 && sopn_pct_socPred10 > (real_T)socc_pct_battSocLow * 0.1)
  85. {
  86. sopn_I_currPred = (real_T)sopc_I_currLow * 0.1;;
  87. }
  88. else
  89. {
  90. iright = 0;
  91. ileft = (real_T) sopc_I_currLow * 0.1;
  92. imid = (iright + ileft)/2;
  93. while(iright - ileft > 0.1)
  94. {
  95. predSystem(ocv,Ro,Rp,RC,imid,sopn_V_up,&sopn_pct_socPred10,&sopn_V_battPred10);
  96. if(sopn_V_battPred10 > (real_T)cmnc_V_disChrgLim * 0.001 && sopn_pct_socPred10 > (real_T)socc_pct_battSocLow * 0.1)
  97. {
  98. iright = imid;
  99. }
  100. else
  101. {
  102. ileft = imid;
  103. }
  104. imid = (iright + ileft)/2;
  105. }
  106. sopn_I_currPred = iright;
  107. }
  108. }
  109. sopn_V_battU = sopn_V_battPred10 * cmnc_num_cellUNum;
  110. sopd_I_disChrgCurrMax = (int16_T)(sopn_I_currPred * 10);
  111. sopd_P_disChrgPMax = (uint16_T)(- sopn_V_battU * sopn_I_currPred);
  112. //sopn_V_up = sopn_V_up * exp(-1/RC) + Rp * (1 - exp(-1/RC)) * sfmd_I_curr;
  113. sopd_flg_firstRun = false;
  114. }
  115. void predSystem(real_T ocv,real_T Ro,real_T Rp,real_T RC,real_T sopn_I_currPred,real_T sopn_V_up,real_T *sopn_pct_socPred10,real_T *sopn_V_battPred10)
  116. {
  117. uint8_T i;
  118. real_T sopn_V_upPred;
  119. real_T sopn_pct_socPred;
  120. real_T sopn_Q_cellCap;
  121. sopn_Q_cellCap = (real_T)sohd_pct_bcuSoh * cmnc_Q_ratedCp * 0.0001;
  122. sopn_pct_socPred = (real_T) socd_pct_battSoc * 0.1;
  123. sopn_V_upPred = sopn_V_up;
  124. for(i = 0;i < 10;i++)
  125. {
  126. sopn_V_upPred = sopn_V_upPred * exp(-1/RC) + Rp * (1 - exp(-1/RC)) * sopn_I_currPred;
  127. sopn_pct_socPred = sopn_pct_socPred + sopn_I_currPred/sopn_Q_cellCap/36;
  128. }
  129. *sopn_pct_socPred10 = sopn_pct_socPred;
  130. *sopn_V_battPred10 = ocv + sopn_I_currPred * Ro + sopn_V_upPred;
  131. }