Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- SPAirDistributor483.airscheme.txt:
- ## двухкамерный резервуар ##
- V tm 0 0.1
- V zr 0 0.1
- V tc 0 0.1
- V rk 0 6
- V zk 0 6
- ## магистральная часть ##
- V mk 0 0.5 # MK
- C tm mk 12mm #
- V s1 0 0.1 # камера в седле C1
- V kdr 0 0.1 # КДР
- V k 0 0.01 # режимная камера
- C mk_s1_p mk s1 2mm 0 # 2d1.0 в хвостовике плунжера (соединяют МК с ЗК при отпуске)
- C kp s1 zk 3.6mm 0 # клапан плунжера (соединяет ЗК и С1 при торможении)
- C s1_zk_p s1 zk 0.7mm 0 # верхнее отверстие в плунжере (соединяет С1 с ЗК или К)
- C s1_k_p s1 k 0.7mm 0
- C k_zk_p k zk 0.7mm 0 # нижнее отверстие в плунжере (соединяет ЗК и К)
- C chm mk s1 12mm 0 # челночная манжета (соединяет МК с С1 при торможении)
- C dr s1 kdr 4mm 0 # клапан доп. разрядки
- C ak kdr at 0.9mm 0 # атмосферный клапан
- C km mk zk 0.9mm 0 # клапан мягкости
- C rd rk k 0.6mm 0 # режимная диафрагма (соединение РК с К)
- ## главная часть ##
- C tm_zr tm zr 1.3mm 0 # дроссельное отверстие для зарядки ЗР
- C rk_zk rk zk 0.5mm 1 # дроссельное отверстие, соединяющее ЗК и РК
- C zr_tc zr tc 1 0 # отверстие (4d3.0 или d1.7) для наполнения ТЦ
- C kdr_tc kdr tc 12mm 1 # канал КДР - ТЦ - Ат
- C tc_at tc at 2.3mm 1 # ниппель в уравнительном поршне для соединения ТЦ с атмосферой
- C vk rk at 1.5mm 0 # выпускной вентиль (выпуск воздуха из РК и отпуск тормоза)
- */
- class SPAirDistributor483 : SPAirObject
- {
- static readonly public int ModeR = 0;
- static readonly public int ModeG = 1;
- public int Mode = ModeR;
- static readonly public int LoadModeP = 0;
- static readonly public int LoadModeS = 1;
- static readonly public int LoadModeG = 2;
- public int LoadMode = LoadModeG;
- public bool chmOpen = false;
- public bool rdOpen = false;
- public float mdPosition = 4.5f;
- public float gpPosition = 0.0f;
- public float upPosition = 5.0f;
- int vTM;
- int vRK;
- int vZK;
- int vZR;
- int vTC;
- int vMK;
- int vS1;
- int vKDR;
- int vK;
- int cMK_S1_P;
- int cKP;
- int cS1_ZK_P;
- int cS1_K_P;
- int cK_ZK_P;
- int cChM;
- int cDR;
- int cAK;
- int cKM;
- int cRD;
- int cTM_ZR;
- int cRK_ZK;
- int cZR_TC;
- int cKDR_TC;
- int cTC_AT;
- public override void Init(SPAirScheme scheme, string objectName)
- {
- vTM = scheme.GetObjectReservoirIndex(".tm");
- vRK = scheme.GetObjectReservoirIndex(".rk");
- vZK = scheme.GetObjectReservoirIndex(".zk");
- vZR = scheme.GetObjectReservoirIndex(".zr");
- vTC = scheme.GetObjectReservoirIndex(".tc");
- vMK = scheme.GetObjectReservoirIndex(".mk");
- vS1 = scheme.GetObjectReservoirIndex(".s1");
- vKDR = scheme.GetObjectReservoirIndex(".kdr");
- vK = scheme.GetObjectReservoirIndex(".k");
- cMK_S1_P = scheme.GetObjectConnectionIndex(".mk_s1_p");
- cKP = scheme.GetObjectConnectionIndex(".kp");
- cS1_ZK_P = scheme.GetObjectConnectionIndex(".s1_zk_p");
- cS1_K_P = scheme.GetObjectConnectionIndex(".s1_k_p");
- cK_ZK_P = scheme.GetObjectConnectionIndex(".k_zk_p");
- cChM = scheme.GetObjectConnectionIndex(".chm");
- cDR = scheme.GetObjectConnectionIndex(".dr");
- cAK = scheme.GetObjectConnectionIndex(".ak");
- cKM = scheme.GetObjectConnectionIndex(".km");
- cRD = scheme.GetObjectConnectionIndex(".rd");
- cTM_ZR = scheme.GetObjectConnectionIndex(".tm_zr");
- cRK_ZK = scheme.GetObjectConnectionIndex(".rk_zk");
- cZR_TC = scheme.GetObjectConnectionIndex(".zr_tc");
- cKDR_TC = scheme.GetObjectConnectionIndex(".kdr_tc");
- cTC_AT = scheme.GetObjectConnectionIndex(".tc_at");
- }
- public override void Update(SPAirScheme scheme, float dt)
- {
- float openMK_S1_P = 0.0f;
- float openKP = 0.0f;
- float openS1_ZK_P = 0.0f;
- float openS1_K_P = 0.0f;
- float openK_ZK = 0.0f;
- float openChM = 0.0f;
- float openDR = 0.0f;
- float openAK = 0.0f;
- float openKM = 0.0f;
- float openRD = 0.0f;
- float openTM_ZR = 0.0f;
- float openRK_ZK = 0.0f;
- float openZR_TC = 0.0f;
- float openKDR_TC = 0.0f;
- float openTC_AT = 0.0f;
- float kdrPressure = scheme.GetPressure(vKDR);
- float mkPressure = scheme.GetPressure(vMK);
- float zkPressure = scheme.GetPressure(vZK);
- float s1Pressure = scheme.GetPressure(vS1);
- float kPressure = scheme.GetPressure(vK);
- float tmPressure = scheme.GetPressure(vTM);
- float zrPressure = scheme.GetPressure(vZR);
- float rkPressure = scheme.GetPressure(vRK);
- float tcPressure = scheme.GetPressure(vTC);
- // клапан мягкости
- const float kmOpenPressure = 400.0f;
- if (kdrPressure < 40.0f && zkPressure >= kmOpenPressure)
- openKM = 1.0f;
- // челночная манжета
- float chmPressure = mkPressure - s1Pressure;
- const float chmOpenSensivity = 150.0f;
- const float chmCloseSensivity = 10.0f;
- const float chmMinOpenDelta = 10.0f;
- const float chmFullOpenDelta = 60.0f;
- if (chmPressure > chmOpenSensivity)
- chmOpen = true;
- else if (chmPressure < chmCloseSensivity)
- chmOpen = false;
- if (chmOpen) {
- openChM = (chmPressure - chmMinOpenDelta) / chmFullOpenDelta;
- if (openChM > 1.0f)
- openChM = 1.0f;
- }
- // магистральная диафрагма
- float mdTargetPosition = 4.5f;
- float mdPressure = zkPressure - mkPressure;
- // расчет положения МД
- const float mdReleaseMax = 10.0f;
- const float mdBrakeFirstStage = 5.0f;
- const float mdBrakeSecondStage = 10.0f;
- const float mdBrakeThirdStage = 20.0f;
- const float mdBrakeMax = 30.0f;
- if (mdPressure >= mdBrakeMax)
- mdTargetPosition = 0.0f;
- else if (mdPressure < -mdReleaseMax)
- mdTargetPosition = 11.0f;
- else if (mdPressure >= mdBrakeThirdStage) {
- float a = (mdPressure - mdBrakeThirdStage) / (mdBrakeMax - mdBrakeThirdStage);
- mdTargetPosition = 1.5f * a;
- }
- else if (mdPressure >= mdBrakeSecondStage) {
- float a = (mdPressure - mdBrakeSecondStage) / (mdBrakeThirdStage - mdBrakeSecondStage);
- mdTargetPosition = 1.5f * a + (1.0f - a) * 3.0f;
- }
- else if (mdPressure >= mdBrakeFirstStage) {
- float a = (mdPressure - mdBrakeFirstStage)/ (mdBrakeSecondStage - mdBrakeFirstStage);
- mdTargetPosition = 3.0f * a + (1.0f - a) * 4.5f;
- }
- else if (mdPressure < 0.0f) {
- float a = -mdPressure / mdReleaseMax;
- mdTargetPosition = 11.0f * a + (1.0f - a) * 4.5f;
- }
- float mdSpeed = 3.0f ;
- float mdPositionDelta = mdTargetPosition - mdPosition;
- if (mdPositionDelta >= 0.0f) {
- mdPosition = mdPosition + mdSpeed * (float)Math.Sqrt(mdPositionDelta) * dt;
- if (mdPosition > mdTargetPosition)
- mdPosition = mdTargetPosition;
- }
- else {
- mdPosition = mdPosition - mdSpeed * (float)Math.Sqrt(-mdPositionDelta) * dt;
- if (mdPosition < mdTargetPosition)
- mdPosition = mdTargetPosition;
- }
- // открытие клапанов МД
- if (mdPosition < 4.5f) {
- openDR = (4.5f - mdPosition) / 1.5f;
- if (mdPosition < 3.0f) {
- openDR = 1.0f;
- openAK = 1.0f;
- if (mdPosition < 1.5f) {
- openKP = (1.5f - mdPosition) / 1.5f;
- }
- }
- }
- else if (mdPosition >= 6.0f) {
- openK_ZK = 1.0f;
- if (mdPosition >= 6.2f) {
- openMK_S1_P = 1.0f;
- if (mdPosition >= 6.5f) {
- openS1_K_P = 1.0f;
- }
- }
- }
- openS1_ZK_P = 1.0f - openS1_K_P;
- // режимная камера (Р и Г режим отпуска)
- if (Mode == ModeR) {
- const float rdRatioRK = 0.4f;
- const float rdRatioK = 0.6f;
- const float rdOpenPressure = rdRatioK * 350.0f + rdRatioRK * 250.0f;
- const float rdFullOpenDelta = 20.0f;
- float rdPressure = rdRatioK * kPressure + rdRatioRK * rkPressure;
- float rdDelta = rdPressure - rdOpenPressure;
- if (rdDelta > 0.0f) {
- openRD = rdDelta / rdFullOpenDelta;
- if (openRD > 1.0f)
- openRD = 1.0f;
- }
- }
- // главная часть
- // ОК зарядки ЗР
- const float okSensivity = 2.0f;
- if (tmPressure - zrPressure > okSensivity)
- openTM_ZR = 1.0f;
- // положение главного поршня
- const float gpSpeed = 7.0f / 1.0f;
- const float gpMaxPressure = 60.0f;
- const float gpMaxPosition = 23.0f;
- const float gpSpring = gpMaxPressure / gpMaxPosition;
- const float gpSensivity = 2.0f;
- float gpSpringPressure = 15.0f + gpPosition * gpSpring;
- float gpPressure = rkPressure - (zkPressure + gpSpringPressure);
- if (gpPressure > gpSensivity) {
- gpPosition = gpPosition + gpSpeed * (gpPressure - gpSensivity) * dt;
- if (gpPosition > gpMaxPosition)
- gpPosition = gpMaxPosition;
- }
- else if (gpPressure < -gpSensivity) {
- gpPosition = gpPosition + gpSpeed * (gpPressure + gpSensivity) * dt;
- if (gpPosition < 0.0f)
- gpPosition = 0.0f;
- }
- // увеличение объема РК из-за движения главного поршня
- const float gpMaxAddVolume = 0.3f;
- const float rkBaseVolume = 6.0f;
- float rkVolume = scheme.GetVolume(vRK);
- float rkAir = rkPressure * rkVolume;
- rkVolume = rkBaseVolume + gpPosition * gpMaxAddVolume / gpMaxPosition;
- rkPressure = rkAir / rkVolume;
- scheme.SetPressure(vRK, rkPressure);
- scheme.SetVolume(vRK, rkVolume);
- // положение уравнительного поршня
- const float upMinPosition = 5.0f;
- const float upMaxPosition = 23.0f;
- const float upPositionRange = upMaxPosition - upMinPosition;
- const float upMinPressure = 40.0f;
- const float upMaxPressureG = 430.0f;
- const float upMaxPressureP = 170.0f;
- const float upPressureSP = 120.0f;
- float upPressure = tcPressure - upMinPressure;
- if (upPressure > 0.0f) {
- if (LoadMode == LoadModeG)
- upPosition = upMinPosition + upPositionRange * (upPressure / upMaxPressureG);
- else if (LoadMode == LoadModeS) {
- float pressureG = 0.0f;
- float pressureS = upPressure;
- if (pressureS > upPressureSP) {
- pressureG = upPressure - upPressureSP;
- pressureS = upPressureSP;
- }
- upPosition = upMinPosition + upPositionRange * (pressureS / upMaxPressureP + pressureG / upMaxPressureG);
- }
- else
- upPosition = upMinPosition + upPositionRange * (upPressure / upMaxPressureP);
- if (upPosition > upMaxPosition)
- upPosition = upMaxPosition;
- }
- else
- upPosition = upMinPosition;
- // каналы, управляемые главным поршнем
- if (gpPosition < 5.0f) {
- openRK_ZK = 1.0f;
- openKDR_TC = 1.0f;
- }
- // тормозной клапан
- const float tkSensivity = 0.3f;
- float tkDelta = gpPosition - upPosition;
- if (tkDelta > tkSensivity) {
- const float tkFullOpenDelta = 2.0f;
- float tkHole = 12.0f;
- if (gpPosition > 15.0f)
- tkHole = 1.7f;
- float open = (tkDelta - tkSensivity) / tkFullOpenDelta;
- if (open > 1.0f)
- open = 1.0f;
- openZR_TC = open * SPAirHelper.HoleFlow(tkHole);
- }
- else if (tkDelta < -tkSensivity) {
- const float tkFullOpenDelta = 0.5f;
- openTC_AT = (-tkDelta - tkSensivity) / tkFullOpenDelta;
- }
- scheme.SetFlowRate(cMK_S1_P, openMK_S1_P);
- scheme.SetFlowRate(cKP, openKP);
- scheme.SetFlowRate(cS1_ZK_P, openS1_ZK_P);
- scheme.SetFlowRate(cS1_K_P, openS1_K_P);
- scheme.SetFlowRate(cK_ZK_P, openK_ZK);
- scheme.SetFlowRate(cChM, openChM);
- scheme.SetFlowRate(cDR, openDR);
- scheme.SetFlowRate(cAK, openAK);
- scheme.SetFlowRate(cKM, openKM);
- scheme.SetFlowRate(cRD, openRD);
- scheme.SetFlowRate(cTM_ZR, openTM_ZR);
- scheme.SetFlowRate(cRK_ZK, openRK_ZK);
- scheme.SetFlowRate(cZR_TC, openZR_TC);
- scheme.SetFlowRate(cKDR_TC, openKDR_TC);
- scheme.SetFlowRate(cTC_AT, openTC_AT);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement