Skip to content

Commit f1c627e

Browse files
committed
Add SME brak function
1 parent 1c4a84d commit f1c627e

File tree

9 files changed

+179
-26
lines changed

9 files changed

+179
-26
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ public enum ControllerState
260260
EPOnly, // TrainBrakesControllerEPOnlyStart
261261
EPFullServ, // TrainBrakesControllerEPFullServiceStart
262262
SlowService, // TrainBrakesControllerSlowServiceStart
263+
SMEOnly, // TrainBrakesControllerSMEOnlyStart
264+
SMEFullServ, // TrainBrakesControllerSMEFullServiceStart
265+
SMESelfLap, // TrainBrakesControllerSMEHoldStart
266+
SMEReleaseStart, // TrainBrakesControllerSEMReleaseStart
263267
};
264268

265269
public static class ControllerStateDictionary
@@ -302,7 +306,11 @@ public static class ControllerStateDictionary
302306
{ControllerState.BrakeNotch, Catalog.GetString("Notch")},
303307
{ControllerState.EPOnly, Catalog.GetString("EP Service")},
304308
{ControllerState.EPFullServ, Catalog.GetString("EP Full Service")},
305-
{ControllerState.SlowService, Catalog.GetString("Slow service")}
309+
{ControllerState.SlowService, Catalog.GetString("Slow service")},
310+
{ControllerState.SMEOnly, Catalog.GetString("SME Service")},
311+
{ControllerState.SMEFullServ, Catalog.GetString("SME Full Service")},
312+
{ControllerState.SMESelfLap, Catalog.GetString("SME Self Lap")},
313+
{ControllerState.SMEReleaseStart, Catalog.GetString("SME Release Start")}
306314
};
307315
}
308316
}

Source/Orts.Simulation/Orts.Simulation.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
<Compile Include="Simulation\RollingStocks\SubSystems\Brakes\MSTS\ManualBraking.cs" />
112112
<Compile Include="Simulation\RollingStocks\SubSystems\Brakes\MSTS\MSTSBrakeSystem.cs" />
113113
<Compile Include="Simulation\RollingStocks\SubSystems\Brakes\MSTS\SingleTransferPipe.cs" />
114+
<Compile Include="Simulation\RollingStocks\SubSystems\Brakes\MSTS\SMEBrakeSystem.cs" />
114115
<Compile Include="Simulation\RollingStocks\SubSystems\Brakes\MSTS\StraightVacuumSinglePipe.cs" />
115116
<Compile Include="Simulation\RollingStocks\SubSystems\Brakes\MSTS\VacuumSinglePipe.cs" />
116117
<Compile Include="Simulation\RollingStocks\SubSystems\Controllers\BrakeController.cs" />

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,30 @@ public override string GetFullStatus(BrakeSystem lastCarBrakeSystem, Dictionary<
142142

143143
public override string[] GetDebugStatus(Dictionary<BrakeSystemComponent, PressureUnit> units)
144144
{
145-
return new string[] {
145+
MSTSLocomotive lead = (MSTSLocomotive)Car.Train.LeadLocomotive;
146+
147+
if (lead != null && lead.BrakeSystem is SMEBrakeSystem)
148+
{
149+
// Set values for SME type brake
150+
return new string[] {
151+
DebugType,
152+
string.Format("{0}{1}",FormatStrings.FormatPressure(CylPressurePSI, PressureUnit.PSI, units[BrakeSystemComponent.BrakeCylinder], true), (Car as MSTSWagon).WheelBrakeSlideProtectionActive ? "???" : ""),
153+
FormatStrings.FormatPressure(BrakeLine1PressurePSI, PressureUnit.PSI, units[BrakeSystemComponent.BrakePipe], true),
154+
FormatStrings.FormatPressure(AuxResPressurePSI, PressureUnit.PSI, units[BrakeSystemComponent.AuxiliaryReservoir], true),
155+
(Car as MSTSWagon).EmergencyReservoirPresent ? FormatStrings.FormatPressure(EmergResPressurePSI, PressureUnit.PSI, units[BrakeSystemComponent.EmergencyReservoir], true) : string.Empty,
156+
TwoPipes ? FormatStrings.FormatPressure(CylPressurePSI, PressureUnit.PSI, units[BrakeSystemComponent.MainPipe], true) : string.Empty,
157+
(Car as MSTSWagon).RetainerPositions == 0 ? string.Empty : RetainerDebugState,
158+
Simulator.Catalog.GetString(GetStringAttribute.GetPrettyName(TripleValveState)),
159+
string.Empty, // Spacer because the state above needs 2 columns.
160+
(Car as MSTSWagon).HandBrakePresent ? string.Format("{0:F0}%", HandbrakePercent) : string.Empty,
161+
FrontBrakeHoseConnected ? "I" : "T",
162+
string.Format("A{0} B{1}", AngleCockAOpen ? "+" : "-", AngleCockBOpen ? "+" : "-"),
163+
BleedOffValveOpen ? Simulator.Catalog.GetString("Open") : string.Empty,
164+
};
165+
}
166+
else
167+
{
168+
return new string[] {
146169
DebugType,
147170
string.Format("{0}{1}",FormatStrings.FormatPressure(CylPressurePSI, PressureUnit.PSI, units[BrakeSystemComponent.BrakeCylinder], true), (Car as MSTSWagon).WheelBrakeSlideProtectionActive ? "???" : ""),
148171
FormatStrings.FormatPressure(BrakeLine1PressurePSI, PressureUnit.PSI, units[BrakeSystemComponent.BrakePipe], true),
@@ -156,7 +179,9 @@ public override string[] GetDebugStatus(Dictionary<BrakeSystemComponent, Pressur
156179
FrontBrakeHoseConnected ? "I" : "T",
157180
string.Format("A{0} B{1}", AngleCockAOpen ? "+" : "-", AngleCockBOpen ? "+" : "-"),
158181
BleedOffValveOpen ? Simulator.Catalog.GetString("Open") : string.Empty,
159-
};
182+
};
183+
}
184+
160185
}
161186

162187
public override float GetCylPressurePSI()

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

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,37 @@ public EPBrakeSystem(TrainCar car)
3232

3333
public override void Update(float elapsedClockSeconds)
3434
{
35-
float demandedAutoCylPressurePSI = 0;
36-
if (BrakeLine3PressurePSI >= 1000f || Car.Train.BrakeLine4 < 0)
35+
MSTSLocomotive lead = (MSTSLocomotive)Car.Train.LeadLocomotive;
36+
if (lead != null && lead.BrakeSystem is EPBrakeSystem)
3737
{
38-
HoldingValve = ValveState.Release;
39-
}
40-
else if (Car.Train.BrakeLine4 == 0)
41-
{
42-
HoldingValve = ValveState.Lap;
43-
}
44-
else
45-
{
46-
demandedAutoCylPressurePSI = Math.Min(Math.Max(Car.Train.BrakeLine4, 0), 1) * MaxCylPressurePSI;
47-
HoldingValve = AutoCylPressurePSI <= demandedAutoCylPressurePSI ? ValveState.Lap : ValveState.Release;
48-
}
4938

50-
base.Update(elapsedClockSeconds);
39+
float demandedAutoCylPressurePSI = 0;
40+
if (BrakeLine3PressurePSI >= 1000f || Car.Train.BrakeLine4 < 0)
41+
{
42+
HoldingValve = ValveState.Release;
43+
}
44+
else if (Car.Train.BrakeLine4 == 0)
45+
{
46+
HoldingValve = ValveState.Lap;
47+
}
48+
else
49+
{
50+
demandedAutoCylPressurePSI = Math.Min(Math.Max(Car.Train.BrakeLine4, 0), 1) * MaxCylPressurePSI;
51+
HoldingValve = AutoCylPressurePSI <= demandedAutoCylPressurePSI ? ValveState.Lap : ValveState.Release;
52+
}
5153

52-
if (AutoCylPressurePSI < demandedAutoCylPressurePSI && !Car.WheelBrakeSlideProtectionActive)
53-
{
54-
float dp = elapsedClockSeconds * MaxApplicationRatePSIpS;
55-
if (BrakeLine2PressurePSI - dp * AuxBrakeLineVolumeRatio / AuxCylVolumeRatio < AutoCylPressurePSI + dp)
56-
dp = (BrakeLine2PressurePSI - AutoCylPressurePSI) / (1 + AuxBrakeLineVolumeRatio / AuxCylVolumeRatio);
57-
if (dp > demandedAutoCylPressurePSI - AutoCylPressurePSI)
58-
dp = demandedAutoCylPressurePSI - AutoCylPressurePSI;
59-
BrakeLine2PressurePSI -= dp * AuxBrakeLineVolumeRatio / AuxCylVolumeRatio;
60-
AutoCylPressurePSI += dp;
54+
base.Update(elapsedClockSeconds);
55+
56+
if (AutoCylPressurePSI < demandedAutoCylPressurePSI && !Car.WheelBrakeSlideProtectionActive)
57+
{
58+
float dp = elapsedClockSeconds * MaxApplicationRatePSIpS;
59+
if (BrakeLine2PressurePSI - dp * AuxBrakeLineVolumeRatio / AuxCylVolumeRatio < AutoCylPressurePSI + dp)
60+
dp = (BrakeLine2PressurePSI - AutoCylPressurePSI) / (1 + AuxBrakeLineVolumeRatio / AuxCylVolumeRatio);
61+
if (dp > demandedAutoCylPressurePSI - AutoCylPressurePSI)
62+
dp = demandedAutoCylPressurePSI - AutoCylPressurePSI;
63+
BrakeLine2PressurePSI -= dp * AuxBrakeLineVolumeRatio / AuxCylVolumeRatio;
64+
AutoCylPressurePSI += dp;
65+
}
6166
}
6267
}
6368

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static BrakeSystem Create(string type, TrainCar car)
3333
case "air_single_pipe": return new AirSinglePipe(car);
3434
case "ecp":
3535
case "ep": return new EPBrakeSystem(car);
36+
case "sme": return new SMEBrakeSystem(car);
3637
case "air_piped":
3738
case "vacuum_piped": return new SingleTransferPipe(car);
3839
default: return new SingleTransferPipe(car);
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// COPYRIGHT 2009, 2010, 2011, 2012, 2013, 2014 by the Open Rails project.
2+
//
3+
// This file is part of Open Rails.
4+
//
5+
// Open Rails is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Open Rails is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
17+
18+
using ORTS.Common;
19+
using System;
20+
using System.Collections.Generic;
21+
22+
namespace Orts.Simulation.RollingStocks.SubSystems.Brakes.MSTS
23+
{
24+
25+
public class SMEBrakeSystem : AirTwinPipe
26+
{
27+
public SMEBrakeSystem(TrainCar car)
28+
: base(car)
29+
{
30+
DebugType = "SME";
31+
}
32+
33+
public override void Update(float elapsedClockSeconds)
34+
{
35+
MSTSLocomotive lead = (MSTSLocomotive)Car.Train.LeadLocomotive;
36+
if (lead != null && lead.BrakeSystem is SMEBrakeSystem)
37+
{
38+
39+
float demandedAutoCylPressurePSI = 0;
40+
if (BrakeLine3PressurePSI >= 1000f || Car.Train.BrakeLine4 < 0)
41+
{
42+
HoldingValve = ValveState.Release;
43+
}
44+
else if (Car.Train.BrakeLine4 == 0)
45+
{
46+
HoldingValve = ValveState.Lap;
47+
}
48+
else
49+
{
50+
demandedAutoCylPressurePSI = Math.Min(Math.Max(Car.Train.BrakeLine4, 0), 1) * MaxCylPressurePSI;
51+
HoldingValve = AutoCylPressurePSI <= demandedAutoCylPressurePSI ? ValveState.Lap : ValveState.Release;
52+
}
53+
54+
base.Update(elapsedClockSeconds);
55+
56+
if (AutoCylPressurePSI < demandedAutoCylPressurePSI && !Car.WheelBrakeSlideProtectionActive)
57+
{
58+
float dp = elapsedClockSeconds * MaxApplicationRatePSIpS;
59+
if (BrakeLine2PressurePSI - dp * AuxBrakeLineVolumeRatio / AuxCylVolumeRatio < AutoCylPressurePSI + dp)
60+
dp = (BrakeLine2PressurePSI - AutoCylPressurePSI) / (1 + AuxBrakeLineVolumeRatio / AuxCylVolumeRatio);
61+
if (dp > demandedAutoCylPressurePSI - AutoCylPressurePSI)
62+
dp = demandedAutoCylPressurePSI - AutoCylPressurePSI;
63+
BrakeLine2PressurePSI -= dp * AuxBrakeLineVolumeRatio / AuxCylVolumeRatio;
64+
AutoCylPressurePSI += dp;
65+
}
66+
}
67+
}
68+
69+
public override string GetFullStatus(BrakeSystem lastCarBrakeSystem, Dictionary<BrakeSystemComponent, PressureUnit> units)
70+
{
71+
var s = $" {Simulator.Catalog.GetString("BC")} {FormatStrings.FormatPressure(CylPressurePSI, PressureUnit.PSI, units[BrakeSystemComponent.BrakeCylinder], true)}";
72+
if (HandbrakePercent > 0)
73+
s += $" {Simulator.Catalog.GetString("Handbrake")} {HandbrakePercent:F0}%";
74+
return s;
75+
}
76+
}
77+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public override void UpdatePressure(ref float pressureBar, float elapsedClockSec
128128
epState = -1;
129129
break;
130130
case ControllerState.FullQuickRelease:
131+
case ControllerState.SMEReleaseStart:
131132
IncreasePressure(ref pressureBar, MaxPressureBar(), QuickReleaseRateBarpS(), elapsedClockSeconds);
132133
DecreasePressure(ref pressureBar, MaxPressureBar(), OverchargeEliminationRateBarpS(), elapsedClockSeconds);
133134
epState = -1;
@@ -184,8 +185,10 @@ public override void UpdatePressure(ref float pressureBar, float elapsedClockSec
184185
break;
185186
case ControllerState.EPApply:
186187
case ControllerState.EPOnly:
188+
case ControllerState.SMEOnly:
187189
case ControllerState.ContServ:
188190
case ControllerState.EPFullServ:
191+
case ControllerState.SMEFullServ:
189192
epState = x;
190193
if (notch.Type == ControllerState.EPApply || notch.Type == ControllerState.ContServ)
191194
{

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public MSTSNotch(float v, int s, string type, STFReader stf)
6969
case "eponlystart": Type = ControllerState.EPOnly; break;
7070
case "epfullservicestart": Type = ControllerState.EPFullServ; break;
7171
case "epholdstart": Type = ControllerState.SelfLap; break;
72+
case "smeholdstart": Type = ControllerState.SMESelfLap; break;
73+
case "smeonlystart": Type = ControllerState.SMEOnly; break;
74+
case "smefullservicestart": Type = ControllerState.SMEFullServ; break;
75+
case "smereleasestart": Type = ControllerState.SMEReleaseStart; break;
7276
case "vacuumcontinuousservicestart": Type = ControllerState.VacContServ; break;
7377
case "vacuumapplycontinuousservicestart": Type = ControllerState.VacApplyContServ; break;
7478
case "manualbrakingstart": Type = ControllerState.ManualBraking; break;

Source/RunActivity/Viewer3D/Popups/HUDWindow.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,35 @@ void TextPageBrakeInfo(TableData table)
918918

919919
}
920920
}
921+
else if ((Viewer.PlayerLocomotive as MSTSLocomotive).BrakeSystem is SMEBrakeSystem)
922+
{
923+
TableSetCells(table, 0,
924+
Viewer.Catalog.GetString("Car"),
925+
Viewer.Catalog.GetString("Type"),
926+
Viewer.Catalog.GetString("BrkCyl"),
927+
Viewer.Catalog.GetString("SrvPipe"),
928+
Viewer.Catalog.GetString("AuxRes"),
929+
Viewer.Catalog.GetString("ErgRes"),
930+
Viewer.Catalog.GetString("StrPipe"),
931+
Viewer.Catalog.GetString("RetValve"),
932+
Viewer.Catalog.GetString("TripleValve"),
933+
Viewer.Catalog.GetString(""),
934+
Viewer.Catalog.GetString("Handbrk"),
935+
Viewer.Catalog.GetString("Conn"),
936+
Viewer.Catalog.GetString("AnglCock"),
937+
Viewer.Catalog.GetString("BleedOff"));
938+
TableAddLine(table);
939+
940+
var n = train.Cars.Count; // Number of lines to show
941+
for (var i = 0; i < n; i++)
942+
{
943+
var j = i < 2 ? i : i * (train.Cars.Count - 1) / (n - 1);
944+
var car = train.Cars[j];
945+
TableSetCell(table, 0, "{0}", car.CarID);
946+
TableSetCells(table, 1, car.BrakeSystem.GetDebugStatus((Viewer.PlayerLocomotive as MSTSLocomotive).BrakeSystemPressureUnits));
947+
TableAddLine(table);
948+
}
949+
}
921950
else // default air braked
922951
{
923952
TableSetCells(table, 0,

0 commit comments

Comments
 (0)