Skip to content

Commit 5859cc9

Browse files
committed
Implement EP_single_pipe brake
1 parent 2759c59 commit 5859cc9

File tree

5 files changed

+76
-17
lines changed

5 files changed

+76
-17
lines changed

Source/Orts.Simulation/Simulation/Physics/Train.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4080,8 +4080,8 @@ public void UnconditionalInitializeBrakes()
40804080
(car.BrakeSystem as AirSinglePipe).EmergencyReservoirPresent = leadAir.EmergencyReservoirPresent;
40814081
}
40824082
}
4083-
else if (lead.BrakeSystem is EPBrakeSystem)
4084-
car.MSTSBrakeSystem = new EPBrakeSystem(car);
4083+
else if (lead.BrakeSystem is EPBrakeSystem ep)
4084+
car.MSTSBrakeSystem = new EPBrakeSystem(car, ep.TwoPipes);
40854085
else if (lead.BrakeSystem is SingleTransferPipe)
40864086
car.MSTSBrakeSystem = new SingleTransferPipe(car);
40874087
else

Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,7 @@ public override void Initialize()
17161716
}
17171717

17181718
// MaximumMainReservoirPipePressurePSI is only used in twin pipe system, and should have a value
1719-
if ((BrakeSystem is AirTwinPipe))
1719+
if (BrakeSystem is AirSinglePipe air && air.TwoPipes)
17201720
{
17211721

17221722
// for airtwinpipe system, make sure that a value is set for it

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Brakes/MSTS/AirSinglePipe.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ public override void Parse(string lowercasetoken, STFReader stf)
457457
case "wagon(ortsemergencydumpvalverate": EmergencyDumpValveRatePSIpS = stf.ReadFloatBlock(STFReader.UNITS.PressureRateDefaultPSIpS, 15f); break;
458458
case "wagon(ortsemergencydumpvalvetimer": EmergencyDumpValveTimerS = stf.ReadFloatBlock(STFReader.UNITS.Time, 120.0f); break;
459459
case "wagon(ortsemergencyquickaction": QuickActionFitted = stf.ReadBoolBlock(false); break;
460-
case "wagon(ortsmainrespipeauxrescharging": MRPAuxResCharging = this is AirTwinPipe && stf.ReadBoolBlock(true); break;
460+
case "wagon(ortsmainrespipeauxrescharging": MRPAuxResCharging = TwoPipes && stf.ReadBoolBlock(true); break;
461461
case "wagon(ortsbrakerelayvalveratio":
462462
RelayValveRatio = stf.ReadFloatBlock(STFReader.UNITS.None, null);
463463
if (RelayValveRatio != 0)

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Brakes/MSTS/EPBrakeSystem.cs

Lines changed: 71 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,21 @@
1919
using System.Collections.Generic;
2020
using ORTS.Common;
2121
using Orts.Parsers.Msts;
22-
using ORTS.Scripting.Api;
2322

2423
namespace Orts.Simulation.RollingStocks.SubSystems.Brakes.MSTS
2524
{
2625

27-
public class EPBrakeSystem : AirTwinPipe
26+
public class EPBrakeSystem : AirSinglePipe
2827
{
2928
bool EPBrakeControlsBrakePipe;
3029
bool EPBrakeActiveInhibitsTripleValve;
3130

32-
public EPBrakeSystem(TrainCar car)
31+
public EPBrakeSystem(TrainCar car, bool twoPipes = true)
3332
: base(car)
3433
{
3534
DebugType = "EP";
35+
TwoPipes = twoPipes;
36+
MRPAuxResCharging = TwoPipes;
3637
}
3738

3839

@@ -69,17 +70,45 @@ public override void Update(float elapsedClockSeconds)
6970
dp = BrakeLine1PressurePSI - targetPressurePSI;
7071
BrakeLine1PressurePSI -= dp;
7172
}
72-
else if (targetPressurePSI > BrakeLine1PressurePSI + 1 && BrakeLine2PressurePSI > targetPressurePSI && Car.Train.BrakeLine4 < 1)
73+
else if (targetPressurePSI > BrakeLine1PressurePSI + 1 && Car.Train.BrakeLine4 < 1)
7374
{
7475
float dp = elapsedClockSeconds * MaxReleaseRatePSIpS / AuxCylVolumeRatio;
7576
if (dp > targetPressurePSI - BrakeLine1PressurePSI)
7677
dp = targetPressurePSI - BrakeLine1PressurePSI;
77-
BrakeLine1PressurePSI += dp;
78-
BrakeLine2PressurePSI -= dp;
78+
if (SupplyReservoirPresent)
79+
{
80+
float ratio = BrakePipeVolumeM3 / SupplyResVolumeM3;
81+
if (BrakeLine1PressurePSI + dp > SupplyResPressurePSI - dp * ratio)
82+
dp = (SupplyResPressurePSI - BrakeLine1PressurePSI) / (1 + ratio);
83+
if (dp < 0)
84+
dp = 0;
85+
SupplyResPressurePSI -= dp * ratio;
86+
BrakeLine1PressurePSI += dp;
87+
}
88+
else if (BrakeValve == BrakeValveType.Distributor && TwoPipes && MRPAuxResCharging)
89+
{
90+
float ratio = 1 / AuxBrakeLineVolumeRatio;
91+
if (BrakeLine1PressurePSI + dp > AuxResPressurePSI - dp * ratio)
92+
dp = (AuxResPressurePSI - BrakeLine1PressurePSI) / (1 + ratio);
93+
if (dp < 0)
94+
dp = 0;
95+
AuxResPressurePSI -= dp * ratio;
96+
BrakeLine1PressurePSI += dp;
97+
}
98+
else if (TwoPipes)
99+
{
100+
if (BrakeLine1PressurePSI + dp > BrakeLine2PressurePSI - dp)
101+
dp = (BrakeLine2PressurePSI - BrakeLine1PressurePSI) / 2;
102+
if (dp < 0)
103+
dp = 0;
104+
BrakeLine2PressurePSI -= dp;
105+
BrakeLine1PressurePSI += dp;
106+
}
79107
}
80108
}
81109
base.Update(elapsedClockSeconds);
82110
HoldingValve = ValveState.Release;
111+
IsolationValve = ValveState.Release;
83112
}
84113
else
85114
{
@@ -114,12 +143,40 @@ public override void Update(float elapsedClockSeconds)
114143
if (AutoCylPressurePSI < demandedAutoCylPressurePSI && !Car.WheelBrakeSlideProtectionActive)
115144
{
116145
float dp = elapsedClockSeconds * ServiceApplicationRatePSIpS;
117-
if (BrakeLine2PressurePSI - (dp * CylBrakeLineVolumeRatio) < AutoCylPressurePSI + dp)
118-
dp = (BrakeLine2PressurePSI - AutoCylPressurePSI) / (1 + CylBrakeLineVolumeRatio);
119146
if (dp > demandedAutoCylPressurePSI - AutoCylPressurePSI)
120147
dp = demandedAutoCylPressurePSI - AutoCylPressurePSI;
121-
BrakeLine2PressurePSI -= dp * CylBrakeLineVolumeRatio;
122-
AutoCylPressurePSI += dp;
148+
if (SupplyReservoirPresent)
149+
{
150+
float displacementSupplyVolumeRatio = AuxResVolumeM3 / AuxCylVolumeRatio / SupplyResVolumeM3;
151+
152+
if (AutoCylPressurePSI + dp > SupplyResPressurePSI - (dp * displacementSupplyVolumeRatio))
153+
dp = (SupplyResPressurePSI - AutoCylPressurePSI) / (1 + displacementSupplyVolumeRatio);
154+
if (dp < 0)
155+
dp = 0;
156+
157+
SupplyResPressurePSI -= dp * displacementSupplyVolumeRatio;
158+
AutoCylPressurePSI += dp;
159+
}
160+
else if (TwoPipes && !MRPAuxResCharging)
161+
{
162+
if (BrakeLine2PressurePSI - (dp * CylBrakeLineVolumeRatio) < AutoCylPressurePSI + dp)
163+
dp = (BrakeLine2PressurePSI - AutoCylPressurePSI) / (1 + CylBrakeLineVolumeRatio);
164+
if (dp < 0)
165+
dp = 0;
166+
167+
BrakeLine2PressurePSI -= dp * CylBrakeLineVolumeRatio;
168+
AutoCylPressurePSI += dp;
169+
}
170+
else
171+
{
172+
if (AuxResPressurePSI - dp / AuxCylVolumeRatio < AutoCylPressurePSI + dp)
173+
dp = (AuxResPressurePSI - AutoCylPressurePSI) * AuxCylVolumeRatio / (1 + AuxCylVolumeRatio);
174+
if (dp < 0)
175+
dp = 0;
176+
177+
AuxResPressurePSI -= dp / AuxCylVolumeRatio;
178+
AutoCylPressurePSI += dp;
179+
}
123180
}
124181
else if (EPBrakeActiveInhibitsTripleValve && AutoCylPressurePSI > demandedAutoCylPressurePSI)
125182
{
@@ -129,7 +186,6 @@ public override void Update(float elapsedClockSeconds)
129186
AutoCylPressurePSI -= dp;
130187
}
131188
}
132-
133189
}
134190

135191
public override void Parse(string lowercasetoken, STFReader stf)
@@ -158,7 +214,9 @@ public override void InitializeFromCopy(BrakeSystem copy)
158214

159215
public override string GetFullStatus(BrakeSystem lastCarBrakeSystem, Dictionary<BrakeSystemComponent, PressureUnit> units)
160216
{
161-
var s = $" {Simulator.Catalog.GetString("BC")} {FormatStrings.FormatPressure(Car.Train.HUDWagonBrakeCylinderPSI, PressureUnit.PSI, units[BrakeSystemComponent.BrakeCylinder], true)}";
217+
string s = "";
218+
if (EPBrakeControlsBrakePipe) s += $" {Simulator.Catalog.GetString("EQ")} {FormatStrings.FormatPressure(Car.Train.EqualReservoirPressurePSIorInHg, PressureUnit.PSI, units[BrakeSystemComponent.EqualizingReservoir], true)}";
219+
s += $" {Simulator.Catalog.GetString("BC")} {FormatStrings.FormatPressure(Car.Train.HUDWagonBrakeCylinderPSI, PressureUnit.PSI, units[BrakeSystemComponent.BrakeCylinder], true)}";
162220
if (HandbrakePercent > 0)
163221
s += $" {Simulator.Catalog.GetString("Handbrake")} {HandbrakePercent:F0}%";
164222
return s;
@@ -167,7 +225,7 @@ public override string GetFullStatus(BrakeSystem lastCarBrakeSystem, Dictionary<
167225
public override void Initialize(bool handbrakeOn, float maxPressurePSI, float fullServPressurePSI, bool immediateRelease)
168226
{
169227
base.Initialize(handbrakeOn, maxPressurePSI, fullServPressurePSI, immediateRelease);
170-
AutoCylPressurePSI = Math.Max(AutoCylPressurePSI, Math.Min(Math.Max(Car.Train.BrakeLine4, 0), 1) * MaxCylPressurePSI);
228+
if (!EPBrakeControlsBrakePipe) AutoCylPressurePSI = Math.Max(AutoCylPressurePSI, Math.Min(Math.Max(Car.Train.BrakeLine4, 0), 1) * ServiceMaxCylPressurePSI);
171229
CylPressurePSI = ForceBrakeCylinderPressure(ref CylAirPSIM3, AutoCylPressurePSI);
172230
}
173231
}

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Brakes/MSTS/MSTSBrakeSystem.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public static BrakeSystem Create(string type, TrainCar car)
3636
case "vacuum_single_pipe": return new VacuumSinglePipe(car);
3737
case "air_twin_pipe": return new AirTwinPipe(car);
3838
case "air_single_pipe": return new AirSinglePipe(car);
39+
case "ep_single_pipe": return new EPBrakeSystem(car, false);
3940
case "ecp":
4041
case "ep": return new EPBrakeSystem(car);
4142
case "sme": return new SMEBrakeSystem(car);

0 commit comments

Comments
 (0)