Advertisement
agmike

Схема ВР292 (без ЭВР305)

Dec 3rd, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.12 KB | None | 0 0
  1. // SPAirDistributor292.airscheme.txt:
  2. // V m 0 0.4
  3. //
  4. // # КДР
  5. // V kdr 0 1
  6. // C mk_kdr m kdr 5mm 0
  7. // C kdr_at kdr at 2.5mm 0
  8. //
  9. // # срывной клапан
  10. // V sk 0 0.5
  11. // C mk_sk m sk 0.8mm 0
  12. // C sk_tc sk tc 5mm 0
  13. // C mk_at_sk m at 6.5mm 0
  14. //
  15. // # МК - ЗК - ЗР
  16. // C mk_zk m zk 1 0
  17. // V zk 0 0.4
  18. // V zr 0 0.4
  19. // C zk zr 9mm
  20. //
  21. // # ТЦ
  22. // V tc 0 0.4
  23. // C zk_tc zk tc 4mm 0    # ЗК - ТЦ (служебное)
  24. // C tc_at tc at 1 0      # ТЦ - Ат (отпуск)
  25. // C zk_tc_e zk tc 1 0    # ЗК - ТЦ (экстренное)
  26.  
  27. class SPAirDistributor292 : SPAirObject
  28. {
  29.     readonly static public int ModeK = 0;
  30.     readonly static public int ModeD = 1;
  31.     readonly static public int ModeUV = 2;
  32.     public int Mode = ModeK;
  33.  
  34.     int vM;
  35.     //int vKDR;
  36.     int cMK_KDR;
  37.     int cKDR_AT;
  38.     int vSK;
  39.     int cMK_SK;
  40.     int cSK_TC;
  41.     int cMK_AT_SK;
  42.     int cMK_ZK;
  43.     int vZK;
  44.     //int vZR;
  45.     int vTC;
  46.     int cZK_TC;
  47.     int cTC_AT;
  48.     int cZK_TC_E;
  49.  
  50.     public float ozx;
  51.     public float gzx;
  52.  
  53.     static readonly float SKChargePressure = 40.0f;
  54.     static readonly float SKTriggerPressure = 120.0f;
  55.     static readonly float SKRatio = 2.0f;
  56.  
  57.     public override void Init(SPAirScheme scheme, string objectName)
  58.     {
  59.         vM = scheme.GetObjectReservoirIndex(".m");
  60.         //vKDR = scheme.GetObjectReservoirIndex(".kdr");
  61.         cMK_KDR = scheme.GetObjectConnectionIndex(".mk_kdr");
  62.         cKDR_AT = scheme.GetObjectConnectionIndex(".kdr_at");
  63.         vSK = scheme.GetObjectReservoirIndex(".sk");
  64.         cMK_SK = scheme.GetObjectConnectionIndex(".mk_sk");
  65.         cSK_TC = scheme.GetObjectConnectionIndex(".sk_tc");
  66.         cMK_AT_SK = scheme.GetObjectConnectionIndex(".mk_at_sk");
  67.         cMK_ZK = scheme.GetObjectConnectionIndex(".mk_zk");
  68.         vZK = scheme.GetObjectReservoirIndex(".zk");
  69.         //vZR = scheme.GetObjectReservoirIndex(".zr");
  70.         vTC = scheme.GetObjectReservoirIndex(".tc");
  71.         cZK_TC = scheme.GetObjectConnectionIndex(".zk_tc");
  72.         cTC_AT = scheme.GetObjectConnectionIndex(".tc_at");
  73.         cZK_TC_E = scheme.GetObjectConnectionIndex(".zk_tc_e");
  74.     }
  75.  
  76.     public override void Update(SPAirScheme scheme, float dt)
  77.     {
  78.         float openMK_KDR = 0.0f;
  79.         float openKDR_AT = 0.0f;
  80.         float openMK_SK = 0.0f;
  81.         float openSK_TC = 0.0f;
  82.         float openMK_AT_SK = 0.0f;
  83.         float openMK_ZK = 0.0f;
  84.         float openZK_TC = 0.0f;
  85.         float openTC_AT = 0.0f;
  86.         float openZK_TC_E = 0.0f;
  87.  
  88.  
  89.         // updating holes
  90.         float ozgz_x = ozx - gzx;
  91.  
  92.         bool hole_a1_kdr =               ozgz_x < 4.0;
  93.         bool hole_t_zk = 3.5 < ozgz_x;
  94.         bool hole_s_mk = 6.0 < ozgz_x;
  95.  
  96.         bool hole_mk_zk_3d175 = 1.0 < ozx && ozx < 4.0;
  97.         bool hole_mk_zk_d200 =              ozx <= 1.0;
  98.  
  99.         bool hole_tc3_t = 5.5 < gzx && gzx < 10.5;
  100.         bool hole_tc3_sk = 10.5 <= gzx;
  101.         bool hole_tc2_at = 0.0 <= gzx && gzx < 5.0;
  102.         bool hole_a1_at = 0.0 <= gzx && gzx < 4.0;
  103.         bool hole_kdr_s = 0.0 <= gzx && gzx <= 5.5;
  104.         bool hole_tc_e = 15.0 <= gzx;
  105.         bool hole_kdr_at_o = 13.0 <= gzx;
  106.  
  107.         float mkPressure = scheme.GetPressure(vM);
  108.         float skPressure = scheme.GetPressure(vSK);
  109.         float zkPressure = scheme.GetPressure(vZK);
  110.         float tcPressure = scheme.GetPressure(vTC);
  111.  
  112.         // updating air flow through holes)
  113.  
  114.         if (hole_tc3_sk && Mode != ModeUV)
  115.             openSK_TC = 1.0f;
  116.  
  117.         float skPressureDelta = mkPressure - (skPressure + SKRatio * tcPressure);
  118.         if (skPressureDelta > SKChargePressure) {
  119.             openMK_SK = 1.0f;
  120.             if (skPressureDelta > SKTriggerPressure)
  121.                 openMK_AT_SK = 1.0f;
  122.         }
  123.  
  124.         if (hole_tc_e) {
  125.             if (Mode == ModeK)
  126.                 openZK_TC_E = SPAirHelper.HoleFlow(5.5f);
  127.             else
  128.                 openZK_TC_E = SPAirHelper.HoleFlow(2.5f);
  129.         }
  130.  
  131.         if (hole_mk_zk_3d175)
  132.             openMK_ZK = SPAirHelper.HoleFlow(3 * 1.25f);
  133.         else if (hole_mk_zk_d200)
  134.             openMK_ZK = SPAirHelper.HoleFlow(2.0f);
  135.  
  136.         if (hole_tc2_at) {
  137.             if (Mode == ModeK)
  138.                 openTC_AT = SPAirHelper.HoleFlow(3.0f);
  139.             else
  140.                 openTC_AT = SPAirHelper.HoleFlow(2.5f);
  141.         }
  142.  
  143.         if (hole_t_zk && hole_tc3_t)
  144.             openZK_TC = (ozgz_x - 3.5f) / 4.0f;
  145.         if (hole_s_mk && hole_kdr_s)
  146.             openMK_KDR = 1.0f;
  147.  
  148.         if (hole_a1_at && hole_a1_kdr || hole_kdr_at_o)
  149.             openKDR_AT = 1.0f;
  150.  
  151.         // setting holes
  152.  
  153.         scheme.SetFlowRate(cMK_KDR, openMK_KDR);
  154.         scheme.SetFlowRate(cKDR_AT, openKDR_AT);
  155.         scheme.SetFlowRate(cMK_SK, openMK_SK);
  156.         scheme.SetFlowRate(cSK_TC, openSK_TC);
  157.         scheme.SetFlowRate(cMK_AT_SK, openMK_AT_SK);
  158.         scheme.SetFlowRate(cMK_ZK, openMK_ZK);
  159.         scheme.SetFlowRate(cZK_TC, openZK_TC);
  160.         scheme.SetFlowRate(cTC_AT, openTC_AT);
  161.         scheme.SetFlowRate(cZK_TC_E, openZK_TC_E);
  162.  
  163.         // updating positions
  164.         float ozDelta = zkPressure - mkPressure;
  165.  
  166.         const float ozLeftBuffer = 120.0f;
  167.         const float ozRightBuffer = 40.0f;
  168.         const float ozFriction = 5.0f;
  169.         const float gzFriction = 7.0f;
  170.         const float ozSpeed = 7.5f / 4.0f;
  171.         const float ozgzSpeed = 7.5f / 6.0f;
  172.  
  173.         if (ozDelta > ozFriction)
  174.             ozDelta = ozDelta - ozFriction;
  175.         else if (ozDelta < -ozFriction)
  176.             ozDelta = ozDelta + ozFriction;
  177.         else
  178.             ozDelta = 0.0f;
  179.  
  180.         float ozxNew = ozx + ozDelta * ozSpeed * dt;
  181.  
  182.         bool leftBuffer = false;
  183.         bool rightBuffer = false;
  184.         if (ozxNew < 3.0) {
  185.             if (ozDelta < -ozLeftBuffer) {
  186.                 ozDelta = ozDelta + ozLeftBuffer;
  187.                 leftBuffer = true;
  188.             }
  189.         }
  190.         else if (ozxNew > 15.0) {
  191.             if (ozDelta > ozRightBuffer) {
  192.                 ozDelta = ozDelta - ozRightBuffer;
  193.                 rightBuffer = true;
  194.             }
  195.         }
  196.  
  197.             // collsion between oz and gz
  198.         if (ozxNew < gzx || ozxNew > gzx + 7.5f) {
  199.             float ozgzDelta = 0.0f;
  200.             if (ozDelta > gzFriction)
  201.                 ozgzDelta = ozDelta - gzFriction;
  202.             else if (ozDelta < -gzFriction)
  203.                 ozgzDelta = ozDelta + gzFriction;
  204.             ozxNew = ozx + ozgzDelta * ozgzSpeed * dt;
  205.         }
  206.         else {
  207.             float max = gzx + 7.5f;
  208.             if (ozxNew > max)
  209.                 ozxNew = max;
  210.             else if (ozxNew < gzx)
  211.                 ozxNew = gzx;
  212.         }
  213.  
  214.         // collision with left and right buffer
  215.         if (ozxNew < 3.0 && !leftBuffer)
  216.             ozxNew = 3.0f;
  217.         else if (ozxNew > 15.0 && !rightBuffer)
  218.             ozxNew = 15.0f;
  219.  
  220.         if (ozxNew > 24.0f)
  221.             ozxNew = 24.0f;
  222.         else if (ozxNew < 0.0f)
  223.             ozxNew = 0.0f;
  224.         ozx = ozxNew;
  225.  
  226.         if (ozxNew > gzx + 7.5f)
  227.             gzx = ozx - 7.5f;
  228.         else if (ozxNew < gzx)
  229.             gzx = ozxNew;
  230.     }
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement