DAM.c 6.2 KB

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