Skip to content

Commit 076cd04

Browse files
committed
Adjust substep calculation
1 parent ef944ab commit 076cd04

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,7 +2807,9 @@ public virtual void AdvancedAdhesion(float elapsedClockSeconds)
28072807
axle.BogieRigidWheelBaseM = RigidWheelBaseM;
28082808
axle.CurtiusKnifflerZeroSpeed = ZeroSpeedAdhesionBase;
28092809
}
2810+
28102811
LocomotiveAxles.Update(elapsedClockSeconds);
2812+
28112813
MotiveForceN = LocomotiveAxles.CompensatedForceN;
28122814

28132815
if (elapsedClockSeconds > 0)

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerTransmissions/Axle.cs

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,13 @@ public void ComputeWheelSlipThresholdMpS()
644644
}
645645
WheelSlipThresholdMpS = (float)Math.Max((a + b) / 2, MpS.FromKpH(0.1f));
646646

647-
// if (SlipSpeedMpS > 0)
648-
// Trace.TraceInformation("Fx Values - a {0} fa1 {1} b {2} fb1 {3} s {4} fs {5} t {6} ft {7} u {8} fu {9} v {10} fv {11} x {12} fx {13} y {14} fy {15} Speed {16} Threshold {17} Fslip {18} SlipSpeed {19}", a, fa1, b, fb1, s, fs, t, ft, u, fu, v, fv, x, fx, y, fy, TrainSpeedMpS, WheelSlipThresholdMpS, fslip, SlipSpeedMpS);
647+
if (IsWheelSlip)
648+
{
649+
// Trace.TraceInformation("Fx Values - a {0} fa1 {1} b {2} fb1 {3} s {4} fs {5} t {6} ft {7} u {8} fu {9} v {10} fv {11} x {12} fx {13} y {14} fy {15} Speed {16} Threshold {17} Fslip {18} SlipSpeed {19}", a, fa1, b, fb1, s, fs, t, ft, u, fu, v, fv, x, fx, y, fy, TrainSpeedMpS, WheelSlipThresholdMpS, fslip, SlipSpeedMpS);
650+
651+
// Trace.TraceInformation("Threshold Speed - {0}", WheelSlipThresholdMpS);
652+
653+
}
649654

650655
}
651656

@@ -878,18 +883,46 @@ void Integrate(float elapsedClockSeconds)
878883
{
879884
++NumOfSubstepsPS;
880885
waitBeforeSpeedingUp = 100;
886+
887+
// Trace.TraceInformation("Algorithim Increase - Steps {0} Err {1}", NumOfSubstepsPS, integratorError);
888+
881889
}
882890
else
883891
{
884892
if (--waitBeforeSpeedingUp <= 0) //wait for a while before speeding up the integration
885893
{
886894
--NumOfSubstepsPS;
887895
waitBeforeSpeedingUp = 10; //not so fast ;)
896+
897+
// Trace.TraceInformation("Algorithim Decrease - Steps {0} Err {1}", NumOfSubstepsPS, integratorError);
888898
}
889899
}
890900

891-
NumOfSubstepsPS = Math.Max(Math.Min(NumOfSubstepsPS, 50), 1);
892-
901+
NumOfSubstepsPS = Math.Max(Math.Min(NumOfSubstepsPS, 130), 1);
902+
903+
// use straight line graph approximation
904+
// Points are 1 = (0, 150) and 2 = (threshold, 0)
905+
906+
907+
if (SlipSpeedMpS > 0.7 * WheelSlipThresholdMpS)
908+
{
909+
var upperLimit = 130;
910+
var AdhesGrad = ((0 - upperLimit) / (WheelSlipThresholdMpS - 0));
911+
var temp = Math.Abs((AdhesGrad * SlipSpeedMpS) + upperLimit);
912+
if (float.IsNaN((float)temp)) temp = 1;
913+
// Trace.TraceInformation("Grad - {0} AdhesGrad {1} SlipSpeedMps {2} Threshold {3}", temp, AdhesGrad, SlipSpeedMpS, WheelSlipThresholdMpS);
914+
915+
NumOfSubstepsPS = (int)temp;
916+
917+
if (NumOfSubstepsPS < 1)
918+
NumOfSubstepsPS = 1;
919+
920+
if (NumOfSubstepsPS > upperLimit)
921+
NumOfSubstepsPS = upperLimit;
922+
923+
// Trace.TraceInformation("Number of Steps {0}", NumOfSubstepsPS);
924+
}
925+
893926
double dt = elapsedClockSeconds / NumOfSubstepsPS;
894927
double hdt = dt / 2;
895928
double axleInForceSumN = 0;
@@ -901,7 +934,8 @@ void Integrate(float elapsedClockSeconds)
901934
{
902935
if (k1.Item1 * dt > Math.Max((Math.Abs(SlipSpeedMpS) - 1) * 10, 1) / 100)
903936
{
904-
NumOfSubstepsPS = Math.Min(NumOfSubstepsPS + 5, 50);
937+
NumOfSubstepsPS = Math.Min(NumOfSubstepsPS + 5, 130);
938+
// Trace.TraceInformation("Algorithim Change - k1 - Number of Steps {0}", NumOfSubstepsPS);
905939
dt = elapsedClockSeconds / NumOfSubstepsPS;
906940
hdt = dt / 2;
907941
}
@@ -974,18 +1008,20 @@ public virtual void Update(float timeSpan)
9741008
// Adding and substracting the brake force is correct for normal operation,
9751009
// but during wheelslip this will produce wrong results.
9761010
// The Axle module subtracts brake force from the motive force for calculation purposes. However brake force is already taken into account in the braking module.
977-
// And thus there is a duplication of the braking effect in OR. To compensate for this, after the slip characteristics have been calculated, the output of the axle module
978-
// has the brake force "added" back in to give the appropriate motive force output for the locomotive. Braking force is handled separately.
979-
// Hence CompensatedAxleForce is the actual output force on the axle.
1011+
// And thus there is a duplication of the braking effect in OR. To compensate for this, after the slip characteristics have been calculated, the output of the axle
1012+
// module has the brake force "added" back in to give the appropriate motive force output for the locomotive. Braking force is handled separately.
1013+
// Hence CompensatedAxleForce is the actual output force on the axle. Similarly friction is also handled separately so it is also discounted from the CompensatedForce.
9801014
if (Math.Abs(TrainSpeedMpS) < 0.001f && AxleForceN == 0) CompensatedAxleForceN = DriveForceN;
981-
else if (TrainSpeedMpS < 0) CompensatedAxleForceN = AxleForceN - BrakeRetardForceN;
982-
else CompensatedAxleForceN = AxleForceN + BrakeRetardForceN;
1015+
else if (TrainSpeedMpS < 0) CompensatedAxleForceN = AxleForceN - BrakeRetardForceN - FrictionN;
1016+
else CompensatedAxleForceN = AxleForceN + BrakeRetardForceN + FrictionN;
1017+
9831018
if (Math.Abs(SlipSpeedMpS) > WheelSlipThresholdMpS)
9841019
{
9851020
// Wait some time before indicating wheelslip to avoid false triggers
9861021
if (WheelSlipTimeS > 0.75f)
9871022
{
9881023
IsWheelSlip = IsWheelSlipWarning = true;
1024+
Trace.TraceInformation("Wheel Slip Triggered");
9891025
}
9901026
WheelSlipTimeS += timeSpan;
9911027
}
@@ -1140,14 +1176,14 @@ public double SlipCharacteristics(double slipSpeedMpS)
11401176

11411177
var fx = (f * Sx / Sc) / wheelLoadN;
11421178

1143-
/*
1179+
11441180
// if (slipSpeedMpS == 0.025f || slipSpeedMpS == 0.05f || slipSpeedMpS == 0.1f || slipSpeedMpS == 0.15f || slipSpeedMpS == 0.2f)
11451181
if (Axle.IsWheelSlip)
11461182
{
1147-
Trace.TraceInformation("Negative Fx - Fx {0} Speed {1} SlipSpeed {2} Sx {3} PolachAdhesion {4} adhesionComponent {5} slipComponent {6} Polach_Ks {7} Stiffness2 {8} SlipForce {9} Sc {10} WheelLoad {11} Syc {12} Hertz_a {13} Sy {14} Threshold {15}", fx, (float)trainSpeedMpS, (float)slipSpeedMpS, (float)Sx, polach_uadhesion, adhesionComponent, slipComponent, polach_Ks, Stiffness2, f, Sc, wheelLoadN, Syc, a_HertzianMM, Sy, Axle.WheelSlipThresholdMpS);
1183+
// Trace.TraceInformation("Negative Fx - Fx {0} Speed {1} SlipSpeed {2} Sx {3} PolachAdhesion {4} adhesionComponent {5} slipComponent {6} Polach_Ks {7} Stiffness2 {8} SlipForce {9} Sc {10} WheelLoad {11} Syc {12} Hertz_a {13} Sy {14} Threshold {15} DriveForce {16} Steps {17} IsWheelSlip {18} IsWheelSlipWarning {19}", fx, (float)trainSpeedMpS, (float)slipSpeedMpS, (float)Sx, polach_uadhesion, adhesionComponent, slipComponent, polach_Ks, Stiffness2, f, Sc, wheelLoadN, Syc, a_HertzianMM, Sy, Axle.WheelSlipThresholdMpS, Axle.DriveForceN, Axle.NumOfSubstepsPS, Axle.IsWheelSlip, Axle.IsWheelSlipWarning);
11481184

11491185
}
1150-
*/
1186+
11511187

11521188
return fx;
11531189
}

0 commit comments

Comments
 (0)