DAM.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #include "DAM.h"
  2. #include <math.h>
  3. #include "rtwtypes.h"
  4. #include "BCUDisp.h"
  5. #include "BCUCal.h"
  6. #include "DAM_private.h"
  7. MdlrefDW_DAM_T DAM_MdlrefDW;
  8. B_DAM_c_T DAM_B;
  9. DW_DAM_f_T DAM_DW;
  10. void DAM_Init(void)
  11. {
  12. DAM_DW.If_ActiveSubsystem = -1;
  13. DAM_DW.UnitDelay_DSTATE_a = true;
  14. }
  15. void DAM_Disable(void)
  16. {
  17. DAM_DW.If_ActiveSubsystem = -1;
  18. }
  19. void DAM(void)
  20. {
  21. real32_T rtb_Product;
  22. real32_T rtb_Product_tmp;
  23. int8_T rtPrevAction;
  24. boolean_T rtb_RelationalOperator;
  25. rtb_RelationalOperator = DAM_DW.UnitDelay_DSTATE_a;
  26. DAM_DW.UnitDelay_DSTATE_a = false;
  27. if (rtb_RelationalOperator) {
  28. uint8_T rtb_Merge10;
  29. if (ihv_flg_EESt[0]) {
  30. DAM_B.Merge = 0.0F;
  31. DAM_B.Merge1 = 0.0F;
  32. DAM_B.Merge2 = 0.0F;
  33. DAM_B.Merge3 = 0.0F;
  34. DAM_B.Merge4 = 0.0F;
  35. DAM_B.Merge5 = 0.0F;
  36. DAM_B.Merge6 = 0.0F;
  37. DAM_B.Merge7 = 0.0F;
  38. DAM_B.Merge11 = 0.0F;
  39. DAM_B.Merge12 = 0.0F;
  40. DAM_B.Merge8 = 0U;
  41. DAM_B.Merge9 = 0U;
  42. DAM_B.Merge13 = 0U;
  43. rtb_Merge10 = 0U;
  44. } else {
  45. DAM_B.Merge = damd_E_totalChrgEngEi;
  46. DAM_B.Merge1 = damd_Q_totalChrgCpEi;
  47. DAM_B.Merge2 = damd_E_totalDisChrgEngEi;
  48. DAM_B.Merge3 = damd_Q_totalDisChrgCpEi;
  49. DAM_B.Merge4 = damd_E_totalRegenEngEi;
  50. DAM_B.Merge5 = damd_Q_totalRegenCpEi;
  51. DAM_B.Merge6 = damd_E_totalVehChrgEngEi;
  52. DAM_B.Merge7 = damd_E_totalSatChrgEngEi;
  53. DAM_B.Merge11 = damd_Q_totalVehChrgCpEi;
  54. DAM_B.Merge12 = damd_Q_totalSatChrgCpEi;
  55. DAM_B.Merge8 = damd_Nr_totalChgEi;
  56. DAM_B.Merge9 = damd_Nr_totalVehChrgEi;
  57. DAM_B.Merge13 = damd_Nr_totalStaChrgEi;
  58. rtb_Merge10 = damd_st_chgCnctObjEi;
  59. }
  60. DAM_B.DataTypeConversion = rtb_Merge10;
  61. }
  62. rtb_Product_tmp = fabsf(ihd_I_battCurr_T2);
  63. rtb_Product = rtb_Product_tmp * ihd_V_battU_T2;
  64. if (dcmd_st_chrgSt_T2 == chrging) {
  65. boolean_T rtb_Switch1_m;
  66. DAM_DW.UnitDelay_DSTATE_d += rtb_Product_tmp;
  67. DAM_DW.UnitDelay1_DSTATE_p += rtb_Product;
  68. rtb_RelationalOperator = (hvmd_st_chgCnctObj_T2 == vehicle);
  69. rtb_Switch1_m = (hvmd_st_chgCnctObj_T2 == chgStation);
  70. DAM_B.Gain_m = DAM_DW.UnitDelay_DSTATE_d * damc_tm_step * 0.000277777785F;
  71. DAM_B.Gain1_b = DAM_DW.UnitDelay1_DSTATE_p * damc_tm_step * 2.77777787E-7F;
  72. DAM_B.Product2 = DAM_B.Gain1_b * (real32_T)rtb_RelationalOperator;
  73. DAM_B.Product3 = DAM_B.Gain1_b * (real32_T)rtb_Switch1_m;
  74. DAM_B.Product4 = DAM_B.Gain_m * (real32_T)rtb_RelationalOperator;
  75. DAM_B.Product5 = DAM_B.Gain_m * (real32_T)rtb_Switch1_m;
  76. } else {
  77. boolean_T rtb_Switch1_m;
  78. rtb_RelationalOperator = (ihd_I_battCurr_T2 < 0.0F);
  79. DAM_DW.UnitDelay1_DSTATE_o += rtb_Product_tmp * (real32_T)
  80. rtb_RelationalOperator;
  81. rtb_Switch1_m = (ihd_I_battCurr_T2 > 0.0F);
  82. DAM_DW.UnitDelay4_DSTATE_g += rtb_Product_tmp * (real32_T)rtb_Switch1_m;
  83. DAM_DW.UnitDelay7_DSTATE_l += rtb_Product * (real32_T)rtb_Switch1_m;
  84. DAM_DW.UnitDelay2_DSTATE_e += rtb_Product * (real32_T)rtb_RelationalOperator;
  85. DAM_B.Gain1_n = DAM_DW.UnitDelay1_DSTATE_o * damc_tm_step * 0.000277777785F;
  86. DAM_B.Gain2 = DAM_DW.UnitDelay4_DSTATE_g * damc_tm_step * 0.000277777785F;
  87. DAM_B.Gain3 = DAM_DW.UnitDelay7_DSTATE_l * damc_tm_step * 2.77777787E-7F;
  88. DAM_B.Gain4 = DAM_DW.UnitDelay2_DSTATE_e * damc_tm_step * 2.77777787E-7F;
  89. }
  90. damd_E_totalChrgEng = DAM_B.Merge + DAM_B.Gain1_b;
  91. damd_E_totalChrgEngEo = damd_E_totalChrgEng;
  92. damd_Q_totalChrgCp = DAM_B.Merge1 + DAM_B.Gain_m;
  93. damd_Q_totalChrgCpEo = damd_Q_totalChrgCp;
  94. DAM_DW.UnitDelay1_DSTATE_k = (uint8_T)((uint32_T)((DAM_DW.UnitDelay_DSTATE_ac ==
  95. noChrg) && (dcmd_st_chrgSt_T2 == chrging)) + DAM_DW.UnitDelay1_DSTATE_k);
  96. rtb_RelationalOperator = (hvmd_st_chgCnctObj_T2 == vehicle);
  97. damd_Nr_totalVehChrg = (uint16_T)(DAM_B.Merge9 + (uint32_T)
  98. (rtb_RelationalOperator ? (int32_T)DAM_DW.UnitDelay1_DSTATE_k : 0));
  99. damd_Nr_totalVehChrgEo = damd_Nr_totalVehChrg;
  100. damd_Q_totalVehChrgCp = DAM_B.Merge11 + DAM_B.Product4;
  101. damd_Q_totalVehChrgCpEo = damd_Q_totalVehChrgCp;
  102. damd_Q_totalSatChrgCp = DAM_B.Merge12 + DAM_B.Product5;
  103. damd_Q_totalSatChrgCpEo = damd_Q_totalSatChrgCp;
  104. damd_E_totalDisChrgEng = DAM_B.Merge2 + DAM_B.Gain3;
  105. damd_E_totalDisChrgEngEo = damd_E_totalDisChrgEng;
  106. damd_Q_totalDisChrgCp = DAM_B.Merge3 + DAM_B.Gain2;
  107. damd_Q_totalDisChrgCpEo = damd_Q_totalDisChrgCp;
  108. damd_E_totalRegenEng = DAM_B.Merge4 + DAM_B.Gain4;
  109. damd_E_totalRegenEngEo = damd_E_totalRegenEng;
  110. damd_Q_totalRegenCp = DAM_B.Merge5 + DAM_B.Gain1_n;
  111. damd_Q_totalRegenCpEo = damd_Q_totalRegenCp;
  112. damd_Nr_totalStaChrg = (uint16_T)((uint32_T)(hvmd_st_chgCnctObj_T2 ==
  113. chgStation ? (int32_T)DAM_DW.UnitDelay1_DSTATE_k : 0) + DAM_B.Merge13);
  114. damd_Nr_totalStaChrgEo = damd_Nr_totalStaChrg;
  115. damd_E_totalVehChrgEng = DAM_B.Merge6 + DAM_B.Product2;
  116. damd_E_totalVehChrgEngEo = damd_E_totalVehChrgEng;
  117. damd_E_totalSatChrgEng = DAM_B.Merge7 + DAM_B.Product3;
  118. damd_E_totalSatChrgEngEo = damd_E_totalSatChrgEng;
  119. damd_Nr_totalChg = (uint16_T)((uint32_T)(rtb_RelationalOperator &&
  120. (DAM_B.DataTypeConversion == chgStation)) + DAM_B.Merge8);
  121. damd_Nr_totalChgEo = damd_Nr_totalChg;
  122. damd_st_chgCnctObjEo = hvmd_st_chgCnctObj_T2;
  123. rtPrevAction = DAM_DW.If_ActiveSubsystem;
  124. DAM_DW.If_ActiveSubsystem = (int8_T)(dcmd_st_chrgSt_T2 != chrging);
  125. if (DAM_DW.If_ActiveSubsystem == 0) {
  126. if (rtPrevAction != 0) {
  127. DAM_DW.UnitDelay_DSTATE_h = 0.0F;
  128. DAM_DW.UnitDelay1_DSTATE_c = 0.0F;
  129. }
  130. DAM_DW.UnitDelay_DSTATE_h += rtb_Product_tmp;
  131. DAM_B.Gain = DAM_DW.UnitDelay_DSTATE_h * damc_tm_step * 0.000277777785F;
  132. DAM_DW.UnitDelay1_DSTATE_c += rtb_Product;
  133. DAM_B.Gain1 = DAM_DW.UnitDelay1_DSTATE_c * damc_tm_step * 2.77777787E-7F;
  134. } else {
  135. if (rtPrevAction != 1) {
  136. DAM_DW.UnitDelay_DSTATE = 0.0F;
  137. DAM_DW.UnitDelay1_DSTATE = 0.0F;
  138. DAM_DW.UnitDelay4_DSTATE = 0.0F;
  139. DAM_DW.UnitDelay5_DSTATE = 0.0F;
  140. DAM_DW.UnitDelay2_DSTATE = 0.0F;
  141. DAM_DW.UnitDelay3_DSTATE = 0.0F;
  142. DAM_DW.UnitDelay6_DSTATE = 0.0F;
  143. DAM_DW.UnitDelay7_DSTATE = 0.0F;
  144. }
  145. DAM_DW.UnitDelay_DSTATE += rtb_Product_tmp;
  146. DAM_DW.UnitDelay1_DSTATE += rtb_Product;
  147. DAM_DW.UnitDelay4_DSTATE += rtb_Product_tmp;
  148. DAM_DW.UnitDelay5_DSTATE += rtb_Product;
  149. if (ihd_I_battCurr_T2 < 0.0F) {
  150. DAM_DW.UnitDelay2_DSTATE = DAM_DW.UnitDelay_DSTATE * damc_tm_step *
  151. 0.000277777785F;
  152. DAM_DW.UnitDelay3_DSTATE = DAM_DW.UnitDelay1_DSTATE * damc_tm_step *
  153. 2.77777787E-7F;
  154. }
  155. if (ihd_I_battCurr_T2 > 0.0F) {
  156. DAM_DW.UnitDelay6_DSTATE = DAM_DW.UnitDelay4_DSTATE * damc_tm_step *
  157. 0.000277777785F;
  158. DAM_DW.UnitDelay7_DSTATE = DAM_DW.UnitDelay5_DSTATE * damc_tm_step *
  159. 2.77777787E-7F;
  160. }
  161. }
  162. damd_Q_chrgCp = DAM_B.Gain;
  163. damd_E_chrgEng = DAM_B.Gain1;
  164. damd_E_disChrgEng = DAM_DW.UnitDelay7_DSTATE;
  165. damd_Q_disChrgCp = DAM_DW.UnitDelay6_DSTATE;
  166. damd_E_regenEng = DAM_DW.UnitDelay3_DSTATE;
  167. damd_Q_regenCp = DAM_DW.UnitDelay2_DSTATE;
  168. DAM_DW.UnitDelay_DSTATE_ac = dcmd_st_chrgSt_T2;
  169. }
  170. void DAM_initialize(const char_T **rt_errorStatus)
  171. {
  172. RT_MODEL_DAM_T *const DAM_M = &(DAM_MdlrefDW.rtm);
  173. rtmSetErrorStatusPointer(DAM_M, rt_errorStatus);
  174. }