Skip to content

Commit 19574dd

Browse files
committed
Improve air brake systems
New variant of EP braking where every vehicle modifies BP pressure Better handling of dynamic brake blending
1 parent 35b9498 commit 19574dd

File tree

12 files changed

+212
-107
lines changed

12 files changed

+212
-107
lines changed

Source/Orts.Simulation/Common/Scripting/BrakeController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ public void SetUpdateValue(float value)
222222
/// </summary>
223223
public void SetDynamicBrakeIntervention(float value)
224224
{
225-
// TODO: Set dynamic brake intervention instead of controller position
226-
// There are some issues that need to be identified and fixed before setting the intervention directly
227-
if (Locomotive.DynamicBrakeController == null) return;
228-
Locomotive.DynamicBrakeChangeActiveState(value > 0);
229-
Locomotive.DynamicBrakeController.SetValue(value);
225+
if (value > 0 && Host.TrainDynamicBrakeIntervention <= 0)
226+
Host.TrainDynamicBrakeCommandStartTime = Host.Simulator.ClockTime;
227+
if (value <= 0)
228+
Host.TrainDynamicBrakeIntervention = -1;
229+
else Host.TrainDynamicBrakeIntervention = Math.Min(value, 1);
230230
}
231231

232232
/// <summary>

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

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,14 +1808,12 @@ protected void CorrectBrakingParams()
18081808
/// </summary>
18091809
public void DynamicBrakeBlending(float elapsedClockSeconds)
18101810
{
1811-
if (Math.Abs(SpeedMpS) > DynamicBrakeSpeed1MpS && airPipeSystem != null && ((airPipeSystem is EPBrakeSystem && Train.BrakeLine4 > 0f) || airPipeSystem.BrakeLine1PressurePSI < TrainBrakeController.MaxPressurePSI - 1f)
1812-
&& ThrottleController.CurrentValue == 0f && !(DynamicBrakeController != null && DynamicBrakeBlendingOverride && DynamicBrakeController.CurrentValue > 0f)
1813-
/* && (!DynamicBrakeBlendingLeverOverride && DynamicBrakeController != null && DynamicBrakeIntervention < DynamicBrakeController.CurrentValue)*/)
1811+
// Local blending
1812+
if (Math.Abs(SpeedMpS) > DynamicBrakeSpeed1MpS && airPipeSystem != null && airPipeSystem.AutoCylPressurePSI > 0.1f
1813+
&& ThrottlePercent == 0 && !(DynamicBrakeController != null && DynamicBrakeBlendingOverride && DynamicBrakeController.CurrentValue > 0))
18141814
{
1815-
float threshold = DynamicBrakeBlendingForceMatch ? 100f : 0.01f;
18161815
float maxCylPressurePSI = airPipeSystem.GetMaxCylPressurePSI();
1817-
float targetDynamicBrakePercent = airPipeSystem is EPBrakeSystem ? Train.BrakeLine4 : Math.Min(((TrainBrakeController.MaxPressurePSI - airPipeSystem.BrakeLine1PressurePSI) * airPipeSystem.GetAuxCylVolumeRatio()) / maxCylPressurePSI, 1f);
1818-
//DynamicBrakeIntervention = Math.Min(((TrainBrakeController.CurrentValue - DynamicBrakeBlendingStart) / (DynamicBrakeBlendingStop - DynamicBrakeBlendingStart)), 1f);
1816+
float target = airPipeSystem.AutoCylPressurePSI / maxCylPressurePSI;
18191817

18201818
if (!DynamicBrakeBlended)
18211819
{
@@ -1828,11 +1826,19 @@ public void DynamicBrakeBlending(float elapsedClockSeconds)
18281826
}
18291827
if (DynamicBrake)
18301828
{
1831-
float diff = DynamicBrakeBlendingForceMatch ? targetDynamicBrakePercent * MaxBrakeForceN - DynamicBrakeForceN : targetDynamicBrakePercent - DynamicBrakeIntervention;
1832-
if (diff > threshold && DynamicBrakeIntervention <= 1)
1833-
DynamicBrakeIntervention = Math.Min( DynamicBrakeIntervention + elapsedClockSeconds * (airPipeSystem.GetMaxApplicationRatePSIpS() / maxCylPressurePSI), 1.0f);
1834-
else if (diff < -threshold)
1835-
DynamicBrakeIntervention -= elapsedClockSeconds * (airPipeSystem.GetMaxReleaseRatePSIpS() / maxCylPressurePSI);
1829+
if (DynamicBrakeBlendingForceMatch)
1830+
{
1831+
float diff = target * MaxBrakeForceN - DynamicBrakeForceN;
1832+
float threshold = 100;
1833+
if (diff > threshold && DynamicBrakeIntervention < 1)
1834+
DynamicBrakeIntervention = Math.Min(DynamicBrakeIntervention + elapsedClockSeconds, 1);
1835+
else if (diff < -threshold)
1836+
DynamicBrakeIntervention -= elapsedClockSeconds;
1837+
}
1838+
else
1839+
{
1840+
DynamicBrakeIntervention = target;
1841+
}
18361842
}
18371843
if (DynamicBrakeController != null)
18381844
DynamicBrakeIntervention = Math.Max(DynamicBrakeIntervention, DynamicBrakeController.CurrentValue);
@@ -1842,6 +1848,17 @@ public void DynamicBrakeBlending(float elapsedClockSeconds)
18421848
DynamicBrakeIntervention = -1;
18431849
DynamicBrakeBlended = false;
18441850
}
1851+
// Train blending
1852+
if (IsLeadLocomotive())
1853+
{
1854+
if (TrainBrakeController.TrainDynamicBrakeIntervention > DynamicBrakeIntervention)
1855+
{
1856+
DynamicBrakeBlended = true;
1857+
DynamicBrakeIntervention = TrainBrakeController.TrainDynamicBrakeIntervention;
1858+
}
1859+
if (TrainBrakeController.TrainDynamicBrakeCommandStartTime > DynamicBrakeCommandStartTime)
1860+
DynamicBrakeCommandStartTime = TrainBrakeController.TrainDynamicBrakeCommandStartTime;
1861+
}
18451862
}
18461863

18471864
/// <summary>
@@ -2243,6 +2260,7 @@ protected virtual void UpdateControllers(float elapsedClockSeconds)
22432260
}
22442261

22452262
DynamicBrakeBlending(elapsedClockSeconds);
2263+
22462264
if (DynamicBrakeController != null && DynamicBrakeController.CommandStartTime > DynamicBrakeCommandStartTime) // use the latest command time
22472265
DynamicBrakeCommandStartTime = DynamicBrakeController.CommandStartTime;
22482266

0 commit comments

Comments
 (0)