Skip to content

Commit 8311431

Browse files
committed
Refactor adhesion parameters
1 parent 86639a2 commit 8311431

File tree

5 files changed

+66
-137
lines changed

5 files changed

+66
-137
lines changed

Source/ORTS.Settings/UserSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public enum DirectXFeature
309309
public bool UseMSTSEnv { get; set; }
310310
[Default(false)]
311311
public bool SignalLightGlow { get; set; }
312-
[Default(130)]
312+
[Default(100)]
313313
public int AdhesionFactor { get; set; }
314314
[Default(10)]
315315
public int AdhesionFactorChange { get; set; }

Source/Orts.Simulation/Simulation/AIs/AITrain.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6298,7 +6298,6 @@ public bool SwitchToPlayerControl()
62986298
{
62996299
var loco = car as MSTSLocomotive;
63006300
loco.LocomotiveAxle.Reset(Simulator.GameTime, SpeedMpS);
6301-
loco.LocomotiveAxle.AxleSpeedMpS = SpeedMpS;
63026301
loco.AntiSlip = false; // <CSComment> TODO Temporary patch until AntiSlip is re-implemented
63036302
}
63046303
if (car == Simulator.PlayerLocomotive) { leadLocomotiveIndex = j; }

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ public enum TractionMotorTypes
454454
public IIRFilter CurrentFilter;
455455
public IIRFilter AdhesionFilter;
456456
public float SaveAdhesionFilter;
457+
public float AdhesionConditions;
457458

458459
public float FilteredMotiveForceN;
459460

@@ -473,8 +474,6 @@ public MSTSLocomotive(Simulator simulator, string wagPath)
473474

474475
LocomotiveAxle = new Axle();
475476
LocomotiveAxle.DriveType = AxleDriveType.ForceDriven;
476-
LocomotiveAxle.DampingNs = MassKG / 1000.0f;
477-
LocomotiveAxle.FrictionN = MassKG / 100.0f;
478477
CurrentFilter = new IIRFilter(IIRFilter.FilterTypes.Butterworth, 1, IIRFilter.HzToRad(0.5f), 0.001f);
479478
AdhesionFilter = new IIRFilter(IIRFilter.FilterTypes.Butterworth, 1, IIRFilter.HzToRad(1f), 0.001f);
480479

@@ -1222,9 +1221,6 @@ public void MoveParamsToAxle()
12221221
{
12231222
LocomotiveAxle.SlipWarningTresholdPercent = SlipWarningThresholdPercent;
12241223
LocomotiveAxle.AdhesionK = AdhesionK;
1225-
LocomotiveAxle.CurtiusKnifflerA = Curtius_KnifflerA;
1226-
LocomotiveAxle.CurtiusKnifflerB = Curtius_KnifflerB;
1227-
LocomotiveAxle.CurtiusKnifflerC = Curtius_KnifflerC;
12281224
}
12291225
}
12301226

@@ -1686,8 +1682,6 @@ public override void InitializeMoving()
16861682
{
16871683
base.InitializeMoving();
16881684
LocomotiveAxle.Reset(Simulator.GameTime, SpeedMpS);
1689-
LocomotiveAxle.AxleSpeedMpS = SpeedMpS;
1690-
LocomotiveAxle.AdhesionConditions = (float)(Simulator.Settings.AdhesionFactor) * 0.01f;
16911685
AdhesionFilter.Reset(0.5f);
16921686
AverageForceN = MaxForceN * Train.MUThrottlePercent / 100;
16931687
float maxPowerW = MaxPowerW * Train.MUThrottlePercent * Train.MUThrottlePercent / 10000;
@@ -2646,16 +2640,16 @@ public void AdvancedAdhesion(float elapsedClockSeconds)
26462640
LocomotiveAxle.InertiaKgm2 = Math.Min(AxleInertiaKgm2, 40000);
26472641

26482642
//LocomotiveAxle.AxleRevolutionsInt.MinStep = LocomotiveAxle.InertiaKgm2 / MaxPowerW / 5.0f;
2649-
LocomotiveAxle.AxleDiameterM = 2*DriverWheelRadiusM;
2643+
LocomotiveAxle.WheelRadiusM = DriverWheelRadiusM;
2644+
LocomotiveAxle.DampingNs = MassKG / 1000.0f;
2645+
LocomotiveAxle.FrictionN = MassKG / 1000.0f;
26502646

26512647
if (SlipControlSystem == SlipControlType.Full)
26522648
{
26532649
// Simple slip control
26542650
// Motive force is reduced to the maximum adhesive force
26552651
// In wheelslip situations, motive force is set to zero
2656-
float umax = (LocomotiveAxle.CurtiusKnifflerA / (MpS.ToKpH(Math.Abs(SpeedMpS)) + LocomotiveAxle.CurtiusKnifflerB) + LocomotiveAxle.CurtiusKnifflerC); // Curtius - Kniffler equation
2657-
umax *= LocomotiveAxle.AdhesionConditions;
2658-
MotiveForceN = Math.Sign(MotiveForceN) * Math.Min(umax * LocomotiveAxle.AxleWeightN, Math.Abs(MotiveForceN));
2652+
MotiveForceN = Math.Sign(MotiveForceN) * Math.Min(LocomotiveAxle.AdhesionLimit * LocomotiveAxle.AxleWeightN, Math.Abs(MotiveForceN));
26592653
if (LocomotiveAxle.IsWheelSlip) MotiveForceN = 0;
26602654
}
26612655

@@ -2666,8 +2660,11 @@ public void AdvancedAdhesion(float elapsedClockSeconds)
26662660
LocomotiveAxle.AxleWeightN = 9.81f * DrvWheelWeightKg; //will be computed each time considering the tilting
26672661
LocomotiveAxle.DriveForceN = MotiveForceN; //Total force applied to wheels
26682662
LocomotiveAxle.TrainSpeedMpS = SpeedMpS; //Set the train speed of the axle mod
2663+
var watch = new Stopwatch();
2664+
watch.Start();
26692665
LocomotiveAxle.Update(elapsedClockSeconds); //Main updater of the axle model
2670-
2666+
watch.Stop();
2667+
//AdhesionConditions = watch.ElapsedTicks / 1000.0f;
26712668
MotiveForceN = LocomotiveAxle.CompensatedAxleForceN;
26722669
if (elapsedClockSeconds > 0)
26732670
{
@@ -3132,8 +3129,8 @@ public virtual void UpdateFrictionCoefficient(float elapsedClockSeconds)
31323129
if (elapsedClockSeconds > 0)
31333130
{
31343131
SaveAdhesionFilter = AdhesionFilter.Filter(BaseFrictionCoefficientFactor + AdhesionRandom, elapsedClockSeconds);
3135-
LocomotiveAxle.AdhesionConditions = AdhesionMultiplier * SaveAdhesionFilter;
3136-
LocomotiveAxle.AdhesionConditions = MathHelper.Clamp(LocomotiveAxle.AdhesionConditions, 0.05f, 2.5f); // Avoids NaNs in axle speed computing
3132+
AdhesionConditions = MathHelper.Clamp(AdhesionMultiplier * SaveAdhesionFilter, 0.05f, 2.5f);
3133+
LocomotiveAxle.AdhesionLimit = AdhesionConditions * BaseuMax;
31373134
}
31383135

31393136
// Set adhesion conditions for other steam locomotives
@@ -3143,7 +3140,7 @@ public virtual void UpdateFrictionCoefficient(float elapsedClockSeconds)
31433140
}
31443141
else
31453142
{
3146-
LocomotiveCoefficientFrictionHUD = BaseuMax * LocomotiveAxle.AdhesionConditions; // Set display value for HUD - diesel
3143+
LocomotiveCoefficientFrictionHUD = LocomotiveAxle.AdhesionLimit; // Set display value for HUD - diesel
31473144
}
31483145

31493146

0 commit comments

Comments
 (0)