Skip to content

Commit

Permalink
Implement EP_single_pipe brake
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarBLG committed Dec 21, 2024
1 parent 2759c59 commit 5859cc9
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Source/Orts.Simulation/Simulation/Physics/Train.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4080,8 +4080,8 @@ public void UnconditionalInitializeBrakes()
(car.BrakeSystem as AirSinglePipe).EmergencyReservoirPresent = leadAir.EmergencyReservoirPresent;
}
}
else if (lead.BrakeSystem is EPBrakeSystem)
car.MSTSBrakeSystem = new EPBrakeSystem(car);
else if (lead.BrakeSystem is EPBrakeSystem ep)
car.MSTSBrakeSystem = new EPBrakeSystem(car, ep.TwoPipes);
else if (lead.BrakeSystem is SingleTransferPipe)
car.MSTSBrakeSystem = new SingleTransferPipe(car);
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ public override void Initialize()
}

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

// for airtwinpipe system, make sure that a value is set for it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public override void Parse(string lowercasetoken, STFReader stf)
case "wagon(ortsemergencydumpvalverate": EmergencyDumpValveRatePSIpS = stf.ReadFloatBlock(STFReader.UNITS.PressureRateDefaultPSIpS, 15f); break;
case "wagon(ortsemergencydumpvalvetimer": EmergencyDumpValveTimerS = stf.ReadFloatBlock(STFReader.UNITS.Time, 120.0f); break;
case "wagon(ortsemergencyquickaction": QuickActionFitted = stf.ReadBoolBlock(false); break;
case "wagon(ortsmainrespipeauxrescharging": MRPAuxResCharging = this is AirTwinPipe && stf.ReadBoolBlock(true); break;
case "wagon(ortsmainrespipeauxrescharging": MRPAuxResCharging = TwoPipes && stf.ReadBoolBlock(true); break;
case "wagon(ortsbrakerelayvalveratio":
RelayValveRatio = stf.ReadFloatBlock(STFReader.UNITS.None, null);
if (RelayValveRatio != 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@
using System.Collections.Generic;
using ORTS.Common;
using Orts.Parsers.Msts;
using ORTS.Scripting.Api;

namespace Orts.Simulation.RollingStocks.SubSystems.Brakes.MSTS
{

public class EPBrakeSystem : AirTwinPipe
public class EPBrakeSystem : AirSinglePipe
{
bool EPBrakeControlsBrakePipe;
bool EPBrakeActiveInhibitsTripleValve;

public EPBrakeSystem(TrainCar car)
public EPBrakeSystem(TrainCar car, bool twoPipes = true)
: base(car)
{
DebugType = "EP";
TwoPipes = twoPipes;
MRPAuxResCharging = TwoPipes;
}


Expand Down Expand Up @@ -69,17 +70,45 @@ public override void Update(float elapsedClockSeconds)
dp = BrakeLine1PressurePSI - targetPressurePSI;
BrakeLine1PressurePSI -= dp;
}
else if (targetPressurePSI > BrakeLine1PressurePSI + 1 && BrakeLine2PressurePSI > targetPressurePSI && Car.Train.BrakeLine4 < 1)
else if (targetPressurePSI > BrakeLine1PressurePSI + 1 && Car.Train.BrakeLine4 < 1)
{
float dp = elapsedClockSeconds * MaxReleaseRatePSIpS / AuxCylVolumeRatio;
if (dp > targetPressurePSI - BrakeLine1PressurePSI)
dp = targetPressurePSI - BrakeLine1PressurePSI;
BrakeLine1PressurePSI += dp;
BrakeLine2PressurePSI -= dp;
if (SupplyReservoirPresent)
{
float ratio = BrakePipeVolumeM3 / SupplyResVolumeM3;
if (BrakeLine1PressurePSI + dp > SupplyResPressurePSI - dp * ratio)
dp = (SupplyResPressurePSI - BrakeLine1PressurePSI) / (1 + ratio);
if (dp < 0)
dp = 0;
SupplyResPressurePSI -= dp * ratio;
BrakeLine1PressurePSI += dp;
}
else if (BrakeValve == BrakeValveType.Distributor && TwoPipes && MRPAuxResCharging)
{
float ratio = 1 / AuxBrakeLineVolumeRatio;
if (BrakeLine1PressurePSI + dp > AuxResPressurePSI - dp * ratio)
dp = (AuxResPressurePSI - BrakeLine1PressurePSI) / (1 + ratio);
if (dp < 0)
dp = 0;
AuxResPressurePSI -= dp * ratio;
BrakeLine1PressurePSI += dp;
}
else if (TwoPipes)
{
if (BrakeLine1PressurePSI + dp > BrakeLine2PressurePSI - dp)
dp = (BrakeLine2PressurePSI - BrakeLine1PressurePSI) / 2;
if (dp < 0)
dp = 0;
BrakeLine2PressurePSI -= dp;
BrakeLine1PressurePSI += dp;
}
}
}
base.Update(elapsedClockSeconds);
HoldingValve = ValveState.Release;
IsolationValve = ValveState.Release;
}
else
{
Expand Down Expand Up @@ -114,12 +143,40 @@ public override void Update(float elapsedClockSeconds)
if (AutoCylPressurePSI < demandedAutoCylPressurePSI && !Car.WheelBrakeSlideProtectionActive)
{
float dp = elapsedClockSeconds * ServiceApplicationRatePSIpS;
if (BrakeLine2PressurePSI - (dp * CylBrakeLineVolumeRatio) < AutoCylPressurePSI + dp)
dp = (BrakeLine2PressurePSI - AutoCylPressurePSI) / (1 + CylBrakeLineVolumeRatio);
if (dp > demandedAutoCylPressurePSI - AutoCylPressurePSI)
dp = demandedAutoCylPressurePSI - AutoCylPressurePSI;
BrakeLine2PressurePSI -= dp * CylBrakeLineVolumeRatio;
AutoCylPressurePSI += dp;
if (SupplyReservoirPresent)
{
float displacementSupplyVolumeRatio = AuxResVolumeM3 / AuxCylVolumeRatio / SupplyResVolumeM3;

if (AutoCylPressurePSI + dp > SupplyResPressurePSI - (dp * displacementSupplyVolumeRatio))
dp = (SupplyResPressurePSI - AutoCylPressurePSI) / (1 + displacementSupplyVolumeRatio);
if (dp < 0)
dp = 0;

SupplyResPressurePSI -= dp * displacementSupplyVolumeRatio;
AutoCylPressurePSI += dp;
}
else if (TwoPipes && !MRPAuxResCharging)
{
if (BrakeLine2PressurePSI - (dp * CylBrakeLineVolumeRatio) < AutoCylPressurePSI + dp)
dp = (BrakeLine2PressurePSI - AutoCylPressurePSI) / (1 + CylBrakeLineVolumeRatio);
if (dp < 0)
dp = 0;

BrakeLine2PressurePSI -= dp * CylBrakeLineVolumeRatio;
AutoCylPressurePSI += dp;
}
else
{
if (AuxResPressurePSI - dp / AuxCylVolumeRatio < AutoCylPressurePSI + dp)
dp = (AuxResPressurePSI - AutoCylPressurePSI) * AuxCylVolumeRatio / (1 + AuxCylVolumeRatio);
if (dp < 0)
dp = 0;

AuxResPressurePSI -= dp / AuxCylVolumeRatio;
AutoCylPressurePSI += dp;
}
}
else if (EPBrakeActiveInhibitsTripleValve && AutoCylPressurePSI > demandedAutoCylPressurePSI)
{
Expand All @@ -129,7 +186,6 @@ public override void Update(float elapsedClockSeconds)
AutoCylPressurePSI -= dp;
}
}

}

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

public override string GetFullStatus(BrakeSystem lastCarBrakeSystem, Dictionary<BrakeSystemComponent, PressureUnit> units)
{
var s = $" {Simulator.Catalog.GetString("BC")} {FormatStrings.FormatPressure(Car.Train.HUDWagonBrakeCylinderPSI, PressureUnit.PSI, units[BrakeSystemComponent.BrakeCylinder], true)}";
string s = "";
if (EPBrakeControlsBrakePipe) s += $" {Simulator.Catalog.GetString("EQ")} {FormatStrings.FormatPressure(Car.Train.EqualReservoirPressurePSIorInHg, PressureUnit.PSI, units[BrakeSystemComponent.EqualizingReservoir], true)}";
s += $" {Simulator.Catalog.GetString("BC")} {FormatStrings.FormatPressure(Car.Train.HUDWagonBrakeCylinderPSI, PressureUnit.PSI, units[BrakeSystemComponent.BrakeCylinder], true)}";
if (HandbrakePercent > 0)
s += $" {Simulator.Catalog.GetString("Handbrake")} {HandbrakePercent:F0}%";
return s;
Expand All @@ -167,7 +225,7 @@ public override string GetFullStatus(BrakeSystem lastCarBrakeSystem, Dictionary<
public override void Initialize(bool handbrakeOn, float maxPressurePSI, float fullServPressurePSI, bool immediateRelease)
{
base.Initialize(handbrakeOn, maxPressurePSI, fullServPressurePSI, immediateRelease);
AutoCylPressurePSI = Math.Max(AutoCylPressurePSI, Math.Min(Math.Max(Car.Train.BrakeLine4, 0), 1) * MaxCylPressurePSI);
if (!EPBrakeControlsBrakePipe) AutoCylPressurePSI = Math.Max(AutoCylPressurePSI, Math.Min(Math.Max(Car.Train.BrakeLine4, 0), 1) * ServiceMaxCylPressurePSI);
CylPressurePSI = ForceBrakeCylinderPressure(ref CylAirPSIM3, AutoCylPressurePSI);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static BrakeSystem Create(string type, TrainCar car)
case "vacuum_single_pipe": return new VacuumSinglePipe(car);
case "air_twin_pipe": return new AirTwinPipe(car);
case "air_single_pipe": return new AirSinglePipe(car);
case "ep_single_pipe": return new EPBrakeSystem(car, false);
case "ecp":
case "ep": return new EPBrakeSystem(car);
case "sme": return new SMEBrakeSystem(car);
Expand Down

0 comments on commit 5859cc9

Please sign in to comment.