Skip to content

Commit 689494b

Browse files
committed
Unify traction-braking interlocking
1 parent f80cfb5 commit 689494b

File tree

6 files changed

+37
-21
lines changed

6 files changed

+37
-21
lines changed

Source/Documentation/Manual/physics.rst

+7-3
Original file line numberDiff line numberDiff line change
@@ -5249,12 +5249,16 @@ the tables below.
52495249
.. index::
52505250
single: DoesBrakeCutPower
52515251
single: BrakeCutsPowerAtBrakeCylinderPressure
5252+
single: ORTSBrakeCutsPowerAtBrakePipePressure
5253+
single: ORTSBrakeRestoresPowerAtBrakePipePressure
52525254

5253-
Two other parameters in the Engine section of the ENG file are used by the TCS:
5255+
Other parameters in the Engine section of the ENG file are used by the braking system to request traction cut-off to the TCS:
52545256

5255-
- ``DoesBrakeCutPower( x )`` sets whether applying brake on the locomotive cuts the traction (1 for enabled, 0 for disabled)
5257+
- ``DoesBrakeCutPower( x )`` sets whether applying brake on the locomotive cuts the traction for air brake system (1 for enabled, 0 for disabled)
5258+
- ``ORTSDoesVacuumBrakeCutPower( x )`` sets whether applying brake on the locomotive cuts the traction for vacuum brake system (1 for enabled, 0 for disabled)
52565259
- ``BrakeCutsPowerAtBrakeCylinderPressure( x )`` sets the minimum pressure in the brake cylinder that cuts the traction (by default 4 PSI)
5257-
5260+
- ``ORTSBrakeCutsPowerAtBrakePipePressure( x )`` sets the maximum pressure in the brake pipe that cuts the traction
5261+
- ``ORTSBrakeRestoresPowerAtBrakePipePressure( x )`` sets the minimum pressure in the brake pipe that restores the traction
52585262

52595263
Train Derailment
52605264
----------------

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,14 @@ internal void AttachToHost(ScriptedTrainControlSystem host)
261261
/// </summary>
262262
public Func<bool> DoesBrakeCutPower;
263263
/// <summary>
264-
/// Train brake pressure value which triggers the power cut-off.
264+
/// Deprecated. Returns positive infinity if traction cutoff is requested by the brake system, and negative infinity if it is not requested
265265
/// </summary>
266-
public Func<float> BrakeCutsPowerAtBrakeCylinderPressureBar;
266+
[Obsolete("BrakeCutsPowerAtBrakeCylinderPressureBar() is deprecated, use BrakeSystemTractionAuthorization instead")]
267+
public float BrakeCutsPowerAtBrakeCylinderPressureBar()
268+
{
269+
return BrakeSystemTractionAuthorization ? float.PositiveInfinity : float.NegativeInfinity;
270+
}
271+
public bool BrakeSystemTractionAuthorization => Host.BrakeSystemTractionAuthorization;
267272
/// <summary>
268273
/// State of the train brake controller.
269274
/// </summary>

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ public enum SlipControlType
296296
public float LargeEjectorBrakePipeChargingRatePSIorInHgpS;
297297
public float ExhausterHighSBPChargingRatePSIorInHgpS; // Rate for Exhauster in high speed mode
298298
public float ExhausterLowSBPChargingRatePSIorInHgpS; // Rate for Exhauster in high speed mode
299-
public bool VacuumBrakeCutoffActivated = false;
300299
public bool BrakeFlagDecrease = false;
301300
public bool BrakeFlagIncrease = false;
302301

@@ -1799,17 +1798,17 @@ public override void Initialize()
17991798

18001799
}
18011800

1802-
if (DoesBrakeCutPower && BrakeCutsPowerAtBrakePipePressurePSI > BrakeRestoresPowerAtBrakePipePressurePSI)
1801+
if ((DoesBrakeCutPower || DoesVacuumBrakeCutPower) && BrakeCutsPowerAtBrakePipePressurePSI > BrakeRestoresPowerAtBrakePipePressurePSI)
18031802
{
18041803
BrakeCutsPowerAtBrakePipePressurePSI = BrakeRestoresPowerAtBrakePipePressurePSI - 1.0f;
18051804

18061805
if (Simulator.Settings.VerboseConfigurationMessages)
18071806
{
1808-
Trace.TraceInformation("BrakeCutsPowerAtBrakePipePressure is greater then BrakeRestoresPowerAtBrakePipePressurePSI, and has been set to value of {0} InHg", Bar.ToInHg(Bar.FromPSI(BrakeCutsPowerAtBrakePipePressurePSI)));
1807+
Trace.TraceInformation("BrakeCutsPowerAtBrakePipePressure is greater then BrakeRestoresPowerAtBrakePipePressure, and has been set to value of {0}", FormatStrings.FormatPressure(BrakeCutsPowerAtBrakePipePressurePSI, PressureUnit.PSI, BrakeSystemPressureUnits[BrakeSystemComponent.BrakePipe], true));
18091808
}
18101809
}
18111810

1812-
if (DoesBrakeCutPower && (BrakeSystem is VacuumSinglePipe) && (BrakeRestoresPowerAtBrakePipePressurePSI == 0 || BrakeRestoresPowerAtBrakePipePressurePSI > OneAtmospherePSI))
1811+
if (DoesVacuumBrakeCutPower && BrakeSystem is VacuumSinglePipe && (BrakeRestoresPowerAtBrakePipePressurePSI == 0 || BrakeRestoresPowerAtBrakePipePressurePSI > OneAtmospherePSI))
18131812
{
18141813
BrakeRestoresPowerAtBrakePipePressurePSI = Bar.ToPSI(Bar.FromInHg(15.0f)); // Power can be restored once brake pipe rises above 15 InHg
18151814

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

+14
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,18 @@ public void UpdateAngleCockState(bool AngleCockOpen, ref float AngleCockOpenAmou
11601160
}
11611161
}
11621162

1163+
public virtual void UpdateTractionCutoff()
1164+
{
1165+
var locomotive = Car as MSTSLocomotive;
1166+
if (!locomotive.DoesBrakeCutPower) return;
1167+
if (locomotive.BrakeCutsPowerAtBrakePipePressurePSI > 0)
1168+
{
1169+
if (BrakeLine1PressurePSI < locomotive.BrakeCutsPowerAtBrakePipePressurePSI) locomotive.TrainControlSystem.BrakeSystemTractionAuthorization = false;
1170+
else if (BrakeLine1PressurePSI >= locomotive.BrakeRestoresPowerAtBrakePipePressurePSI) locomotive.TrainControlSystem.BrakeSystemTractionAuthorization = true;
1171+
}
1172+
else locomotive.TrainControlSystem.BrakeSystemTractionAuthorization = CylPressurePSI <= locomotive.BrakeCutsPowerAtBrakeCylinderPressurePSI;
1173+
}
1174+
11631175
public override void Update(float elapsedClockSeconds)
11641176
{
11651177
var valveType = BrakeValve;
@@ -1926,6 +1938,8 @@ public override void Update(float elapsedClockSeconds)
19261938
}
19271939

19281940
}
1941+
1942+
if (Car is MSTSLocomotive) UpdateTractionCutoff();
19291943

19301944
// Record HUD display values for brake cylinders depending upon whether they are wagons or locomotives/tenders (which are subject to their own engine brakes)
19311945
if (Car.WagonType == MSTSWagon.WagonTypes.Engine || Car.WagonType == MSTSWagon.WagonTypes.Tender)

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

+3-9
Original file line numberDiff line numberDiff line change
@@ -453,25 +453,19 @@ public override void Update(float elapsedClockSeconds)
453453
float BrakeCutoffPressurePSI = OneAtmospherePSI - lead.BrakeCutsPowerAtBrakePipePressurePSI;
454454
float BrakeRestorePressurePSI = OneAtmospherePSI - lead.BrakeRestoresPowerAtBrakePipePressurePSI;
455455

456-
if (lead.DoesVacuumBrakeCutPower)
456+
if (Car is MSTSLocomotive locomotive && locomotive.DoesVacuumBrakeCutPower)
457457
{
458-
459458
// There are three zones of operation - (note logic reversed - O InHg = 14.73psi, and eg 21 InHg = 4.189psi)
460459
// Cutoff - exceeds set value, eg 12.5InHg (= 8.5psi)
461460
// Between cutoff and restore levels - only if cutoff has triggerd
462461
// Restore - when value exceeds set value, eg 17InHg (= 6.36 psi) - resets throttle
463462
if (BrakeLine1PressurePSI < BrakeRestorePressurePSI)
464463
{
465-
lead.VacuumBrakeCutoffActivated = false;
464+
locomotive.TrainControlSystem.BrakeSystemTractionAuthorization = true;
466465
}
467466
else if (BrakeLine1PressurePSI > BrakeCutoffPressurePSI)
468467
{
469-
lead.MotiveForceN = 0.0f; // ToDO - This is not a good way to do it, better to be added to MotiveForce Update in MSTSLocomotive(s) when PRs Added
470-
lead.VacuumBrakeCutoffActivated = true;
471-
}
472-
else if (lead.VacuumBrakeCutoffActivated)
473-
{
474-
lead.MotiveForceN = 0.0f; // ToDO - This is not a good way to do it, better to be added to MotiveForce Update in MSTSLocomotive(s) when PRs Added
468+
locomotive.TrainControlSystem.BrakeSystemTractionAuthorization = false;
475469
}
476470
}
477471
}

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/TrainControlSystem.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ protected set
152152
public bool TractionAuthorization { get; private set; }
153153
public float MaxThrottlePercent { get; private set; } = 100f;
154154
public bool FullDynamicBrakingOrder { get; private set; }
155+
public bool BrakeSystemTractionAuthorization = true;
155156

156157
public Dictionary<int, float> CabDisplayControls = new Dictionary<int, float>();
157158

@@ -365,8 +366,7 @@ public void Initialize()
365366
Script.TractionAuthorization = () => TractionAuthorization;
366367
Script.BrakePipePressureBar = () => Locomotive.BrakeSystem != null ? Bar.FromPSI(Locomotive.BrakeSystem.BrakeLine1PressurePSI) : float.MaxValue;
367368
Script.LocomotiveBrakeCylinderPressureBar = () => Locomotive.BrakeSystem != null ? Bar.FromPSI(Locomotive.BrakeSystem.GetCylPressurePSI()) : float.MaxValue;
368-
Script.DoesBrakeCutPower = () => Locomotive.DoesBrakeCutPower;
369-
Script.BrakeCutsPowerAtBrakeCylinderPressureBar = () => Bar.FromPSI(Locomotive.BrakeCutsPowerAtBrakeCylinderPressurePSI);
369+
Script.DoesBrakeCutPower = () => Locomotive.DoesBrakeCutPower || Locomotive.DoesVacuumBrakeCutPower;
370370
Script.TrainBrakeControllerState = () => Locomotive.TrainBrakeController.TrainBrakeControllerState;
371371
Script.AccelerationMpSS = () => Locomotive.AccelerationMpSS;
372372
Script.AltitudeM = () => Locomotive.WorldPosition.Location.Y;
@@ -1189,7 +1189,7 @@ public override void Update()
11891189
PowerCut |= ExternalEmergency;
11901190
}
11911191

1192-
SetTractionAuthorization(!DoesBrakeCutPower() || LocomotiveBrakeCylinderPressureBar() < BrakeCutsPowerAtBrakeCylinderPressureBar());
1192+
SetTractionAuthorization(BrakeSystemTractionAuthorization);
11931193

11941194
SetEmergencyBrake(EmergencyBrake);
11951195
SetFullBrake(FullBrake);

0 commit comments

Comments
 (0)