SOC.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. #include "SOC.h"
  2. //---------------SOC初始化-----------------------------------------------
  3. void SOC_Init(void)
  4. {
  5. socd_flg_firstRun = true;
  6. }
  7. //-------------------------------------------------------------------------
  8. //---------------------------SOC-------------------------------------------
  9. //-------------------------------------------------------------------------
  10. void SOC(void)
  11. {
  12. static uint16_T socn_pct_battSocEE;
  13. static uint16_T socn_pct_bcuSocEE;
  14. static uint16_T socn_Q_cap;
  15. //
  16. real_T Q;
  17. real_T battcurr;
  18. boolean_T socn_flg_ekfInvalidMin;
  19. boolean_T socn_flg_ekfInvalidMax;
  20. boolean_T socn_flg_ekfInvalidAvrg;
  21. boolean_T socn_flg_ekfInvalid;
  22. real_T ocv;
  23. real_T Ro;
  24. real_T Rp;
  25. real_T RC;
  26. real_T deltU;
  27. real_T UL;
  28. real_T A[4];
  29. real_T B[2];
  30. real_T H[2];
  31. real_T K[2];
  32. real_T P1[4];
  33. static real_T P_Min_Delay[4];
  34. static real_T P_Max_Delay[4];
  35. static real_T P_avrg_Delay[4];
  36. real_T soc1;
  37. static real_T soc_Min_Delay;
  38. static real_T soc_Avrg_Delay;
  39. static real_T soc_Max_Delay;
  40. real_T Up1;
  41. static real_T Up_Min_Delay;
  42. static real_T Up_Max_Delay;
  43. static real_T Up_Avrg_Delay;
  44. uint16_T EKFSOCMin;
  45. uint16_T EKFSOCMax;
  46. uint16_T EKFSOCAvrg;
  47. uint16_T cellSocMax;
  48. uint16_T cellSocMin;
  49. uint16_T factor;
  50. //
  51. static real_T ahDelay;
  52. int16_T ahSoc;
  53. //
  54. boolean_T socn_flg_ekfDisable;
  55. static uint16_T ekfInvalidCntl;
  56. static boolean_T onceFlg_est;
  57. static int16_T ahSoc0_est;
  58. static uint16_T ekfSoc0_est;
  59. //
  60. uint16_T socn_V_chrgCCV;
  61. uint16_T socn_V_disChrgCCV;
  62. static boolean_T overFlg;
  63. static boolean_T fulFlg;
  64. static uint16_T overCntl;
  65. static uint16_T fulCntl;
  66. static boolean_T onceFlg_utrckOver;
  67. static int16_T ahSoc0_utrckOver;
  68. static uint16_T estSoc0_utrckOver;
  69. static uint16_T Soc_Delay;
  70. static boolean_T lowFlg;
  71. static uint16_T lowCntl;
  72. static boolean_T onceFlg_utrckLow;
  73. static int16_T ahSoc0_utrckLow;
  74. static uint16_T estSoc0_utrckLow;
  75. uint16_T socn_pct_utrackSoc;
  76. uint16_T socTemp;
  77. //
  78. //
  79. static uint16_T statCntl;
  80. static uint8_T socn_st_workStat_Delay;
  81. static uint16_T socn_pct_battSoc_Delay;
  82. static uint16_T socn_pct_battSoc0;
  83. static uint16_T socn_pct_bcuSoc0;
  84. uint16_T delSOC;
  85. uint16_T bcuSoc;
  86. int16_T coinSoc;
  87. uint16_T x[3];
  88. uint16_T y[3];
  89. boolean_T Flg;
  90. static boolean_T onceFlg_chrg;
  91. static boolean_T onceFlg_dischrg;
  92. static uint16_T socn_pct_battSoc_save;
  93. static uint16_T socn_pct_bcuSoc_save;
  94. uint16_T i;
  95. //
  96. if (socd_flg_firstRun)
  97. {
  98. onceFlg_est = true;
  99. ekfInvalidCntl = 0;
  100. overCntl = 0;
  101. fulCntl = 0;
  102. lowCntl = 0;
  103. overFlg = false;
  104. fulFlg = false;
  105. lowFlg = false;
  106. statCntl = 0;
  107. Soc_Delay = 0;
  108. onceFlg_utrckOver = true;
  109. onceFlg_utrckLow = true;
  110. socn_st_workStat_Delay = 0;
  111. socn_pct_battSoc_Delay = 0;
  112. onceFlg_chrg = true;
  113. onceFlg_dischrg = true;
  114. socn_pct_battSoc_save = 0;
  115. socn_pct_bcuSoc_save = 0;
  116. }
  117. //=====================================================================
  118. ////////////////////////初始值获取/EE校验//////////////////////////////
  119. //=====================================================================
  120. if (socd_flg_firstRun)
  121. { //
  122. if (socd_pct_battSocEi > socc_pct_battSocUp || socd_pct_bcuSocEi > socc_pct_battSocUp || ihd_st_EOLState == 0 ||
  123. (((int16_T)(socd_pct_battSocEi - socd_pct_bcuSocEi) > 300 || (int16_T)(socd_pct_battSocEi - socd_pct_bcuSocEi) < -300) && ihd_tm_parkTime >= cmnc_tm_parkTime && sfmd_I_curr < 10 && sfmd_I_curr > -10))
  124. {
  125. socn_pct_battSocEE = look1_u16tu16(sfmd_V_cellUAvrg, cmnm_V_ocv, cmnm_pct_soc, 13);
  126. socn_pct_bcuSocEE = look1_u16tu16(sfmd_V_cellUAvrg, cmnm_V_ocv, cmnm_pct_soc, 13);
  127. }
  128. else
  129. {
  130. socn_pct_battSocEE = socd_pct_battSocEi;
  131. socn_pct_bcuSocEE = socd_pct_bcuSocEi;
  132. }
  133. //
  134. if (ihd_tm_parkTime >= cmnc_tm_parkTime && sfmd_I_curr < 10 && sfmd_I_curr > -10)
  135. {
  136. socn_pct_battSocEE = look1_u16tu16(sfmd_V_cellUAvrg, cmnm_V_ocv, cmnm_pct_soc, 13);
  137. }
  138. socn_Q_cap = (uint16_T)((uint16_T)((uint32_T)sohd_pct_bcuSoh * cmnc_Q_ratedCp / 2000U) << 1);
  139. }
  140. //printf("1---- battSocEi:%d,bcuSocEi:%d,battSocEE:%d,bcuSocEE:%d\n",socd_pct_battSocEi,socd_pct_bcuSocEi,socn_pct_battSocEE,socn_pct_bcuSocEE);
  141. //======================================================================
  142. ////////////////////////EKFSOC//////////////////////////////////////////
  143. //======================================================================
  144. battcurr = (real_T)sfmd_I_curr * 0.1;
  145. Q = (real_T)socn_Q_cap * 0.1;
  146. //-------------------------EKFmin---------------------------------------
  147. if (socd_flg_firstRun)
  148. {
  149. soc_Min_Delay = (real_T)socn_pct_battSocEE * 0.1;
  150. Up_Min_Delay = 0;
  151. P_Min_Delay[0] = 10;
  152. P_Min_Delay[1] = 0;
  153. P_Min_Delay[2] = 0;
  154. P_Min_Delay[3] = 10;
  155. }
  156. //参数查表
  157. ocv = (real_T)look1_u16tu16((uint16_T)(soc_Min_Delay * 10), cmnm_pct_soc, cmnm_V_ocv, 13) * 0.001;
  158. Ro = (real_T)look1_u16tu16((uint16_T)(soc_Min_Delay * 10), cmnm_pct_soc, cmnm_R_ohm, 13) * 0.001 * 0.001;
  159. Rp = (real_T)look1_u16tu16((uint16_T)(soc_Min_Delay * 10), cmnm_pct_soc, cmnm_R_polar,13) * 0.001 * 0.001;
  160. RC = (real_T)look1_u16tu16((uint16_T)(soc_Min_Delay * 10), cmnm_pct_soc, cmnm_F_polar,13) * 0.001;
  161. A[0] = 1;
  162. A[1] = 0;
  163. A[2] = 0;
  164. A[3] = exp(-1 / RC);
  165. B[0] = 1 / Q / 3600 * 100;
  166. B[1] = Rp * (1 - exp(-1 / RC));
  167. H[0] = docvmath(soc_Min_Delay);
  168. H[1] = 1;
  169. //先验
  170. soc1 = soc_Min_Delay * A[0] + B[0] * battcurr;
  171. Up1 = Up_Min_Delay * A[3] + B[1] * battcurr;
  172. UL = ocv + battcurr * Ro + Up1;
  173. P1[0] = P_Min_Delay[0] + 0.001;
  174. P1[1] = P_Min_Delay[1] * A[3] + 0.001;
  175. P1[2] = P_Min_Delay[2] * A[3] + 0.001;
  176. P1[3] = P_Min_Delay[3] * A[3] * A[3] + 0.001;
  177. //增益
  178. K[0] = (P1[0] * H[0] + P1[2]) / (H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] + 0.5);
  179. K[1] = (P1[1] * H[0] + P1[3]) / (H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] + 0.5);
  180. //后验
  181. deltU = (real_T)sfmd_V_cellUMin * 0.001 - UL;
  182. soc_Min_Delay = soc1 + K[0] * deltU;
  183. soc_Min_Delay = Saturation_r(soc_Min_Delay, (real_T)socc_pct_battSocLow * 0.1, (real_T)socc_pct_battSocUp * 0.1);
  184. Up_Min_Delay = Up1 + K[1] * deltU;
  185. //P更新
  186. P_Min_Delay[0] = (1 - K[0] * H[0]) * P1[0] - K[0] * P1[1];
  187. P_Min_Delay[1] = -K[1] * H[0] * P1[0] + P1[1] * (1 - K[1]);
  188. P_Min_Delay[2] = (1 - K[0] * H[0]) * P1[2] - K[0] * P1[3];
  189. P_Min_Delay[3] = -K[1] * H[0] * P1[2] + P1[3] * (1 - K[1]);
  190. //输出
  191. EKFSOCMin = (uint16_T)(soc_Min_Delay * 10);
  192. socn_flg_ekfInvalidMin = (deltU > 0.02) || (deltU < -0.02);
  193. //printf("2----socmin:%f,U:%d,R:%f\n",soc_Min_Delay,sfmd_V_cellUMin,Ro);
  194. //------------------------EKFSOCmax-----------------------------------
  195. if (socd_flg_firstRun)
  196. {
  197. soc_Max_Delay = (real_T)socn_pct_battSocEE * 0.1;
  198. Up_Max_Delay = 0;
  199. P_Max_Delay[0] = 10;
  200. P_Max_Delay[1] = 0;
  201. P_Max_Delay[2] = 0;
  202. P_Max_Delay[3] = 10;
  203. }
  204. // 参数查表
  205. ocv = (real_T)look1_u16tu16((uint16_T)(soc_Max_Delay * 10), cmnm_pct_soc, cmnm_V_ocv, 13) * 0.001;
  206. Ro = (real_T)look1_u16tu16((uint16_T)(soc_Max_Delay * 10), cmnm_pct_soc, cmnm_R_ohm, 13) * 0.001 * 0.001;
  207. Rp = (real_T)look1_u16tu16((uint16_T)(soc_Max_Delay * 10), cmnm_pct_soc, cmnm_R_polar,13) * 0.001 * 0.001;
  208. RC = (real_T)look1_u16tu16((uint16_T)(soc_Max_Delay * 10), cmnm_pct_soc, cmnm_F_polar,13) * 0.001;
  209. A[0] = 1;
  210. A[1] = 0;
  211. A[2] = 0;
  212. A[3] = exp(-1 / RC);
  213. B[0] = 1 / Q / 3600 * 100;
  214. B[1] = Rp * (1 - exp(-1 / RC));
  215. H[0] = docvmath(soc_Max_Delay);
  216. H[1] = 1;
  217. //先验
  218. soc1 = soc_Max_Delay * A[0] + B[0] * battcurr;
  219. Up1 = Up_Max_Delay * A[3] + B[1] * battcurr;
  220. UL = ocv + battcurr * Ro + Up1;
  221. P1[0] = P_Max_Delay[0] + 0.001;
  222. P1[1] = P_Max_Delay[1] * A[3] + 0.001;
  223. P1[2] = P_Max_Delay[2] * A[3] + 0.002;
  224. P1[3] = P_Max_Delay[3] * A[3] * A[3] + 0.001;
  225. //增益
  226. K[0] = (P1[0] * H[0] + P1[2]) / (H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] + 0.5);
  227. K[1] = (P1[1] * H[0] + P1[3]) / (H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] + 0.5);
  228. //后验
  229. deltU = (real_T)sfmd_V_cellUMax * 0.001 - UL;
  230. soc_Max_Delay = soc1 + K[0] * deltU;
  231. soc_Max_Delay = Saturation_r(soc_Max_Delay, (real_T)socc_pct_battSocLow * 0.1, (real_T)socc_pct_battSocUp * 0.1);
  232. Up_Max_Delay = Up1 + K[1] * deltU;
  233. //P更新
  234. P_Max_Delay[0] = (1 - K[0] * H[0]) * P1[0] - K[0] * P1[1];
  235. P_Max_Delay[1] = -K[1] * H[0] * P1[0] + P1[1] * (1 - K[1]);
  236. P_Max_Delay[2] = (1 - K[0] * H[0]) * P1[2] - K[0] * P1[3];
  237. P_Max_Delay[3] = -K[1] * H[0] * P1[2] + P1[3] * (1 - K[1]);
  238. //输出
  239. EKFSOCMax = (uint16_T)(soc_Max_Delay * 10);
  240. socn_flg_ekfInvalidMax = (deltU > 0.02) || (deltU < -0.02);
  241. //printf("3----socmax:%f,U:%d,R:%f\n\n",soc_Max_Delay,sfmd_V_cellUMax,Ro);
  242. //-----------------------EKFSOC----------------------------------------
  243. socn_flg_ekfInvalid = socn_flg_ekfInvalidMax || socn_flg_ekfInvalidMin;
  244. if (EKFSOCMax > 800)
  245. {
  246. factor = 100;
  247. }
  248. else if (EKFSOCMin < 200)
  249. {
  250. factor = 0;
  251. }
  252. else
  253. {
  254. factor = (uint16_T)(((uint16_T)(((uint32_T)(EKFSOCMin - 200) << 6) / (800 - (EKFSOCMax - EKFSOCMin) - 200)) * 25U) >> 4);
  255. }
  256. socd_pct_ekfSoc = (uint16_T)(((1 - (real_T)(factor * 0.01)) * (real_T)(EKFSOCMin * 0.1) + (real_T)(factor * 0.01) * (real_T)(EKFSOCMax * 0.1)) * 10);
  257. //printf("4----socd_pct_ekfSoc:%d,EKFSOCMax:%d,EKFSOCMin:%d,\n",socd_pct_ekfSoc,EKFSOCMax,EKFSOCMin);
  258. /*
  259. //-------------------------EKFavrg---------------------------------------
  260. if (socd_flg_firstRun)
  261. {
  262. soc_Avrg_Delay = (real_T)socn_pct_battSocEE * 0.1;
  263. Up_Avrg_Delay = 0;
  264. P_avrg_Delay[0] = 10;
  265. P_avrg_Delay[1] = 0;
  266. P_avrg_Delay[2] = 0;
  267. P_avrg_Delay[3] = 10;
  268. }
  269. //参数查表
  270. ocv = (real_T)look1_u16tu16((uint16_T)(soc_Avrg_Delay * 10), cmnm_pct_soc, cmnm_V_ocv, 13) * 0.001;
  271. Ro = (real_T)look1_u16tu16((uint16_T)(soc_Avrg_Delay * 10), cmnm_pct_soc, cmnm_R_ohm, 13) * 0.001 * 0.001;
  272. Rp = (real_T)look1_u16tu16((uint16_T)(soc_Avrg_Delay * 10), cmnm_pct_soc, cmnm_R_polar,13) * 0.001 * 0.001;
  273. RC = (real_T)look1_u16tu16((uint16_T)(soc_Avrg_Delay * 10), cmnm_pct_soc, cmnm_F_polar,13) * 0.001;
  274. A[0] = 1;
  275. A[1] = 0;
  276. A[2] = 0;
  277. A[3] = exp(-1 / RC);
  278. B[0] = 1 / Q / 3600 * 100;
  279. B[1] = Rp * (1 - exp(-1 / RC));
  280. H[0] = docvmath(soc_Avrg_Delay);
  281. H[1] = 1;
  282. //先验
  283. soc1 = soc_Avrg_Delay * A[0] + B[0] * battcurr;
  284. Up1 = Up_Avrg_Delay * A[3] + B[1] * battcurr;
  285. UL = ocv + battcurr * Ro + Up1;
  286. P1[0] = P_avrg_Delay[0] + 0.001;
  287. P1[1] = P_avrg_Delay[1] * A[3] + 0.001;
  288. P1[2] = P_avrg_Delay[2] * A[3] + 0.001;
  289. P1[3] = P_avrg_Delay[3] * A[3] * A[3] + 0.001;
  290. //增益
  291. K[0] = (P1[0] * H[0] + P1[2]) / (H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] + 0.5);
  292. K[1] = (P1[1] * H[0] + P1[3]) / (H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] + 0.5);
  293. //后验
  294. deltU = (real_T)sfmd_V_cellUAvrg * 0.001 - UL;
  295. soc_Avrg_Delay = soc1 + K[0] * deltU;
  296. soc_Avrg_Delay = Saturation_r(soc_Avrg_Delay, (real_T)socc_pct_battSocLow * 0.1, (real_T)socc_pct_battSocUp * 0.1);
  297. Up_Avrg_Delay = Up1 + K[1] * deltU;
  298. //P更新
  299. P_avrg_Delay[0] = (1 - K[0] * H[0]) * P1[0] - K[0] * P1[1];
  300. P_avrg_Delay[1] = -K[1] * H[0] * P1[0] + P1[1] * (1 - K[1]);
  301. P_avrg_Delay[2] = (1 - K[0] * H[0]) * P1[2] - K[0] * P1[3];
  302. P_avrg_Delay[3] = -K[1] * H[0] * P1[2] + P1[3] * (1 - K[1]);
  303. //输出
  304. EKFSOCAvrg = (uint16_T)(soc_Avrg_Delay * 10);
  305. socn_flg_ekfInvalidAvrg = (deltU > 0.01) || (deltU < -0.01);
  306. //printf("4----soc:%f,Up:%f,U:%d,deltU:%f,K[0]:%f,K[1]:%f\n\n",soc_Avrg_Delay,Up_Avrg_Delay,sfmd_V_cellUAvrg,deltU,K[0],K[1]);
  307. //
  308. for(i = 0;i < cmnc_num_cellUNum;i++)
  309. {
  310. socv_pct_cellSoc[i] = look1_u16tu16((look1_u16tu16(EKFSOCAvrg, cmnm_pct_soc, cmnm_V_ocv, 13) + cdmv_V_deltOCV[i]), cmnm_V_ocv, cmnm_pct_soc, 13);
  311. }
  312. socd_flg_cellSocDisable = socn_flg_ekfInvalidAvrg || cdmd_flg_deltOCVDisable;
  313. cellSocMax = ArrMax(socv_pct_cellSoc,cmnc_num_cellUNum);
  314. cellSocMin = ArrMin(socv_pct_cellSoc,cmnc_num_cellUNum);
  315. if (cellSocMax > 800)
  316. {
  317. factor = 100;
  318. }
  319. else if (cellSocMin < 200)
  320. {
  321. factor = 0;
  322. }
  323. else
  324. {
  325. factor = (uint16_T)(((uint16_T)(((uint32_T)(cellSocMin - 200) << 6) / (800 - (cellSocMax - cellSocMin) - 200)) * 25U) >> 4);
  326. }
  327. socd_pct_cellBattSoc = (uint16_T)(((1 - (real_T)(factor * 0.01)) * (real_T)(cellSocMin * 0.1) + (real_T)(factor * 0.01) * (real_T)(cellSocMax * 0.1)) * 10);
  328. */
  329. //======================================================================
  330. ////////////////////////AhSOC//////////////////////////////////////////
  331. //======================================================================
  332. if (socd_flg_firstRun)
  333. {
  334. ahDelay = (real_T)(socn_pct_battSocEE * 0.1);
  335. }
  336. else
  337. {
  338. ahDelay = ahDelay + battcurr / (real_T)(cmnc_Q_ratedCp * 0.1) / 36.0;//cmnc_Q_ratedCp
  339. }
  340. ahSoc = (int16_T)(ahDelay * 10);
  341. socd_pct_ahSoc = Saturation_u(ahSoc < 0 ? 0 : (uint16_T)ahSoc, socc_pct_battSocLow, socc_pct_battSocUp);
  342. //printf("5----ahDelay:%f,ahSoc:%d,battcurr:%f,sfmd_I_curr:%d\n",ahDelay,ahSoc,battcurr,sfmd_I_curr);
  343. //======================================================================
  344. ///////////////////////estSOC//////////////////////////////////////////
  345. //======================================================================
  346. socn_flg_ekfDisable = !JudgeTimeSystem(1,!socn_flg_ekfInvalid,&ekfInvalidCntl,2);
  347. if (socn_flg_ekfDisable)
  348. {
  349. if (onceFlg_est)
  350. {
  351. ahSoc0_est = ahSoc;
  352. ekfSoc0_est = socd_pct_ekfSoc;
  353. onceFlg_est = false;
  354. }
  355. socd_pct_estSoc = (int16_T)(ahSoc - ahSoc0_est + ekfSoc0_est) > 0 ? (uint16_T)(ahSoc - ahSoc0_est + ekfSoc0_est) : 0;
  356. }
  357. else
  358. {
  359. onceFlg_est = true;
  360. socd_pct_estSoc = socd_pct_ekfSoc;
  361. }
  362. socd_pct_estSoc = Saturation_u(socd_pct_estSoc, socc_pct_battSocLow, socc_pct_battSocUp);
  363. //
  364. //printf("6----ahSoc0_est:%d,ekfSoc0_est:%d,socd_pct_estSoc:%d\n",ahSoc0_est,ekfSoc0_est,socd_pct_estSoc);
  365. //======================================================================
  366. ////////////////////////UtrackSOC//////////////////////////////////////////
  367. //======================================================================
  368. if (ihd_st_workStat == 2)
  369. {
  370. lowCntl = 0;
  371. lowFlg = false;
  372. socn_V_chrgCCV = look1_i16tu16(sfmd_I_curr,socm_I_chrgCor,socm_V_chrgCor,3);
  373. overFlg = JudgeTimeSystem(1,sfmd_V_cellUMax >= socn_V_chrgCCV,&overCntl,2) || overFlg;
  374. fulFlg = JudgeTimeSystem(1,sfmd_V_cellUMax >= cmnc_V_chrgFul,&fulCntl ,2) || fulFlg;
  375. //
  376. if (overFlg)
  377. {
  378. if (onceFlg_utrckOver)
  379. {
  380. onceFlg_utrckOver = false;
  381. ahSoc0_utrckOver = ahSoc;
  382. estSoc0_utrckOver = socd_pct_estSoc > socc_pct_chrgCor ? socd_pct_estSoc : socc_pct_chrgCor;
  383. }
  384. socTemp = (uint16_T)(ahSoc - ahSoc0_utrckOver + estSoc0_utrckOver);
  385. }
  386. else
  387. {
  388. onceFlg_utrckOver = true;
  389. socTemp = socd_pct_estSoc > socc_pct_chrgCor ? socc_pct_chrgCor : socd_pct_estSoc;
  390. }
  391. //
  392. socn_pct_utrackSoc = Soc_Delay + (socTemp > Soc_Delay ? (socTemp - Soc_Delay) : 0);
  393. Soc_Delay = socn_pct_utrackSoc;
  394. if (fulFlg)
  395. {
  396. socn_pct_utrackSoc = socc_pct_battSocUp;
  397. }
  398. else
  399. {
  400. socn_pct_utrackSoc = socn_pct_utrackSoc > (socc_pct_battSocUp - 1) ? (socc_pct_battSocUp - 1) : socn_pct_utrackSoc;
  401. }
  402. // printf("7----overCntl:%d,overFlg:%d,fulCntl:%d,fulFlg:%d,ahSoc0_utrckOver:%d,estSoc0_utrckOver:%d,socn_pct_utrackSoc:%d,socTemp:%d\n",overCntl,overFlg,fulCntl,fulFlg,ahSoc0_utrckOver,estSoc0_utrckOver,socn_pct_utrackSoc,socTemp);
  403. }
  404. else
  405. {
  406. Soc_Delay = 0;
  407. overCntl = 0;
  408. overFlg = false;
  409. fulFlg = false;
  410. fulCntl = 0;
  411. if (!pimv_flg_inval[sfmd_idx_cellUMin])
  412. {
  413. socn_V_disChrgCCV = look1_i16tu16(sfmd_I_curr,socm_I_disChrgCor,socm_V_disChrgCor,3) + (uint16_T)(sfmd_I_curr * (pimv_R_cellOhm[sfmd_idx_cellUMin]) * 0.001 * 0.1);
  414. }
  415. else
  416. {
  417. socn_V_disChrgCCV = look1_i16tu16(sfmd_I_curr,socm_I_disChrgCor,socm_V_disChrgCor,3);
  418. }
  419. lowFlg = JudgeTimeSystem(1,sfmd_V_cellUMin <= socn_V_disChrgCCV,&lowCntl,2) || lowFlg;
  420. //
  421. if (lowFlg)
  422. {
  423. if (onceFlg_utrckLow)
  424. {
  425. onceFlg_utrckLow = false;
  426. ahSoc0_utrckLow = ahSoc;
  427. estSoc0_utrckLow = socc_pct_disChrgCor;
  428. }
  429. socn_pct_utrackSoc = (int16_T)(ahSoc - ahSoc0_utrckLow + estSoc0_utrckLow) > 0 ? (uint16_T)(ahSoc - ahSoc0_utrckLow + estSoc0_utrckLow) : 0;
  430. }
  431. else
  432. {
  433. onceFlg_utrckLow = true;
  434. socn_pct_utrackSoc = socd_pct_estSoc < socc_pct_disChrgCor ? socc_pct_disChrgCor : socd_pct_estSoc;
  435. }
  436. //printf("8----lowCntl:%d,lowFlg:%d,ahSoc0_utrckLow:%d,estSoc0_utrckLow:%d,socn_pct_utrackSoc:%d\n",lowCntl,lowFlg,ahSoc0_utrckLow,estSoc0_utrckLow,socn_pct_utrackSoc);
  437. }
  438. socd_pct_battSoc = Saturation_u(socn_pct_utrackSoc, socc_pct_battSocLow, socc_pct_battSocUp);
  439. socd_pct_battSocEo = socd_pct_battSoc;
  440. //===============================================================================================================================================================
  441. ////////////////////////////////////////////////BCUSOC///////////////////////////////////////////////////////////////////////////////////////////////////////////
  442. //===============================================================================================================================================================
  443. Flg = (socd_flg_firstRun || (socn_st_workStat_Delay == 2 && ihd_st_workStat != 2) || (socn_st_workStat_Delay != 2 && ihd_st_workStat == 2) ||
  444. ((int16_T)(socd_pct_battSoc - socn_pct_battSoc_Delay) > 5 || (int16_T)(socd_pct_battSoc - socn_pct_battSoc_Delay) < -5) ||
  445. JudgeTimeSystem(1,sfmd_I_curr < 10 && sfmd_I_curr > -10,&statCntl ,3));
  446. socn_st_workStat_Delay = ihd_st_workStat;
  447. socn_pct_battSoc_Delay = socd_pct_battSoc;
  448. //
  449. if (Flg)
  450. {
  451. socn_pct_battSoc0 = socd_pct_battSoc;
  452. if (socd_flg_firstRun)
  453. {
  454. socn_pct_bcuSoc0 = socn_pct_bcuSocEE;
  455. }
  456. else
  457. {
  458. socn_pct_bcuSoc0 = socd_pct_bcuSoc;
  459. }
  460. }
  461. //
  462. if (ihd_st_workStat == 2)
  463. {
  464. delSOC = socn_pct_battSoc0 > socn_pct_bcuSoc0 ? (socn_pct_battSoc0 - socn_pct_bcuSoc0) : (socn_pct_bcuSoc0 - socn_pct_battSoc0);
  465. coinSoc = (socn_pct_battSoc0 > socn_pct_bcuSoc0 ? socn_pct_battSoc0 : socn_pct_bcuSoc0) + (delSOC > 50 ? 50 : delSOC);
  466. x[0] = socn_pct_battSoc0 > socc_pct_battSocUp - 2 ? socc_pct_battSocUp - 2 : socn_pct_battSoc0;
  467. x[1] = coinSoc > socc_pct_battSocUp - 1 ? socc_pct_battSocUp - 1: (uint16_T)coinSoc;
  468. x[2] = socc_pct_battSocUp;
  469. y[0] = socn_pct_bcuSoc0 > socc_pct_battSocUp - 2 ? socc_pct_battSocUp - 2 : socn_pct_bcuSoc0;;
  470. y[1] = coinSoc > socc_pct_battSocUp - 1 ? socc_pct_battSocUp - 1: (uint16_T)coinSoc;
  471. y[2] = socc_pct_battSocUp;
  472. bcuSoc = look1_u16tu16(socd_pct_battSoc, x, y,3);
  473. //
  474. if (onceFlg_chrg)
  475. {
  476. onceFlg_chrg = false;
  477. onceFlg_dischrg = true;
  478. socd_pct_bcuSoc = bcuSoc;
  479. }
  480. socd_pct_bcuSoc = DataFilt(bcuSoc, &socd_pct_bcuSoc, 1);
  481. //
  482. if (fulFlg)
  483. {
  484. socd_pct_bcuSoc = socc_pct_battSocUp;
  485. }
  486. else
  487. {
  488. socd_pct_bcuSoc = socd_pct_bcuSoc > (socc_pct_battSocUp - 1) ? (socc_pct_battSocUp - 1) : socd_pct_bcuSoc;
  489. }
  490. //printf("10-----x:[%d-%d-%d],y:[%d-%d-%d],battSOC:%d,bcusoc:%d,socd_pct_bcuSoc:%d\n",x[0],x[1],x[2],y[0],y[1],y[2],socd_pct_battSoc,bcuSoc,socd_pct_bcuSoc);
  491. }
  492. else
  493. {
  494. //
  495. delSOC = socn_pct_battSoc0 > socn_pct_bcuSoc0 ? (socn_pct_battSoc0 - socn_pct_bcuSoc0) : (socn_pct_bcuSoc0 - socn_pct_battSoc0);
  496. coinSoc = (int16_T)((socn_pct_battSoc0 < socn_pct_bcuSoc0 ? socn_pct_battSoc0 : socn_pct_bcuSoc0) - (delSOC > 50 ? 50 : delSOC));
  497. x[0] = socc_pct_battSocLow;
  498. x[1] = coinSoc < socc_pct_battSocLow + 1 ? socc_pct_battSocLow + 1 : (uint16_T)coinSoc;
  499. x[2] = socn_pct_battSoc0 < socc_pct_battSocLow + 2 ? socc_pct_battSocLow + 2 : (uint16_T)socn_pct_battSoc0;
  500. y[0] = socc_pct_battSocLow;
  501. y[1] = coinSoc < socc_pct_battSocLow + 1 ? socc_pct_battSocLow + 1 : (uint16_T)coinSoc;
  502. y[2] = socn_pct_bcuSoc0 < socc_pct_battSocLow + 2 ? socc_pct_battSocLow + 2 : (uint16_T)socn_pct_bcuSoc0;
  503. bcuSoc = look1_u16tu16(socd_pct_battSoc, x, y,3);
  504. //
  505. if (onceFlg_dischrg)
  506. {
  507. onceFlg_chrg = true;
  508. onceFlg_dischrg = false;
  509. socd_pct_bcuSoc = bcuSoc;
  510. }
  511. socd_pct_bcuSoc = DataFilt(bcuSoc, &socd_pct_bcuSoc, 1);
  512. //printf("11-----x:[%d-%d-%d],y:[%d-%d-%d],bcusoc:%d,socd_pct_bcuSoc:%d\n",x[0],x[1],x[2],y[0],y[1],y[2],bcuSoc,socd_pct_bcuSoc);
  513. }
  514. socd_pct_bcuSoc = Saturation_u(socd_pct_bcuSoc, socc_pct_battSocLow, socc_pct_battSocUp);
  515. socd_pct_bcuSocEo = socd_pct_bcuSoc;
  516. //=======================================VCUSOC========================================================================================
  517. socd_pct_vcuSoc = (uint16_T)((uint32_T)((socd_pct_bcuSoc - socc_pct_battSocLow) * 1000) / (socc_pct_battSocUp - socc_pct_battSocLow));
  518. //================================================================================================
  519. //------------------EEsave-------------------------------------------=============================
  520. //================================================================================================
  521. if ((int16_T)(socd_pct_battSoc - socn_pct_battSoc_save) > 10 || (int16_T)(socd_pct_battSoc - socn_pct_battSoc_save) < -10 || (int16_T)(socd_pct_bcuSoc - socn_pct_bcuSoc_save) > 10 || (int16_T)(socd_pct_bcuSoc - socn_pct_bcuSoc_save) < -10 )
  522. {
  523. socd_flg_EEsave = 1;
  524. socn_pct_battSoc_save = socd_pct_battSoc;
  525. socn_pct_bcuSoc_save = socd_pct_bcuSoc;
  526. }
  527. else
  528. {
  529. socd_flg_EEsave = 0;
  530. }
  531. socd_flg_firstRun = false;
  532. //printf("\n");
  533. }
  534. //===================================================================================================================
  535. //----------------------------function-------------------------------------------------------------------------------
  536. //===================================================================================================================
  537. real_T docvmath(real_T soc)
  538. {
  539. real_T docv;
  540. docv = ((((((-1.0936E-13 * pow(soc, 7.0) +3.9249E-11 * pow(soc, 6.0)) +
  541. -5.5776E-9 * pow(soc, 5.0)) + 3.996E-7 * pow(soc, 4.0)) +
  542. -1.5332E-5 * pow(soc, 3.0)) +soc * soc * 0.0003192) +
  543. -0.00371 * soc) +0.02732;
  544. return docv;
  545. }
  546. ////
  547. //-------------------------------------------------------------------------