Skip to content

Commit 1fdec87

Browse files
committed
Further adjustments to substeps
1 parent 4213063 commit 1fdec87

File tree

2 files changed

+26
-14
lines changed
  • Source
    • Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerTransmissions
    • RunActivity/Viewer3D/Popups

2 files changed

+26
-14
lines changed

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ public float SlipDerivationPercentpS
728728
}
729729

730730
double integratorError;
731-
int waitBeforeSpeedingUp;
731+
int waitBeforeIntegreationRate;
732732

733733
/// <summary>
734734
/// Read/Write relative slip speed warning threshold value, in percent of maximal effective slip
@@ -908,26 +908,38 @@ void Integrate(float elapsedClockSeconds)
908908
var AdhesGrad = ((upperLimit - lowerLimit) / (WheelSlipThresholdMpS - 0));
909909
var targetNumOfSubstepsPS = Math.Abs((AdhesGrad * SlipSpeedMpS) + lowerLimit);
910910
if (float.IsNaN((float)targetNumOfSubstepsPS)) targetNumOfSubstepsPS = 1;
911+
912+
if (SlipSpeedMpS > WheelSlipThresholdMpS) // if in wheel slip then maximise the substeps
913+
{
914+
targetNumOfSubstepsPS = 130;
915+
}
916+
911917
// Trace.TraceInformation("Grad - {0} AdhesGrad {1} SlipSpeedMps {2} Threshold {3}", temp, AdhesGrad, SlipSpeedMpS, WheelSlipThresholdMpS);
912918

913-
// if (targetNumOfSubstepsPS > NumOfSubstepsPS && Math.Abs(integratorError) > Math.Max((Math.Abs(SlipSpeedMpS) - 1) * 0.01, 0.001)) // increase substeps
914-
if (targetNumOfSubstepsPS > NumOfSubstepsPS && Math.Abs(integratorError) > Math.Max((Math.Abs(SlipSpeedMpS) - 1) * 0.01, 0.001)) // increase substeps
919+
if (Math.Abs(integratorError) < 0.000277 && !IsWheelSlip && !IsWheelSlipWarning && SlipSpeedMpS < 0.4 * WheelSlipThresholdMpS)
915920
{
916-
if (--waitBeforeSpeedingUp <= 0 ) //wait for a while before speeding up the integration
921+
if (--waitBeforeIntegreationRate <= 0) //wait for a while before changing the integration rate
917922
{
918-
NumOfSubstepsPS += 5;
919-
waitBeforeSpeedingUp = 5; //not so fast ;)
923+
NumOfSubstepsPS -= 2;
924+
waitBeforeIntegreationRate = 20;
920925
}
921926
}
922-
else if (targetNumOfSubstepsPS < NumOfSubstepsPS) // decrease sub steps
927+
// else if (targetNumOfSubstepsPS > NumOfSubstepsPS && Math.Abs(integratorError) > Math.Max((Math.Abs(SlipSpeedMpS) - 1) * 0.01, 0.001)) // increase substeps
928+
else if (targetNumOfSubstepsPS > NumOfSubstepsPS) // increase substeps
923929
{
924-
NumOfSubstepsPS -= 5;
925-
waitBeforeSpeedingUp = 5;
930+
if (--waitBeforeIntegreationRate <= 0 ) //wait for a while before changing the integration rate
931+
{
932+
NumOfSubstepsPS += 5;
933+
waitBeforeIntegreationRate = 30; //not so fast ;)
934+
}
926935
}
927-
else if (Math.Abs(integratorError) < 0.000277)
936+
else if (targetNumOfSubstepsPS < NumOfSubstepsPS) // decrease sub steps
928937
{
929-
NumOfSubstepsPS -= 2;
930-
waitBeforeSpeedingUp = 5;
938+
if (--waitBeforeIntegreationRate <= 0) //wait for a while before changing the integration rate
939+
{
940+
NumOfSubstepsPS -= 5;
941+
waitBeforeIntegreationRate = 20;
942+
}
931943
}
932944

933945
if (NumOfSubstepsPS < lowerLimit)

Source/RunActivity/Viewer3D/Popups/HUDWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public HUDWindow(WindowManager owner)
112112
ForceGraphs = new HUDGraphSet(Viewer, HUDGraphMaterial);
113113
ForceGraphMotiveForce = ForceGraphs.Add(Viewer.Catalog.GetString("Motive force"), "0%", "100%", Color.Green, 75);
114114
ForceGraphDynamicForce = ForceGraphs.AddOverlapped(Color.Red, 75);
115-
ForceGraphNumOfSubsteps = ForceGraphs.Add(Viewer.Catalog.GetString("Num of substeps"), "0", "50", Color.Blue, 25);
115+
ForceGraphNumOfSubsteps = ForceGraphs.Add(Viewer.Catalog.GetString("Num of substeps"), "0", "100", Color.Blue, 25);
116116

117117
DebugGraphs = new HUDGraphSet(Viewer, HUDGraphMaterial);
118118
DebugGraphMemory = DebugGraphs.Add(Viewer.Catalog.GetString("Memory"), "0GB", String.Format("{0:F0}GB", (float)Host.CPUMemoryVirtualLimit / 1024 / 1024 / 1024), Color.Orange, 50);
@@ -201,7 +201,7 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime, bo
201201
ForceGraphDynamicForce.AddSample(-loco.MotiveForceN / loco.MaxForceN);
202202
}
203203

204-
ForceGraphNumOfSubsteps.AddSample(loco.LocomotiveAxles.NumOfSubstepsPS / 50.0f);
204+
ForceGraphNumOfSubsteps.AddSample(loco.LocomotiveAxles.NumOfSubstepsPS / 100.0f);
205205

206206
ForceGraphs.PrepareFrame(frame);
207207
}

0 commit comments

Comments
 (0)