Skip to content

Commit

Permalink
Further adjustments to substeps
Browse files Browse the repository at this point in the history
  • Loading branch information
peternewell committed Oct 24, 2023
1 parent 4213063 commit 1fdec87
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ public float SlipDerivationPercentpS
}

double integratorError;
int waitBeforeSpeedingUp;
int waitBeforeIntegreationRate;

/// <summary>
/// Read/Write relative slip speed warning threshold value, in percent of maximal effective slip
Expand Down Expand Up @@ -908,26 +908,38 @@ void Integrate(float elapsedClockSeconds)
var AdhesGrad = ((upperLimit - lowerLimit) / (WheelSlipThresholdMpS - 0));
var targetNumOfSubstepsPS = Math.Abs((AdhesGrad * SlipSpeedMpS) + lowerLimit);
if (float.IsNaN((float)targetNumOfSubstepsPS)) targetNumOfSubstepsPS = 1;

if (SlipSpeedMpS > WheelSlipThresholdMpS) // if in wheel slip then maximise the substeps
{
targetNumOfSubstepsPS = 130;
}

// Trace.TraceInformation("Grad - {0} AdhesGrad {1} SlipSpeedMps {2} Threshold {3}", temp, AdhesGrad, SlipSpeedMpS, WheelSlipThresholdMpS);

// if (targetNumOfSubstepsPS > NumOfSubstepsPS && Math.Abs(integratorError) > Math.Max((Math.Abs(SlipSpeedMpS) - 1) * 0.01, 0.001)) // increase substeps
if (targetNumOfSubstepsPS > NumOfSubstepsPS && Math.Abs(integratorError) > Math.Max((Math.Abs(SlipSpeedMpS) - 1) * 0.01, 0.001)) // increase substeps
if (Math.Abs(integratorError) < 0.000277 && !IsWheelSlip && !IsWheelSlipWarning && SlipSpeedMpS < 0.4 * WheelSlipThresholdMpS)
{
if (--waitBeforeSpeedingUp <= 0 ) //wait for a while before speeding up the integration
if (--waitBeforeIntegreationRate <= 0) //wait for a while before changing the integration rate
{
NumOfSubstepsPS += 5;
waitBeforeSpeedingUp = 5; //not so fast ;)
NumOfSubstepsPS -= 2;
waitBeforeIntegreationRate = 20;
}
}
else if (targetNumOfSubstepsPS < NumOfSubstepsPS) // decrease sub steps
// else if (targetNumOfSubstepsPS > NumOfSubstepsPS && Math.Abs(integratorError) > Math.Max((Math.Abs(SlipSpeedMpS) - 1) * 0.01, 0.001)) // increase substeps
else if (targetNumOfSubstepsPS > NumOfSubstepsPS) // increase substeps
{
NumOfSubstepsPS -= 5;
waitBeforeSpeedingUp = 5;
if (--waitBeforeIntegreationRate <= 0 ) //wait for a while before changing the integration rate
{
NumOfSubstepsPS += 5;
waitBeforeIntegreationRate = 30; //not so fast ;)
}
}
else if (Math.Abs(integratorError) < 0.000277)
else if (targetNumOfSubstepsPS < NumOfSubstepsPS) // decrease sub steps
{
NumOfSubstepsPS -= 2;
waitBeforeSpeedingUp = 5;
if (--waitBeforeIntegreationRate <= 0) //wait for a while before changing the integration rate
{
NumOfSubstepsPS -= 5;
waitBeforeIntegreationRate = 20;
}
}

if (NumOfSubstepsPS < lowerLimit)
Expand Down
4 changes: 2 additions & 2 deletions Source/RunActivity/Viewer3D/Popups/HUDWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public HUDWindow(WindowManager owner)
ForceGraphs = new HUDGraphSet(Viewer, HUDGraphMaterial);
ForceGraphMotiveForce = ForceGraphs.Add(Viewer.Catalog.GetString("Motive force"), "0%", "100%", Color.Green, 75);
ForceGraphDynamicForce = ForceGraphs.AddOverlapped(Color.Red, 75);
ForceGraphNumOfSubsteps = ForceGraphs.Add(Viewer.Catalog.GetString("Num of substeps"), "0", "50", Color.Blue, 25);
ForceGraphNumOfSubsteps = ForceGraphs.Add(Viewer.Catalog.GetString("Num of substeps"), "0", "100", Color.Blue, 25);

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

ForceGraphNumOfSubsteps.AddSample(loco.LocomotiveAxles.NumOfSubstepsPS / 50.0f);
ForceGraphNumOfSubsteps.AddSample(loco.LocomotiveAxles.NumOfSubstepsPS / 100.0f);

ForceGraphs.PrepareFrame(frame);
}
Expand Down

0 comments on commit 1fdec87

Please sign in to comment.