Skip to content

Commit b403a51

Browse files
committed
Add distributing valve
1 parent aac9b67 commit b403a51

File tree

5 files changed

+72
-25
lines changed

5 files changed

+72
-25
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ public enum ControllerState
359359
SMEFullServ, // TrainBrakesControllerSMEFullServiceStart
360360
SMESelfLap, // TrainBrakesControllerSMEHoldStart
361361
SMEReleaseStart, // TrainBrakesControllerSMEReleaseStart
362+
HoldEngine, // TrainBrakesControllerHoldEngineStart
363+
BailOff, // EngineBrakesControllerBailOffStart
362364
};
363365

364366
public static class ControllerStateDictionary
@@ -405,7 +407,9 @@ public static class ControllerStateDictionary
405407
{ControllerState.SMEOnly, Catalog.GetString("SME Service")},
406408
{ControllerState.SMEFullServ, Catalog.GetString("SME Full Service")},
407409
{ControllerState.SMESelfLap, Catalog.GetString("SME Self Lap")},
408-
{ControllerState.SMEReleaseStart, Catalog.GetString("SME Release Start")}
410+
{ControllerState.SMEReleaseStart, Catalog.GetString("SME Release Start")},
411+
{ControllerState.HoldEngine, Catalog.GetString("Hold Engine")},
412+
{ControllerState.BailOff, Catalog.GetString("Bail Off")}
409413
};
410414
}
411415
}

Source/Orts.Simulation/Simulation/RollingStocks/MSTSWagon.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ public enum BrakeValveType
226226
None,
227227
TripleValve, // Plain triple valve
228228
Distributor, // Triple valve with graduated release
229+
DistributingValve, // Triple valve + driver brake valve control. Only for locomotives
229230
}
230231
/// <summary>
231232
/// Type of brake valve in the car
@@ -1162,6 +1163,7 @@ public virtual void Parse(string lowercasetoken, STFReader stf)
11621163
case "triple_valve": BrakeValve = BrakeValveType.TripleValve; break;
11631164
case "distributor":
11641165
case "graduated_release_triple_valve": BrakeValve = BrakeValveType.Distributor; break;
1166+
case "distributing_valve": BrakeValve = BrakeValveType.DistributingValve; break;
11651167
case "emergency_brake_reservoir": EmergencyReservoirPresent = true; break;
11661168
case "handbrake": HandBrakePresent = true; break;
11671169
case "auxilary_reservoir": // MSTS legacy parameter - use is discouraged

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

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -517,36 +517,73 @@ public override void Update(float elapsedClockSeconds)
517517
if (AutoCylPressurePSI < 0)
518518
AutoCylPressurePSI = 0;
519519

520-
bool bailoff = false;
520+
if (Car is MSTSLocomotive && (Car as MSTSWagon).BrakeValve == MSTSWagon.BrakeValveType.DistributingValve)
521+
{
522+
// For distributing valves, we use AutoCylPressurePSI as "Application Chamber/Pipe" pressure
523+
// CylPressurePSI is the actual pressure applied to cylinders
524+
var loco = Car as MSTSLocomotive;
525+
var engineBrakeStatus = loco.EngineBrakeController.Notches[loco.EngineBrakeController.CurrentNotch].Type;
526+
var trainBrakeStatus = loco.TrainBrakeController.Notches[loco.TrainBrakeController.CurrentNotch].Type;
527+
// BailOff
528+
if (engineBrakeStatus == ControllerState.BailOff)
529+
{
530+
AutoCylPressurePSI -= MaxReleaseRatePSIpS * elapsedClockSeconds;
531+
if (AutoCylPressurePSI < 0) AutoCylPressurePSI = 0;
532+
}
533+
// Emergency application
534+
if (trainBrakeStatus == ControllerState.Emergency)
535+
{
536+
float dp = elapsedClockSeconds * MaxApplicationRatePSIpS;
537+
if (dp > MaxCylPressurePSI - AutoCylPressurePSI)
538+
dp = MaxCylPressurePSI - AutoCylPressurePSI;
539+
AutoCylPressurePSI += dp;
540+
}
541+
// Release pipe open
542+
HoldingValve = engineBrakeStatus == ControllerState.Release && trainBrakeStatus == ControllerState.Release ? ValveState.Release : ValveState.Lap;
543+
544+
// Independent air brake equalization
545+
if (AutoCylPressurePSI < loco.Train.BrakeLine3PressurePSI)
546+
AutoCylPressurePSI = loco.Train.BrakeLine3PressurePSI;
547+
else
548+
loco.Train.BrakeLine3PressurePSI = AutoCylPressurePSI;
521549

522-
if (Car is MSTSLocomotive loco && loco.EngineType != TrainCar.EngineTypes.Control) // TODO - Control cars ned to be linked to power suppy requirements.
550+
// Equalization between application chamber and brake cylinders
551+
// TODO: Drain air from main reservoir
552+
CylPressurePSI = AutoCylPressurePSI;
553+
}
554+
else
523555
{
524-
// if (Car is MSTSLocomotive loco && loco.LocomotivePowerSupply.MainPowerSupplyOn)
525-
if (loco.LocomotivePowerSupply.MainPowerSupplyOn)
556+
bool bailoff = false;
557+
558+
if (Car is MSTSLocomotive loco && loco.EngineType != TrainCar.EngineTypes.Control) // TODO - Control cars ned to be linked to power suppy requirements.
526559
{
527-
if (loco.Train.LeadLocomotiveIndex >= 0 && ((MSTSLocomotive)loco.Train.Cars[loco.Train.LeadLocomotiveIndex]).BailOff)
528-
{
529-
bailoff = true;
530-
CylPressurePSI -= MaxReleaseRatePSIpS * elapsedClockSeconds;
531-
if (CylPressurePSI < 0) CylPressurePSI = 0;
532-
}
533-
else if (loco.DynamicBrakeAutoBailOff && loco.DynamicBrakePercent > 0 && Car.MaxBrakeForceN > 0)
560+
// if (Car is MSTSLocomotive loco && loco.LocomotivePowerSupply.MainPowerSupplyOn)
561+
if (loco.LocomotivePowerSupply.MainPowerSupplyOn)
534562
{
535-
bailoff = true;
536-
var requiredBrakeForce = Math.Min(AutoCylPressurePSI / MaxCylPressurePSI, 1) * Car.MaxBrakeForceN;
537-
var airBrakeForce = requiredBrakeForce - loco.DynamicBrakeForceN;
538-
var requiredCylPressure = Math.Max(Math.Min(airBrakeForce / Car.MaxBrakeForceN * MaxCylPressurePSI, AutoCylPressurePSI), 0);
539-
if (requiredCylPressure > CylPressurePSI)
540-
CylPressurePSI = Math.Min(requiredCylPressure, CylPressurePSI + MaxApplicationRatePSIpS * elapsedClockSeconds);
541-
if (requiredCylPressure < CylPressurePSI)
542-
CylPressurePSI = Math.Max(requiredCylPressure, CylPressurePSI - MaxReleaseRatePSIpS * elapsedClockSeconds);
563+
if (loco.Train.LeadLocomotiveIndex >= 0 && ((MSTSLocomotive)loco.Train.Cars[loco.Train.LeadLocomotiveIndex]).BailOff)
564+
{
565+
bailoff = true;
566+
CylPressurePSI -= MaxReleaseRatePSIpS * elapsedClockSeconds;
567+
if (CylPressurePSI < 0) CylPressurePSI = 0;
568+
}
569+
else if (loco.DynamicBrakeAutoBailOff && loco.DynamicBrakePercent > 0 && Car.MaxBrakeForceN > 0)
570+
{
571+
bailoff = true;
572+
var requiredBrakeForce = Math.Min(AutoCylPressurePSI / MaxCylPressurePSI, 1) * Car.MaxBrakeForceN;
573+
var airBrakeForce = requiredBrakeForce - loco.DynamicBrakeForceN;
574+
var requiredCylPressure = Math.Max(Math.Min(airBrakeForce / Car.MaxBrakeForceN * MaxCylPressurePSI, AutoCylPressurePSI), 0);
575+
if (requiredCylPressure > CylPressurePSI)
576+
CylPressurePSI = Math.Min(requiredCylPressure, CylPressurePSI + MaxApplicationRatePSIpS * elapsedClockSeconds);
577+
if (requiredCylPressure < CylPressurePSI)
578+
CylPressurePSI = Math.Max(requiredCylPressure, CylPressurePSI - MaxReleaseRatePSIpS * elapsedClockSeconds);
579+
}
543580
}
544581
}
582+
if (!bailoff)
583+
CylPressurePSI = AutoCylPressurePSI;
584+
if (CylPressurePSI < BrakeLine3PressurePSI) // Brake Cylinder pressure will be the greater of engine brake pressure or train brake pressure
585+
CylPressurePSI = BrakeLine3PressurePSI;
545586
}
546-
if (!bailoff)
547-
CylPressurePSI = AutoCylPressurePSI;
548-
if (CylPressurePSI < BrakeLine3PressurePSI) // Brake Cylinder pressure will be the greater of engine brake pressure or train brake pressure
549-
CylPressurePSI = BrakeLine3PressurePSI;
550587

551588
// During braking wheelslide control is effected throughout the train by additional equipment on each vehicle. In the piping to each pair of brake cylinders are fitted electrically operated
552589
// dump valves. When axle rotations which are sensed electrically, differ by a predetermined speed the dump valves are operated releasing brake cylinder pressure to both axles of the affected

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Controllers/MSTSBrakeController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public override void UpdatePressure(ref float pressureBar, float elapsedClockSec
128128
switch (type)
129129
{
130130
case ControllerState.Release:
131+
case ControllerState.HoldEngine:
131132
IncreasePressure(ref pressureBar, Math.Min(MaxPressureBar(), MainReservoirPressureBar()), ReleaseRateBarpS(), elapsedClockSeconds);
132133
DecreasePressure(ref pressureBar, MaxPressureBar(), OverchargeEliminationRateBarpS(), elapsedClockSeconds);
133134
epState = 0;
@@ -256,14 +257,15 @@ public override void UpdateEngineBrakePressure(ref float pressureBar, float elap
256257
case ControllerState.Lap:
257258
break;
258259
case ControllerState.FullQuickRelease:
260+
case ControllerState.BailOff:
259261
pressureBar -= x * QuickReleaseRateBarpS() * elapsedClockSeconds;
260262
break;
261263
case ControllerState.Release:
262264
pressureBar -= x * ReleaseRateBarpS() * elapsedClockSeconds;
263265
break;
264266
case ControllerState.Apply:
265267
case ControllerState.FullServ:
266-
IncreasePressure(ref pressureBar, x * (MaxPressureBar() - FullServReductionBar()), ApplyRateBarpS(), elapsedClockSeconds);
268+
IncreasePressure(ref pressureBar, MaxPressureBar() - FullServReductionBar(), x*ApplyRateBarpS(), elapsedClockSeconds);
267269
break;
268270
case ControllerState.ManualBraking:
269271
case ControllerState.VacContServ:

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Controllers/MSTSNotchController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public MSTSNotch(float v, int s, string type, STFReader stf)
7979
case "brakenotchstart": Type = ControllerState.BrakeNotch; break;
8080
case "overchargestart": Type = ControllerState.Overcharge; break;
8181
case "slowservicestart": Type = ControllerState.SlowService; break;
82+
case "holdenginestart": Type = ControllerState.HoldEngine; break;
83+
case "bailoffstart": Type = ControllerState.BailOff; break;
8284
default:
8385
STFException.TraceInformation(stf, "Skipped unknown notch type " + type);
8486
break;

0 commit comments

Comments
 (0)