Skip to content

Commit d06a7b6

Browse files
authored
Merge pull request #829 from cesarBLG/emergency-valves
Improvements for air brakes #3 - Emergency valves
2 parents 55f992d + 434af02 commit d06a7b6

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

Source/Documentation/Manual/physics.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2973,6 +2973,8 @@ MaxAuxilaryChargingRate and EmergencyResChargingRate.
29732973
.. index::
29742974
single: BrakePipeVolume
29752975
single: ORTSEmergencyValveActuationRate
2976+
single: ORTSEmergencyDumpValveRate
2977+
single: ORTSEmergencyDumpValveTimer
29762978
single: ORTSMainResPipeAuxResCharging
29772979
single: ORTSMainResChargingRate
29782980
single: ORTSEngineBrakeReleaseRate
@@ -3001,6 +3003,11 @@ MaxAuxilaryChargingRate and EmergencyResChargingRate.
30013003
brake actuation of the triple valve. If the pressure in the brake pipe
30023004
decreases at a higher rate than specified, the triple valve will switch to
30033005
emergency mode.
3006+
- ``Wagon(ORTSEmergencyDumpValveRate)``-- Rate at which BP is locally discharged
3007+
at every wagon during an emergency brake application.
3008+
- ``Wagon(ORTSEmergencyDumpValveTimer)``-- Timer for emergency dump valve to close
3009+
after it is activated. If set to 0, it will close as soon as BP is discharged.
3010+
Default value will prevent BP from being charged for 2 minutes.
30043011
- ``Wagon(ORTSMainResPipeAuxResCharging`` -- Boolean value that indicates,
30053012
for twin pipe systems, if the main reservoir pipe is used for charging the auxiliary
30063013
reservoirs. If set to false, the main reservoir pipe will not be used

Source/Documentation/Manual/sound.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,9 @@ Trigger Function
403403
243 GenericItem2Off
404404
========= =====================================
405405

406+
Trigger 252 is activated when the braking system detects an
407+
emergency brake application and starts venting air from the Brake Pipe.
408+
406409
Variable Triggers
407410
-----------------
408411

Source/Orts.Simulation/Common/Events.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ public enum Event
255255

256256
OverchargeBrakingOn,
257257
OverchargeBrakingOff,
258+
EmergencyVentValveOn,
258259

259260
// Cruise Control
260261
LeverFromZero,
@@ -523,6 +524,7 @@ public static Event From(Source source, int eventID)
523524

524525
case 250: return Event.OverchargeBrakingOn;
525526
case 251: return Event.OverchargeBrakingOff;
527+
case 252: return Event.EmergencyVentValveOn;
526528

527529
// Cruise Control
528530
case 298: return Event.LeverFromZero;

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public class AirSinglePipe : MSTSBrakeSystem
5151
protected float MaxAuxilaryChargingRatePSIpS = 1.684f;
5252
protected float BrakeInsensitivityPSIpS = 0.07f;
5353
protected float EmergencyValveActuationRatePSIpS = 0;
54+
protected float EmergencyDumpValveRatePSIpS = 0;
55+
protected float EmergencyDumpValveTimerS = 120;
56+
protected float? EmergencyDumpStartTime;
5457
protected float EmergResChargingRatePSIpS = 1.684f;
5558
protected float EmergAuxVolumeRatio = 1.4f;
5659
protected string DebugType = string.Empty;
@@ -116,6 +119,8 @@ public override void InitializeFromCopy(BrakeSystem copy)
116119
MaxAuxilaryChargingRatePSIpS = thiscopy.MaxAuxilaryChargingRatePSIpS;
117120
BrakeInsensitivityPSIpS = thiscopy.BrakeInsensitivityPSIpS;
118121
EmergencyValveActuationRatePSIpS = thiscopy.EmergencyValveActuationRatePSIpS;
122+
EmergencyDumpValveRatePSIpS = thiscopy.EmergencyDumpValveRatePSIpS;
123+
EmergencyDumpValveTimerS = thiscopy.EmergencyDumpValveTimerS;
119124
EmergResChargingRatePSIpS = thiscopy.EmergResChargingRatePSIpS;
120125
EmergAuxVolumeRatio = thiscopy.EmergAuxVolumeRatio;
121126
TwoPipes = thiscopy.TwoPipes;
@@ -232,6 +237,8 @@ public override void Parse(string lowercasetoken, STFReader stf)
232237
case "wagon(brakepipevolume": BrakePipeVolumeM3 = Me3.FromFt3(stf.ReadFloatBlock(STFReader.UNITS.VolumeDefaultFT3, null)); break;
233238
case "wagon(ortsbrakeinsensitivity": BrakeInsensitivityPSIpS = stf.ReadFloatBlock(STFReader.UNITS.PressureRateDefaultPSIpS, 0.07f); break;
234239
case "wagon(ortsemergencyvalveactuationrate": EmergencyValveActuationRatePSIpS = stf.ReadFloatBlock(STFReader.UNITS.PressureRateDefaultPSIpS, 15f); break;
240+
case "wagon(ortsemergencydumpvalverate": EmergencyDumpValveRatePSIpS = stf.ReadFloatBlock(STFReader.UNITS.PressureRateDefaultPSIpS, 15f); break;
241+
case "wagon(ortsemergencydumpvalvetimer": EmergencyDumpValveTimerS = stf.ReadFloatBlock(STFReader.UNITS.Time, 120.0f); break;
235242
case "wagon(ortsmainrespipeauxrescharging": MRPAuxResCharging = this is AirTwinPipe && stf.ReadBoolBlock(true); break;
236243
}
237244
}
@@ -307,7 +314,10 @@ public override void Initialize(bool handbrakeOn, float maxPressurePSI, float fu
307314
CylPressurePSI = AutoCylPressurePSI = immediateRelease ? 0 : Math.Min((maxPressurePSI - BrakeLine1PressurePSI) * AuxCylVolumeRatio, MaxCylPressurePSI);
308315
AuxResPressurePSI = Math.Max(TwoPipes ? maxPressurePSI : maxPressurePSI - AutoCylPressurePSI / AuxCylVolumeRatio, BrakeLine1PressurePSI);
309316
if ((Car as MSTSWagon).EmergencyReservoirPresent)
317+
{
310318
EmergResPressurePSI = Math.Max(AuxResPressurePSI, maxPressurePSI);
319+
if (EmergencyValveActuationRatePSIpS == 0) EmergencyValveActuationRatePSIpS = 15;
320+
}
311321
TripleValveState = AutoCylPressurePSI < 1 ? ValveState.Release : ValveState.Lap;
312322
HoldingValve = ValveState.Release;
313323
HandbrakePercent = handbrakeOn & (Car as MSTSWagon).HandBrakePresent ? 100 : 0;
@@ -340,23 +350,25 @@ public override void LocoInitializeMoving() // starting conditions when starting
340350

341351
public void UpdateTripleValveState(float elapsedClockSeconds)
342352
{
353+
var prevState = TripleValveState;
343354
var valveType = (Car as MSTSWagon).BrakeValve;
355+
bool disableGradient = !(Car.Train.LeadLocomotive is MSTSLocomotive) && Car.Train.TrainType != Orts.Simulation.Physics.Train.TRAINTYPE.STATIC;
344356
if (valveType == MSTSWagon.BrakeValveType.Distributor)
345357
{
346358
float targetPressurePSI = (ControlResPressurePSI - BrakeLine1PressurePSI) * AuxCylVolumeRatio;
347-
if (targetPressurePSI > AutoCylPressurePSI && EmergencyValveActuationRatePSIpS > 0 && (prevBrakePipePressurePSI - BrakeLine1PressurePSI) > Math.Max(elapsedClockSeconds, 0.0001f) * EmergencyValveActuationRatePSIpS)
359+
if (!disableGradient && targetPressurePSI > AutoCylPressurePSI && EmergencyValveActuationRatePSIpS > 0 && (prevBrakePipePressurePSI - BrakeLine1PressurePSI) > Math.Max(elapsedClockSeconds, 0.0001f) * EmergencyValveActuationRatePSIpS)
348360
TripleValveState = ValveState.Emergency;
349361
else if (targetPressurePSI < AutoCylPressurePSI - (TripleValveState != ValveState.Release ? 2.2f : 0f)
350362
|| targetPressurePSI < 2.2f) // The latter is a UIC regulation (0.15 bar)
351363
TripleValveState = ValveState.Release;
352364
else if (TripleValveState != ValveState.Emergency && targetPressurePSI > AutoCylPressurePSI + (TripleValveState != ValveState.Apply ? 2.2f : 0f))
353365
TripleValveState = ValveState.Apply;
354-
else
366+
else if (TripleValveState != ValveState.Emergency)
355367
TripleValveState = ValveState.Lap;
356368
}
357369
else if (valveType == MSTSWagon.BrakeValveType.TripleValve || valveType == MSTSWagon.BrakeValveType.DistributingValve)
358370
{
359-
if (BrakeLine1PressurePSI < AuxResPressurePSI - 1 && EmergencyValveActuationRatePSIpS > 0 && (prevBrakePipePressurePSI - BrakeLine1PressurePSI) > Math.Max(elapsedClockSeconds, 0.0001f) * EmergencyValveActuationRatePSIpS)
371+
if (!disableGradient && BrakeLine1PressurePSI < AuxResPressurePSI - 1 && EmergencyValveActuationRatePSIpS > 0 && (prevBrakePipePressurePSI - BrakeLine1PressurePSI) > Math.Max(elapsedClockSeconds, 0.0001f) * EmergencyValveActuationRatePSIpS)
360372
TripleValveState = ValveState.Emergency;
361373
else if (BrakeLine1PressurePSI > AuxResPressurePSI + 1)
362374
TripleValveState = ValveState.Release;
@@ -371,6 +383,15 @@ public void UpdateTripleValveState(float elapsedClockSeconds)
371383
{
372384
TripleValveState = ValveState.Release;
373385
}
386+
if (TripleValveState == ValveState.Emergency)
387+
{
388+
if (prevState != ValveState.Emergency)
389+
{
390+
EmergencyDumpStartTime = (float)Car.Simulator.GameTime;
391+
Car.SignalEvent(Event.EmergencyVentValveOn);
392+
}
393+
}
394+
else EmergencyDumpStartTime = null;
374395
prevBrakePipePressurePSI = BrakeLine1PressurePSI;
375396
}
376397

@@ -440,6 +461,20 @@ public override void Update(float elapsedClockSeconds)
440461
EmergResPressurePSI -= dp;
441462
AuxResPressurePSI += dp * EmergAuxVolumeRatio;
442463
}
464+
if (EmergencyDumpValveTimerS == 0)
465+
{
466+
if (BrakeLine1PressurePSI < 1) EmergencyDumpStartTime = null;
467+
}
468+
else if (Car.Simulator.GameTime - EmergencyDumpStartTime > EmergencyDumpValveTimerS)
469+
{
470+
EmergencyDumpStartTime = null;
471+
}
472+
if (EmergencyDumpValveRatePSIpS > 0 && EmergencyDumpStartTime != null)
473+
{
474+
BrakeLine1PressurePSI -= elapsedClockSeconds * EmergencyDumpValveRatePSIpS;
475+
if (BrakeLine1PressurePSI < 0)
476+
BrakeLine1PressurePSI = 0;
477+
}
443478
}
444479
}
445480

0 commit comments

Comments
 (0)