Skip to content

Commit fb27f31

Browse files
authored
Merge pull request #488 from peternewell/brake-enhancements#5
Correct error introduced that stopped some brake tokens from operating
2 parents f5efd07 + dd82524 commit fb27f31

File tree

2 files changed

+62
-53
lines changed

2 files changed

+62
-53
lines changed

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

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,40 +37,44 @@ public override void Update(float elapsedClockSeconds)
3737
float demandedAutoCylPressurePSI = 0;
3838

3939
// Only allow EP brake tokens to operate if car is connected to an EP system
40-
if (lead != null && lead.BrakeSystem is EPBrakeSystem && Car.BrakeSystem is EPBrakeSystem && (lead.TrainBrakeController.TrainBrakeControllerState == ControllerState.EPFullServ || lead.TrainBrakeController.TrainBrakeControllerState == ControllerState.EPOnly || lead.TrainBrakeController.TrainBrakeControllerState == ControllerState.EPApply))
40+
if (lead == null || !(lead.BrakeSystem is EPBrakeSystem))
4141
{
42+
HoldingValve = ValveState.Release;
43+
base.Update(elapsedClockSeconds);
44+
return;
45+
}
46+
47+
// process valid EP brake tokens
4248

43-
if (BrakeLine3PressurePSI >= 1000f || Car.Train.BrakeLine4 < 0)
44-
{
45-
HoldingValve = ValveState.Release;
46-
}
47-
else if (Car.Train.BrakeLine4 == 0)
48-
{
49-
HoldingValve = ValveState.Lap;
50-
}
51-
else
52-
{
53-
demandedAutoCylPressurePSI = Math.Min(Math.Max(Car.Train.BrakeLine4, 0), 1) * MaxCylPressurePSI;
54-
HoldingValve = AutoCylPressurePSI <= demandedAutoCylPressurePSI ? ValveState.Lap : ValveState.Release;
55-
}
49+
if (BrakeLine3PressurePSI >= 1000f || Car.Train.BrakeLine4 < 0)
50+
{
51+
HoldingValve = ValveState.Release;
52+
}
53+
else if (Car.Train.BrakeLine4 == 0)
54+
{
55+
HoldingValve = ValveState.Lap;
5656
}
57+
else
58+
{
59+
demandedAutoCylPressurePSI = Math.Min(Math.Max(Car.Train.BrakeLine4, 0), 1) * MaxCylPressurePSI;
60+
HoldingValve = AutoCylPressurePSI <= demandedAutoCylPressurePSI ? ValveState.Lap : ValveState.Release;
61+
}
62+
5763

5864
base.Update(elapsedClockSeconds); // Allow processing of other valid tokens
5965

60-
// Only allow EP brake tokens to operate if car is connected to an EP system
61-
if (lead != null && lead.BrakeSystem is EPBrakeSystem && Car.BrakeSystem is EPBrakeSystem && (lead.TrainBrakeController.TrainBrakeControllerState == ControllerState.EPFullServ || lead.TrainBrakeController.TrainBrakeControllerState == ControllerState.EPOnly || lead.TrainBrakeController.TrainBrakeControllerState == ControllerState.EPApply))
66+
67+
if (AutoCylPressurePSI < demandedAutoCylPressurePSI && !Car.WheelBrakeSlideProtectionActive)
6268
{
63-
if (AutoCylPressurePSI < demandedAutoCylPressurePSI && !Car.WheelBrakeSlideProtectionActive)
64-
{
65-
float dp = elapsedClockSeconds * MaxApplicationRatePSIpS;
66-
if (BrakeLine2PressurePSI - dp * AuxBrakeLineVolumeRatio / AuxCylVolumeRatio < AutoCylPressurePSI + dp)
67-
dp = (BrakeLine2PressurePSI - AutoCylPressurePSI) / (1 + AuxBrakeLineVolumeRatio / AuxCylVolumeRatio);
68-
if (dp > demandedAutoCylPressurePSI - AutoCylPressurePSI)
69-
dp = demandedAutoCylPressurePSI - AutoCylPressurePSI;
70-
BrakeLine2PressurePSI -= dp * AuxBrakeLineVolumeRatio / AuxCylVolumeRatio;
71-
AutoCylPressurePSI += dp;
72-
}
69+
float dp = elapsedClockSeconds * MaxApplicationRatePSIpS;
70+
if (BrakeLine2PressurePSI - dp * AuxBrakeLineVolumeRatio / AuxCylVolumeRatio < AutoCylPressurePSI + dp)
71+
dp = (BrakeLine2PressurePSI - AutoCylPressurePSI) / (1 + AuxBrakeLineVolumeRatio / AuxCylVolumeRatio);
72+
if (dp > demandedAutoCylPressurePSI - AutoCylPressurePSI)
73+
dp = demandedAutoCylPressurePSI - AutoCylPressurePSI;
74+
BrakeLine2PressurePSI -= dp * AuxBrakeLineVolumeRatio / AuxCylVolumeRatio;
75+
AutoCylPressurePSI += dp;
7376
}
77+
7478
}
7579

7680
public override string GetFullStatus(BrakeSystem lastCarBrakeSystem, Dictionary<BrakeSystemComponent, PressureUnit> units)

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

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,38 +41,43 @@ public override void Update(float elapsedClockSeconds)
4141
float demandedAutoCylPressurePSI = 0;
4242

4343
// Only allow SME brake tokens to operate if car is connected to an SME system
44-
if (lead != null && lead.BrakeSystem is SMEBrakeSystem && Car.BrakeSystem is SMEBrakeSystem && (lead.TrainBrakeController.TrainBrakeControllerState == ControllerState.SMEFullServ || lead.TrainBrakeController.TrainBrakeControllerState == ControllerState.SMEOnly || lead.TrainBrakeController.TrainBrakeControllerState == ControllerState.SMEReleaseStart || lead.TrainBrakeController.TrainBrakeControllerState == ControllerState.SMESelfLap))
45-
{
46-
if (BrakeLine3PressurePSI >= 1000f || Car.Train.BrakeLine4 < 0)
47-
{
48-
HoldingValve = ValveState.Release;
49-
}
50-
else if (Car.Train.BrakeLine4 == 0)
51-
{
52-
HoldingValve = ValveState.Lap;
53-
}
54-
else
55-
{
56-
demandedAutoCylPressurePSI = Math.Min(Math.Max(Car.Train.BrakeLine4, 0), 1) * MaxCylPressurePSI;
57-
HoldingValve = AutoCylPressurePSI <= demandedAutoCylPressurePSI ? ValveState.Lap : ValveState.Release;
58-
}
44+
if (lead == null || !(lead.BrakeSystem is SMEBrakeSystem))
45+
{
46+
HoldingValve = ValveState.Release;
47+
base.Update(elapsedClockSeconds);
48+
return;
49+
}
50+
51+
// process valid SME brake tokens
52+
53+
if (BrakeLine3PressurePSI >= 1000f || Car.Train.BrakeLine4 < 0)
54+
{
55+
HoldingValve = ValveState.Release;
5956
}
57+
else if (Car.Train.BrakeLine4 == 0)
58+
{
59+
HoldingValve = ValveState.Lap;
60+
}
61+
else
62+
{
63+
demandedAutoCylPressurePSI = Math.Min(Math.Max(Car.Train.BrakeLine4, 0), 1) * MaxCylPressurePSI;
64+
HoldingValve = AutoCylPressurePSI <= demandedAutoCylPressurePSI ? ValveState.Lap : ValveState.Release;
65+
}
66+
6067
base.Update(elapsedClockSeconds); // Allow processing of other valid tokens
6168

62-
// Only allow SME brake tokens to operate if car is connected to an SME system
63-
if (lead != null && lead.BrakeSystem is SMEBrakeSystem && Car.BrakeSystem is SMEBrakeSystem && (lead.TrainBrakeController.TrainBrakeControllerState == ControllerState.SMEFullServ || lead.TrainBrakeController.TrainBrakeControllerState == ControllerState.SMEOnly || lead.TrainBrakeController.TrainBrakeControllerState == ControllerState.SMEReleaseStart || lead.TrainBrakeController.TrainBrakeControllerState == ControllerState.SMESelfLap))
69+
70+
if (AutoCylPressurePSI < demandedAutoCylPressurePSI && !Car.WheelBrakeSlideProtectionActive)
6471
{
65-
if (AutoCylPressurePSI < demandedAutoCylPressurePSI && !Car.WheelBrakeSlideProtectionActive)
66-
{
67-
float dp = elapsedClockSeconds * MaxApplicationRatePSIpS;
68-
if (BrakeLine2PressurePSI - dp * AuxBrakeLineVolumeRatio / AuxCylVolumeRatio < AutoCylPressurePSI + dp)
69-
dp = (BrakeLine2PressurePSI - AutoCylPressurePSI) / (1 + AuxBrakeLineVolumeRatio / AuxCylVolumeRatio);
70-
if (dp > demandedAutoCylPressurePSI - AutoCylPressurePSI)
71-
dp = demandedAutoCylPressurePSI - AutoCylPressurePSI;
72-
BrakeLine2PressurePSI -= dp * AuxBrakeLineVolumeRatio / AuxCylVolumeRatio;
73-
AutoCylPressurePSI += dp;
74-
}
72+
float dp = elapsedClockSeconds * MaxApplicationRatePSIpS;
73+
if (BrakeLine2PressurePSI - dp * AuxBrakeLineVolumeRatio / AuxCylVolumeRatio < AutoCylPressurePSI + dp)
74+
dp = (BrakeLine2PressurePSI - AutoCylPressurePSI) / (1 + AuxBrakeLineVolumeRatio / AuxCylVolumeRatio);
75+
if (dp > demandedAutoCylPressurePSI - AutoCylPressurePSI)
76+
dp = demandedAutoCylPressurePSI - AutoCylPressurePSI;
77+
BrakeLine2PressurePSI -= dp * AuxBrakeLineVolumeRatio / AuxCylVolumeRatio;
78+
AutoCylPressurePSI += dp;
7579
}
80+
7681
}
7782

7883
public override string GetFullStatus(BrakeSystem lastCarBrakeSystem, Dictionary<BrakeSystemComponent, PressureUnit> units)

0 commit comments

Comments
 (0)