Skip to content

Commit 156a2be

Browse files
committed
Refactoring of slip control
1 parent 452a72f commit 156a2be

File tree

3 files changed

+75
-26
lines changed

3 files changed

+75
-26
lines changed

Source/Orts.Simulation/Simulation/RollingStocks/MSTSDieselLocomotive.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,13 +669,25 @@ protected override void UpdateTractiveForce(float elapsedClockSeconds, float t,
669669
// its impact. More modern locomotive have a more sophisticated system that eliminates slip in the majority (if not all circumstances).
670670
// Simple adhesion control does not have any slip control feature built into it.
671671
// TODO - a full review of slip/no slip control.
672-
if (WheelSlip && AdvancedAdhesionModel)
672+
if (ElectricMotorType == ElectricMotorTypes.AC)
673673
{
674-
AbsTractionSpeedMpS = AbsWheelSpeedMpS;
674+
AbsTractionSpeedMpS = AbsSpeedMpS;
675+
if (AbsWheelSpeedMpS > 1.1 * MaxSpeedMpS)
676+
{
677+
AverageForceN = TractiveForceN = 0;
678+
return;
679+
}
675680
}
676681
else
677682
{
678-
AbsTractionSpeedMpS = AbsSpeedMpS;
683+
if (WheelSlip && AdvancedAdhesionModel)
684+
{
685+
AbsTractionSpeedMpS = AbsWheelSpeedMpS;
686+
}
687+
else
688+
{
689+
AbsTractionSpeedMpS = AbsSpeedMpS;
690+
}
679691
}
680692

681693
if (TractiveForceCurves == null)

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

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ public float CurrentLocomotiveSteamHeatBoilerWaterCapacityL
214214
//float DebugTimer = 0.0f;
215215

216216
// Adhesion parameters
217+
public enum SlipControlType
218+
{
219+
None,
220+
Full
221+
}
222+
public SlipControlType SlipControlSystem = SlipControlType.Full;
217223
float BaseFrictionCoefficientFactor; // Factor used to adjust Curtius formula depending upon weather conditions
218224
public float SteamStaticWheelForce;
219225
public float SteamTangentialWheelForce;
@@ -426,6 +432,13 @@ public float OdometerM
426432
public float DynamicBrakeIntervention = -1;
427433
protected float PreviousDynamicBrakeIntervention = -1;
428434

435+
public enum ElectricMotorTypes
436+
{
437+
AC,
438+
DC
439+
}
440+
public ElectricMotorTypes ElectricMotorType;
441+
429442
public ILocomotivePowerSupply LocomotivePowerSupply => PowerSupply as ILocomotivePowerSupply;
430443
public ScriptedTrainControlSystem TrainControlSystem;
431444

@@ -862,6 +875,18 @@ public override void Parse(string lowercasetoken, STFReader stf)
862875
case "engine(dieselenginespeedofmaxtractiveeffort": MSTSSpeedOfMaxContinuousForceMpS = stf.ReadFloatBlock(STFReader.UNITS.Speed, null); break;
863876
case "engine(maxvelocity": MaxSpeedMpS = stf.ReadFloatBlock(STFReader.UNITS.Speed, null); break;
864877
case "engine(ortsunloadingspeed": UnloadingSpeedMpS = stf.ReadFloatBlock(STFReader.UNITS.Speed, null); break;
878+
case "engine(ortsslipcontrolsystem":
879+
stf.MustMatch("(");
880+
string slipControlType = stf.ReadString().ToLowerInvariant();
881+
try
882+
{
883+
SlipControlSystem = (SlipControlType)Enum.Parse(typeof(SlipControlType), slipControlType.First().ToString().ToUpper() + slipControlType.Substring(1));
884+
}
885+
catch
886+
{
887+
STFException.TraceWarning(stf, "Skipped unknown slip control system " + slipControlType);
888+
}
889+
break;
865890
case "engine(type":
866891
stf.MustMatch("(");
867892
var engineType = stf.ReadString();
@@ -874,6 +899,18 @@ public override void Parse(string lowercasetoken, STFReader stf)
874899
STFException.TraceWarning(stf, "Skipped unknown engine type " + engineType);
875900
}
876901
break;
902+
case "engine(ortselectricmotortype":
903+
stf.MustMatch("(");
904+
string electricMotorType = stf.ReadString().ToUpper();
905+
try
906+
{
907+
ElectricMotorType = (ElectricMotorTypes)Enum.Parse(typeof(ElectricMotorTypes), electricMotorType);
908+
}
909+
catch
910+
{
911+
STFException.TraceWarning(stf, "Skipped unknown electric motor type " + electricMotorType);
912+
}
913+
break;
877914

878915
case "engine(enginecontrollers(throttle": ThrottleController = new MSTSNotchController(stf); break;
879916
case "engine(enginecontrollers(regulator": ThrottleController = new MSTSNotchController(stf); break;
@@ -1070,7 +1107,9 @@ public override void Copy(MSTSWagon copy)
10701107
MaxCurrentA = locoCopy.MaxCurrentA;
10711108
MaxSpeedMpS = locoCopy.MaxSpeedMpS;
10721109
UnloadingSpeedMpS = locoCopy.UnloadingSpeedMpS;
1110+
SlipControlSystem = locoCopy.SlipControlSystem;
10731111
EngineType = locoCopy.EngineType;
1112+
ElectricMotorType = locoCopy.ElectricMotorType;
10741113
TractiveForceCurves = locoCopy.TractiveForceCurves;
10751114
MaxContinuousForceN = locoCopy.MaxContinuousForceN;
10761115
SpeedOfMaxContinuousForceMpS = locoCopy.SpeedOfMaxContinuousForceMpS;
@@ -1893,7 +1932,6 @@ public override void Update(float elapsedClockSeconds)
18931932
DynamicBrakeController.CurrentValue * 100);
18941933
}
18951934

1896-
18971935
// SimpleControlPhysics and if locomotive is a control car advanced adhesion will be "disabled".
18981936
if (Simulator.UseAdvancedAdhesion && !Simulator.Settings.SimpleControlPhysics && EngineType != EngineTypes.Control)
18991937
{
@@ -2199,13 +2237,25 @@ protected virtual void UpdateTractiveForce(float elapsedClockSeconds, float t, f
21992237
// More modern locomotive have a more sophisticated system that eliminates slip in the majority (if not all circumstances).
22002238
// Simple adhesion control does not have any slip control feature built into it.
22012239
// TODO - a full review of slip/no slip control.
2202-
if (WheelSlip && AdvancedAdhesionModel)
2240+
if (ElectricMotorType == ElectricMotorTypes.AC)
22032241
{
2204-
AbsTractionSpeedMpS = AbsWheelSpeedMpS;
2242+
AbsTractionSpeedMpS = AbsSpeedMpS;
2243+
if (AbsWheelSpeedMpS > 1.1 * MaxSpeedMpS)
2244+
{
2245+
AverageForceN = TractiveForceN = 0;
2246+
return;
2247+
}
22052248
}
22062249
else
22072250
{
2208-
AbsTractionSpeedMpS = AbsSpeedMpS;
2251+
if (WheelSlip && AdvancedAdhesionModel)
2252+
{
2253+
AbsTractionSpeedMpS = AbsWheelSpeedMpS;
2254+
}
2255+
else
2256+
{
2257+
AbsTractionSpeedMpS = AbsSpeedMpS;
2258+
}
22092259
}
22102260

22112261
if (TractiveForceCurves == null)
@@ -2297,7 +2347,7 @@ public void ConfirmWheelslip(float elapsedClockSeconds)
22972347
if (AdvancedAdhesionModel)
22982348
{
22992349
// Wheelslip
2300-
if (LocomotiveAxle.IsWheelSlip)
2350+
if (WheelSlip)
23012351
{
23022352
if (WheelslipState != Wheelslip.Occurring)
23032353
{
@@ -2307,7 +2357,7 @@ public void ConfirmWheelslip(float elapsedClockSeconds)
23072357
}
23082358
else
23092359
{
2310-
if (LocomotiveAxle.IsWheelSlipWarning)
2360+
if (WheelSlipWarning)
23112361
{
23122362
if (WheelslipState != Wheelslip.Warning)
23132363
{
@@ -2590,7 +2640,7 @@ public void AdvancedAdhesion(float elapsedClockSeconds)
25902640
//LocomotiveAxle.AxleRevolutionsInt.MinStep = LocomotiveAxle.InertiaKgm2 / MaxPowerW / 5.0f;
25912641
LocomotiveAxle.AxleDiameterM = 2*DriverWheelRadiusM;
25922642

2593-
if (AntislipControl == AntislipControlType.Full)
2643+
if (SlipControlSystem == SlipControlType.Full)
25942644
{
25952645
// Simple slip control
25962646
// Motive force is reduced to the maximum adhesive force
@@ -2614,7 +2664,7 @@ public void AdvancedAdhesion(float elapsedClockSeconds)
26142664
if (elapsedClockSeconds > 0)
26152665
{
26162666
WheelSlip = LocomotiveAxle.IsWheelSlip; //Get the wheelslip indicator
2617-
WheelSlipWarning = LocomotiveAxle.IsWheelSlipWarning;
2667+
WheelSlipWarning = LocomotiveAxle.IsWheelSlipWarning && SlipControlSystem != SlipControlType.Full;
26182668
}
26192669
WheelSpeedMpS = LocomotiveAxle.AxleSpeedMpS;
26202670
}
@@ -5017,7 +5067,7 @@ public virtual float GetDataOf(CabViewControl cvc)
50175067
if (activeloco.DieselEngines[0] != null)
50185068
{
50195069
if (activeloco.AdvancedAdhesionModel && Train.TrainType != Train.TRAINTYPE.AI_PLAYERHOSTING)
5020-
data = activeloco.LocomotiveAxle.IsWheelSlipWarning ? 1 : 0;
5070+
data = activeloco.WheelSlipWarning ? 1 : 0;
50215071
else
50225072
data = activeloco.WheelSlip ? 1 : 0;
50235073

@@ -5028,7 +5078,7 @@ public virtual float GetDataOf(CabViewControl cvc)
50285078
else
50295079
{
50305080
if (AdvancedAdhesionModel && Train.TrainType != Train.TRAINTYPE.AI_PLAYERHOSTING)
5031-
data = LocomotiveAxle.IsWheelSlipWarning ? 1 : 0;
5081+
data = WheelSlipWarning ? 1 : 0;
50325082
else
50335083
data = WheelSlip ? 1 : 0;
50345084
}

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,6 @@ public class MSTSWagon : TrainCar
146146
public float Curtius_KnifflerB = 44.0f; // (adhesion coeficient) umax = --------------------- + C
147147
public float Curtius_KnifflerC = 0.161f; // speedMpS * 3.6 + B
148148
public float AdhesionK = 0.7f; //slip characteristics slope
149-
public enum AntislipControlType
150-
{
151-
None,
152-
Full
153-
}
154-
public AntislipControlType AntislipControl = AntislipControlType.None;
155149
public float AxleInertiaKgm2; //axle inertia
156150
public float AdhesionDriveWheelRadiusM;
157151
public float WheelSpeedMpS;
@@ -1365,12 +1359,6 @@ public virtual void Parse(string lowercasetoken, STFReader stf)
13651359
SlipWarningThresholdPercent = stf.ReadFloat(STFReader.UNITS.None, 70.0f); if (SlipWarningThresholdPercent <= 0) SlipWarningThresholdPercent = 70.0f;
13661360
stf.SkipRestOfBlock();
13671361
break;
1368-
case "wagon(ortsadhesion(ortsantislip":
1369-
string type = stf.ReadStringBlock("none").ToLowerInvariant();
1370-
if (type == "full") AntislipControl = AntislipControlType.Full;
1371-
else AntislipControl = AntislipControlType.None;
1372-
stf.SkipRestOfBlock();
1373-
break;
13741362
case "wagon(ortsadhesion(wheelset(axle(ortsinertia":
13751363
stf.MustMatch("(");
13761364
AxleInertiaKgm2 = stf.ReadFloat(STFReader.UNITS.RotationalInertia, null);
@@ -1573,7 +1561,6 @@ public virtual void Copy(MSTSWagon copy)
15731561
Curtius_KnifflerC = copy.Curtius_KnifflerC;
15741562
AdhesionK = copy.AdhesionK;
15751563
AxleInertiaKgm2 = copy.AxleInertiaKgm2;
1576-
AntislipControl = copy.AntislipControl;
15771564
AdhesionDriveWheelRadiusM = copy.AdhesionDriveWheelRadiusM;
15781565
SlipWarningThresholdPercent = copy.SlipWarningThresholdPercent;
15791566
Lights = copy.Lights;

0 commit comments

Comments
 (0)