Advertisement
agmike

TEP70AirScheme

Nov 2nd, 2012
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.92 KB | None | 0 0
  1.  
  2. include "spairscheme.gs"
  3.  
  4.  
  5. class TEP70AirScheme isclass SPAirScheme
  6. {
  7.     public int TB395State = 6;
  8.     public float LB254State = 4.0;
  9.     public bool B367State = false;
  10.     public int B367CombinedValveState = 0; // -1 - connects bp with atm, 1 - normal, 0 - bp off
  11.  
  12.     public float BPAdditionalFlow = 0.0;
  13.  
  14.     // Values for sounds
  15.     public float TB395MRtoBPFlowRate = 0.0;
  16.     public float TB395ERReductorFlowRate = 0.0;
  17.     public float TB395ERStabilizerFlowRate = 0.0;
  18.     public float TB395ERtoAtmFlowRate = 0.0;
  19.     public float TB395BPtoAtmFlowRate = 0.0;
  20.     public float LB254FlowRate = 0.0;
  21.  
  22.     public float TB395ChargePressure = 500.0; // reductor setting
  23.  
  24.     public float TB395EqualizingChargeRate = 12.0;
  25.     public float TB395EqualizingReductionRate = 13.0;
  26.     public float TB395EqualizingThreshold = 4.0;
  27.  
  28.     public float TB395AdditChargeRateI = 4.0;
  29.     public float TB395AdditReductionRateVI = 6.53;
  30.  
  31.     public float TB395ReleaseIIEqualizingPressureK = -3.375;
  32.     public float TB395ReleaseIIEqualizingPressureB = 2187.5;
  33.  
  34.     public float TB395ChargeRate = Math.Rand(0.25, 0.334);
  35.     public float TB395OverchargeReductionRate = Math.Rand(0.0034, 0.005); // stabilizer setting
  36.  
  37.     public float TB395ERDumpRateIII = 0.7;
  38.  
  39.     public float TB395ReductionRateVA = Math.Rand(0.05, 0.067);
  40.     public float TB395ReductionRateV = Math.Rand(0.4, 0.417);
  41.     public float TB395ReductionRateVI = 1.4;
  42.  
  43.     public SPAirNode ERNode = SPAirNodeStatic.New(500.0, 0.02);
  44.     public float ERLeakPressureRate = Math.Rand(0.011, 0.044);
  45.  
  46.     public SPAirNode MRNode = SPAirNodeStatic.New(850.0, 1.04);
  47.     public float MRLeakPressureRate = Math.Rand(0.125, 0.25);
  48.  
  49.     public bool CompressorState = false;
  50.     public float CompressorFlowRate = 5.0;
  51.  
  52.     public SPAirNode BPNode;
  53.     public SPAirNode FBCNode = SPAirNodeStatic.New(0.0, 0.020);
  54.     public SPAirNode[] BCNodes;
  55.  
  56.     public bool LB254Repeater = true;
  57.     public float LB254BufferPressure = 0.0;
  58.     public bool LB254BufferRelease = false;
  59.     public float LB254BufferPressureThreshold = 10.0;
  60.     public float LB254BufferReleasePressureRate = Math.Rand(25.0, 35.0);
  61.     public float LB254MinPressure = Math.Rand(30.0, 40.0);
  62.     public float LB254PressureThreshold = 12.0;
  63.     public float LB254PressureInitial = Math.Rand(100.0, 130.0);
  64.     public float LB254PressureFull = Math.Rand(380.0, 400.0);
  65.  
  66.     public float LB254FeedRate = 0.04 * 350.0 / Math.Rand(3.0, 4.0);
  67.     public float LB254ReleaseRate = 0.04 * 300.0 / Math.Rand(11.0, 13.0);
  68.  
  69.     public SPAirDistributor292_305 AD;
  70.     public SPStandardAirBrakePipe BP;
  71.     public SPStandardAirBrakePipe FP; // Feed Pipe -- питательная магистраль
  72.     public SPStandardAirBrakeCylinder BC1;
  73.     public SPStandardAirBrakeCylinder BC2;
  74.     public SPWireState EPT;
  75.     int bcUpdateFirstIndex = 0;
  76.  
  77.     public float B367CombinedValveReductionRate = 16.0;
  78.  
  79.     final float flowKBrakePipeEqualization(float dP)
  80.     {
  81.         if (dP > TB395EqualizingThreshold)
  82.             return SPAirHelper.FlowSoft(dP - TB395EqualizingThreshold);
  83.         else if (dP < -TB395EqualizingThreshold)
  84.             return SPAirHelper.FlowSoft(dP + TB395EqualizingThreshold);
  85.         return 0.0;
  86.     }
  87.    
  88.     public void Update(float dt)
  89.     {
  90.         AD.Update(dt);
  91.         BP.Update(dt);
  92.         FP.Update(dt);
  93.         BC1.Update(dt);
  94.         BC2.Update(dt);
  95.         BrakeForce = BC1.BrakeForce + BC2.BrakeForce;
  96.        
  97.         TB395MRtoBPFlowRate = 0.0;
  98.         TB395ERReductorFlowRate = 0.0;
  99.         TB395ERStabilizerFlowRate = 0.0;
  100.         TB395ERtoAtmFlowRate = 0.0;
  101.         TB395BPtoAtmFlowRate = 0.0;
  102.         LB254FlowRate = 0.0;
  103.  
  104.         if (CompressorState)
  105.             MRNode.Flow = MRNode.Flow + CompressorFlowRate * dt;
  106.  
  107.         // Train brake lever N 395
  108.         if (B367State) {
  109.             bool tbI   = TB395State == 1;
  110.             bool tbII  = TB395State == 2;
  111.             bool tbIII = TB395State == 3;
  112.             bool tbIV  = TB395State == 4;
  113.             bool tbVA  = TB395State == 51;
  114.             bool tbV   = TB395State == 5;
  115.             bool tbVI  = TB395State == 6;
  116.  
  117.             // tb er
  118.  
  119.             if (tbI) {
  120.                 TB395ERReductorFlowRate = TB395ChargeRate * SPAirHelper.FlowHard(MRNode.Pressure - ERNode.Pressure);
  121.  
  122.                 float flow = TB395ERReductorFlowRate * dt;
  123.                 flow = SPAirHelper.FlowLimit(flow, MRNode.Pressure, MRNode.Volume, ERNode.Pressure, ERNode.Volume);
  124.                 ERNode.Flow = ERNode.Flow + flow;
  125.                 MRNode.Flow = MRNode.Flow - flow;
  126.             }
  127.             else if (tbII) {
  128.                 if (ERNode.Pressure < TB395ChargePressure) {
  129.                     TB395ERReductorFlowRate = TB395ChargeRate * SPAirHelper.FlowHard(MRNode.Pressure - ERNode.Pressure);
  130.  
  131.                     float flow = TB395ERReductorFlowRate * dt;
  132.                     flow = SPAirHelper.FlowLimit(flow, MRNode.Pressure, MRNode.Volume, ERNode.Pressure, ERNode.Volume);
  133.                     ERNode.Flow = ERNode.Flow + flow;
  134.                     MRNode.Flow = MRNode.Flow - flow;
  135.                 }
  136.  
  137.                 TB395ERStabilizerFlowRate = TB395OverchargeReductionRate * SPAirHelper.FlowHard(ERNode.Pressure);
  138.  
  139.                 float flow = TB395ERStabilizerFlowRate * dt;
  140.                 flow = SPAirHelper.FlowLimit(flow, ERNode.Pressure, ERNode.Volume, 0.0);
  141.                 ERNode.Flow = ERNode.Flow - flow;
  142.             }
  143.             else if (tbIII) {
  144.                 if (ERNode.Pressure > BPNode.Pressure and B367CombinedValveState == 1) {
  145.                     float flow = TB395ERDumpRateIII * SPAirHelper.FlowHard(ERNode.Pressure - BPNode.Pressure) * dt;
  146.                     flow = SPAirHelper.FlowLimit(flow, ERNode.Pressure, ERNode.Volume, BPNode.Pressure, BPNode.Volume);
  147.                     BPNode.Flow = BPNode.Flow + flow;
  148.                     ERNode.Flow = ERNode.Flow - flow;
  149.                 }
  150.             }
  151.             else if (tbIV) {
  152.             }
  153.             else {
  154.                 if (tbVA)
  155.                     TB395ERtoAtmFlowRate = TB395ReductionRateVA * SPAirHelper.FlowHard(ERNode.Pressure);
  156.                 else if (tbV)
  157.                     TB395ERtoAtmFlowRate = TB395ReductionRateV * SPAirHelper.FlowHard(ERNode.Pressure);
  158.                 else if (tbVI)
  159.                     TB395ERtoAtmFlowRate = TB395ReductionRateVI * SPAirHelper.FlowHard(ERNode.Pressure);
  160.  
  161.                 float flow = TB395ERtoAtmFlowRate * dt;
  162.                 flow = SPAirHelper.FlowLimit(flow, ERNode.Pressure, ERNode.Volume, 0.0);
  163.  
  164.                 ERNode.Flow = ERNode.Flow - flow;
  165.             }
  166.  
  167.             // equalizing relay
  168.             if (B367CombinedValveState == 1) {
  169.                 float flowMrBp = 0.0;
  170.                 float flowBpAtm = 0.0;
  171.                 float equalizingPressure;
  172.                 if (tbI)
  173.                     equalizingPressure = MRNode.Pressure;
  174.                 else if (tbII) {
  175.                     float eqP = TB395ReleaseIIEqualizingPressureK * ERNode.Pressure + TB395ReleaseIIEqualizingPressureB;
  176.                     equalizingPressure = Math.Fmax(ERNode.Pressure, Math.Fmin(MRNode.Pressure, eqP));
  177.                 }
  178.                 else if (tbVI)
  179.                     equalizingPressure = 0.0;
  180.                 else
  181.                     equalizingPressure = Math.Fmin(ERNode.Pressure, MRNode.Pressure);
  182.  
  183.                 float deltaEq = equalizingPressure - BPNode.Pressure;
  184.                 float flowK = flowKBrakePipeEqualization(deltaEq);
  185.  
  186.                 float flowRateMrBp = TB395EqualizingChargeRate;
  187.                 if (tbI)
  188.                     flowRateMrBp = flowRateMrBp + TB395AdditChargeRateI;
  189.  
  190.                 float flowRateBpAtm = TB395EqualizingReductionRate;
  191.                 if (tbVI)
  192.                     flowRateBpAtm = flowRateBpAtm + TB395AdditReductionRateVI;
  193.  
  194.                 if (deltaEq > 0.0) {
  195.                     TB395MRtoBPFlowRate = flowRateMrBp * flowK;
  196.                     flowMrBp = TB395MRtoBPFlowRate * dt;
  197.                 }
  198.                 else if (deltaEq < 0.0) {
  199.                     TB395BPtoAtmFlowRate = flowRateBpAtm * (-flowK);
  200.                     flowBpAtm = TB395BPtoAtmFlowRate * dt;
  201.                 }
  202.  
  203.                 //flowMrBp = SPAirHelper.FlowLimit(flowMrBp, BPNode.Pressure, BPNode.Volume, equalizingPressure);
  204.                 flowMrBp = SPAirHelper.FlowLimit(flowMrBp, MRNode.Pressure, MRNode.Volume, BPNode.Pressure, BPNode.Volume);
  205.                 //flowBpAtm = SPAirHelper.FlowLimit(flowBpAtm, BPNode.Pressure, BPNode.Volume, equalizingPressure);
  206.                 flowBpAtm = SPAirHelper.FlowLimit(flowBpAtm, BPNode.Pressure, BPNode.Volume, 0.0);
  207.  
  208.                 BPNode.Flow = BPNode.Flow + flowMrBp - flowBpAtm;
  209.                 MRNode.Flow = MRNode.Flow - flowMrBp;
  210.             }
  211.         }
  212.  
  213.         if (B367CombinedValveState == -1) {
  214.             TB395BPtoAtmFlowRate = B367CombinedValveReductionRate * SPAirHelper.FlowSoft(BPNode.Pressure);
  215.  
  216.             float flow = TB395BPtoAtmFlowRate * dt;
  217.             flow = SPAirHelper.FlowLimit(flow, BPNode.Pressure, BPNode.Volume, 0.0);
  218.             BPNode.Flow = BPNode.Flow - flow;
  219.         }
  220.  
  221.         // Locomotive brake lever
  222.         if (B367State) {
  223.             if (!LB254BufferRelease)
  224.                 LB254BufferPressure = FBCNode.Pressure;
  225.  
  226.             float independentPressure = 0.0;
  227.  
  228.             if (LB254State > 1.0)
  229.                 independentPressure = (LB254PressureFull - LB254PressureInitial) / 3.0 * (LB254State - 1.0) + LB254PressureInitial;
  230.             else if (LB254State > 0.0)
  231.                 independentPressure = LB254PressureInitial * LB254State;
  232.  
  233.             if (independentPressure < LB254MinPressure)
  234.                 independentPressure = 0.0;
  235.  
  236.             float bcTargetPressure = Math.Fmin(MRNode.Pressure, Math.Fmax(independentPressure, LB254BufferPressure));
  237.  
  238.             LB254FlowRate = 0.0;
  239.  
  240.             int bcIndex = bcUpdateFirstIndex;
  241.             int bcCount = BCNodes.size();
  242.             int i;
  243.             for (i = 0; i < bcCount; ++i, bcIndex = (bcIndex + 1) % bcCount) {
  244.                 SPAirNode bc = BCNodes[bcIndex];
  245.                 float pressureDelta = bcTargetPressure - bc.Pressure;
  246.  
  247.                 if (pressureDelta > LB254PressureThreshold) {
  248.                     LB254FlowRate = LB254FeedRate * SPAirHelper.FlowSoft(pressureDelta);
  249.  
  250.                     float flow = LB254FlowRate * dt;
  251.                     //flow = SPAirHelper.FlowLimit(flow, MRNode.Pressure, MRNode.Volume, bc.Pressure, bc.Volume);
  252.                     bc.Flow = bc.Flow + flow;
  253.                     MRNode.Flow = MRNode.Flow - flow;
  254.                 }
  255.                 else if (pressureDelta < -LB254PressureThreshold) {
  256.                     LB254FlowRate = LB254ReleaseRate * SPAirHelper.FlowSoft(pressureDelta);
  257.  
  258.                     float flow = LB254FlowRate * dt;
  259.                     //flow = SPAirHelper.FlowLimit(flow, bc.Pressure, bc.Volume, 0.0);
  260.                     bc.Flow = bc.Flow + flow;
  261.                 }
  262.                 else if (bcTargetPressure < LB254PressureThreshold) {
  263.                     LB254FlowRate = -LB254ReleaseRate * SPAirHelper.FlowSoft(bc.Pressure);
  264.  
  265.                     float flow = LB254FlowRate * dt;
  266.                     //flow = SPAirHelper.FlowLimit(flow, bc.Pressure, bc.Volume, 0.0);
  267.                     bc.Flow = bc.Flow + flow;
  268.                 }
  269.             }
  270.             bcUpdateFirstIndex = bcIndex;
  271.         }
  272.  
  273.         if (LB254Repeater) {
  274.             if (LB254State == -1.0) {
  275.                 LB254BufferRelease = true;
  276.                 LB254BufferPressure = LB254BufferPressure - LB254BufferReleasePressureRate * SPAirHelper.FlowSoft(LB254BufferPressure) * dt;
  277.                 if (LB254BufferPressure < 0.0f)
  278.                     LB254BufferPressure = 0.0f;
  279.             }
  280.             else if (FBCNode.Pressure <= LB254BufferPressure + LB254BufferPressureThreshold)
  281.                 LB254BufferRelease = false;
  282.         }
  283.  
  284.         ERNode.Flow = ERNode.Flow - ERLeakPressureRate * ERNode.Volume * SPAirHelper.FlowSoft(ERNode.Pressure) * dt;
  285.         MRNode.Flow = MRNode.Flow - MRLeakPressureRate * MRNode.Volume * SPAirHelper.FlowSoft(MRNode.Pressure) * dt;
  286.  
  287.         BPNode.Flow = BPNode.Flow + BPAdditionalFlow;
  288.         BPAdditionalFlow = 0.0;
  289.     }
  290.    
  291.     public void UpdateFinalize()
  292.     {
  293.         inherited();
  294.         BP.UpdateFinalize();
  295.         FP.UpdateFinalize();
  296.         AD.UpdateFinalize();
  297.         BC1.UpdateFinalize();
  298.         BC2.UpdateFinalize();
  299.         ERNode.Update();
  300.         MRNode.Update();
  301.         FBCNode.Update();
  302.     }
  303.    
  304.     public void Init(SPVehicle owner)
  305.     {
  306.         inherited(owner);
  307.        
  308.         BC1.Init(owner);
  309.         BC2.Init(owner);
  310.         BP.Init(owner);
  311.         FP.Init(owner);
  312.        
  313.         AD.BCNode = FBCNode;
  314.         AD.BPNode = BPNode = BP.Node;
  315.         AD.Init(owner);
  316.        
  317.         BCNodes = new SPAirNode[2];
  318.         BCNodes[0] = BC1.Node;
  319.         BCNodes[1] = BC2.Node;
  320.     }
  321. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement