@@ -516,6 +516,11 @@ public float TransmissionEfficiency
516516 /// </summary>
517517 public float CurtiusKnifflerZeroSpeed ;
518518
519+ /// <summary>
520+ /// Simulator FPS
521+ /// </summary>
522+ public float ScreenFrameRate ;
523+
519524 /// <summary>
520525 /// Wheel adhesion as calculated by Polach
521526 /// </summary>
@@ -643,15 +648,6 @@ public void ComputeWheelSlipThresholdMpS()
643648 }
644649 }
645650 WheelSlipThresholdMpS = ( float ) Math . Max ( ( a + b ) / 2 , MpS . FromKpH ( 0.1f ) ) ;
646-
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- }
654-
655651 }
656652
657653 /// <summary>
@@ -878,53 +874,47 @@ void Integrate(float elapsedClockSeconds)
878874 {
879875 if ( elapsedClockSeconds <= 0 ) return ;
880876 double prevSpeedMpS = AxleSpeedMpS ;
881- /*
882- if (Math.Abs(integratorError) > Math.Max((Math.Abs(SlipSpeedMpS) - 1) * 0.01, 0.001))
883- {
884- ++NumOfSubstepsPS;
885- waitBeforeSpeedingUp = 100;
877+
878+ var upperSubStepStartingLimit = 120 ;
879+ var upperSubStepLimit = upperSubStepStartingLimit ;
880+ var lowerSubStepLimit = 1 ;
886881
887- // Trace.TraceInformation("Algorithim Increase - Steps {0} Err {1}", NumOfSubstepsPS, integratorError);
882+ var screenFrameUpperLimit = 60 ;
883+ var screenFrameLowerLimit = 40 ;
888884
885+ // Reduces the number of substeps if screen FPS drops
886+ if ( ScreenFrameRate >= screenFrameUpperLimit )
887+ {
888+ upperSubStepLimit = upperSubStepStartingLimit ;
889+ }
890+ else if ( ScreenFrameRate < screenFrameLowerLimit )
891+ {
892+ upperSubStepLimit = upperSubStepStartingLimit * ( screenFrameLowerLimit / screenFrameUpperLimit ) ;
889893 }
890894 else
891895 {
892- if (--waitBeforeSpeedingUp <= 0) //wait for a while before speeding up the integration
893- {
894- --NumOfSubstepsPS;
895- waitBeforeSpeedingUp = 10; //not so fast ;)
896-
897- // Trace.TraceInformation("Algorithim Decrease - Steps {0} Err {1}", NumOfSubstepsPS, integratorError);
898- }
896+ upperSubStepLimit = ( int ) ( ( ScreenFrameRate / 60 ) * upperSubStepStartingLimit ) ;
899897 }
900898
901- NumOfSubstepsPS = Math.Max(Math.Min(NumOfSubstepsPS, 130), 1);
902- */
903- // use straight line graph approximation
904- // Points are 1 = (0, upperLimit) and 2 = (threshold, lowerLimit)
905-
906- var upperLimit = 130 ;
907- var lowerLimit = 1 ;
908- var AdhesGrad = ( ( upperLimit - lowerLimit ) / ( WheelSlipThresholdMpS - 0 ) ) ;
909- var targetNumOfSubstepsPS = Math . Abs ( ( AdhesGrad * SlipSpeedMpS ) + lowerLimit ) ;
899+ // use straight line graph approximation to increase substeps as slipspeed increases towards the threshold speed point
900+ // Points are 1 = (0, upperLimit) and 2 = (threshold, lowerLimit)
901+ var AdhesGrad = ( ( upperSubStepLimit - lowerSubStepLimit ) / ( WheelSlipThresholdMpS - 0 ) ) ;
902+ var targetNumOfSubstepsPS = Math . Abs ( ( AdhesGrad * SlipSpeedMpS ) + lowerSubStepLimit ) ;
910903 if ( float . IsNaN ( ( float ) targetNumOfSubstepsPS ) ) targetNumOfSubstepsPS = 1 ;
911904
912905 if ( SlipSpeedMpS > WheelSlipThresholdMpS ) // if in wheel slip then maximise the substeps
913906 {
914- targetNumOfSubstepsPS = 130 ;
907+ targetNumOfSubstepsPS = upperSubStepLimit ;
915908 }
916909
917- // Trace.TraceInformation("Grad - {0} AdhesGrad {1} SlipSpeedMps {2} Threshold {3}", temp, AdhesGrad, SlipSpeedMpS, WheelSlipThresholdMpS);
918-
919910 if ( Math . Abs ( integratorError ) < 0.000277 && ! IsWheelSlip && ! IsWheelSlipWarning && SlipSpeedMpS < 0.4 * WheelSlipThresholdMpS )
920911 {
921912 if ( -- waitBeforeIntegreationRate <= 0 ) //wait for a while before changing the integration rate
922913 {
923- NumOfSubstepsPS -= 2 ;
914+ NumOfSubstepsPS -= 2 ; // decrease substeps when under low slip conditions
924915 waitBeforeIntegreationRate = 20 ;
925916 }
926917 }
927- // else if (targetNumOfSubstepsPS > NumOfSubstepsPS && Math.Abs(integratorError) > Math.Max((Math.Abs(SlipSpeedMpS) - 1) * 0.01, 0.001)) // increase substeps
928918 else if ( targetNumOfSubstepsPS > NumOfSubstepsPS ) // increase substeps
929919 {
930920 if ( -- waitBeforeIntegreationRate <= 0 ) //wait for a while before changing the integration rate
@@ -942,13 +932,11 @@ void Integrate(float elapsedClockSeconds)
942932 }
943933 }
944934
945- if ( NumOfSubstepsPS < lowerLimit )
946- NumOfSubstepsPS = lowerLimit ;
935+ if ( NumOfSubstepsPS < lowerSubStepLimit )
936+ NumOfSubstepsPS = lowerSubStepLimit ;
947937
948- if ( NumOfSubstepsPS > upperLimit )
949- NumOfSubstepsPS = upperLimit ;
950-
951- // Trace.TraceInformation("Grad - {0} AdhesGrad {1} SlipSpeedMps {2} Threshold {3} NumStepsPS {4} Error {5}", targetNumOfSubstepsPS, AdhesGrad, SlipSpeedMpS, WheelSlipThresholdMpS, NumOfSubstepsPS, integratorError);
938+ if ( NumOfSubstepsPS > upperSubStepLimit )
939+ NumOfSubstepsPS = upperSubStepLimit ;
952940
953941 double dt = elapsedClockSeconds / NumOfSubstepsPS ;
954942 double hdt = dt / 2 ;
@@ -957,18 +945,6 @@ void Integrate(float elapsedClockSeconds)
957945 for ( int i = 0 ; i < NumOfSubstepsPS ; i ++ )
958946 {
959947 var k1 = GetAxleMotionVariation ( AxleSpeedMpS , dt ) ;
960- /*
961- if (i == 0)
962- {
963- if (k1.Item1 * dt > Math.Max((Math.Abs(SlipSpeedMpS) - 1) * 10, 1) / 100)
964- {
965- // NumOfSubstepsPS = Math.Min(NumOfSubstepsPS + 5, 130);
966- // Trace.TraceInformation("Algorithim Change - k1 - Number of Steps {0}", NumOfSubstepsPS);
967- dt = elapsedClockSeconds / NumOfSubstepsPS;
968- hdt = dt / 2;
969- }
970- }
971- */
972948 var k2 = GetAxleMotionVariation ( AxleSpeedMpS + k1 . Item1 * hdt , hdt ) ;
973949 var k3 = GetAxleMotionVariation ( AxleSpeedMpS + k2 . Item1 * hdt , hdt ) ;
974950 var k4 = GetAxleMotionVariation ( AxleSpeedMpS + k3 . Item1 * dt , dt ) ;
@@ -998,8 +974,6 @@ public virtual void Update(float timeSpan)
998974 axleStaticForceN = AxleWeightN * SlipCharacteristics ( 0 ) ;
999975 ComputeWheelSlipThresholdMpS ( ) ;
1000976
1001- // Trace.TraceInformation("Threshold - Threshold {0} SlipSpeed {1} Speed {2}", WheelSlipThresholdMpS, SlipSpeedMpS, TrainSpeedMpS);
1002-
1003977 if ( count < 6 && count ++ == 5 )
1004978 {
1005979 TrainSpeedMpS = 10 / 3.6f ;
@@ -1050,7 +1024,6 @@ public virtual void Update(float timeSpan)
10501024 if ( WheelSlipTimeS > 1 )
10511025 {
10521026 IsWheelSlip = IsWheelSlipWarning = true ;
1053- // Trace.TraceInformation("Wheel Slip Triggered");
10541027 }
10551028 WheelSlipTimeS += timeSpan ;
10561029 }
@@ -1153,13 +1126,9 @@ public void Update()
11531126 if ( float . IsNaN ( ( float ) Sy ) ) Sy = 0 ; //avoid NaN when first starting OR
11541127 Sy2 = Sy * Sy ;
11551128
1156- // Trace.TraceInformation("Spin - {0} FlangeAngle {1} wheelRadius {2} Speed {3}", spinM1, Axle.WheelFlangeAngleRad, wheelRadiusMM, trainSpeedMpS);
1157-
11581129 Syc = Sy + ( spinM1 * a_HertzianM ) ;
11591130 Syc2 = Syc * Syc ;
11601131
1161- // Trace.TraceInformation("Sy - {0} Syc {1} Spin {2} a_hertz {3}", Sy, Syc, spinM1, a_HertzianMM);
1162-
11631132 // calculate "standard" Polach adhesion parameters as straight line approximations as u varies - these values are capped at the moment at the u=0.3 level
11641133 // Taking them lower may reduce the stability of the calculations
11651134 polach_A = 0.4 ;
@@ -1176,8 +1145,6 @@ public double SlipCharacteristics(double slipSpeedMpS)
11761145 {
11771146 var polach_uadhesion = zeroSpeedAdhesion * ( ( ( 1 - polach_A ) * Math . Exp ( - polach_B * slipSpeedMpS ) ) + polach_A ) ;
11781147
1179- // Trace.TraceInformation("Polach Adhesion - {0} ZeroAdhesion {1} RawPolach {2} SlipSpeed {3}", polach_uadhesion, zeroSpeedAdhesion, (((1 - polach_A) * Math.Exp(-polach_B * slipSpeedMpS)) + polach_A), slipSpeedMpS);
1180-
11811148 if ( trainSpeedMpS < 0.05f )
11821149 return polach_uadhesion ;
11831150
@@ -1205,15 +1172,6 @@ public double SlipCharacteristics(double slipSpeedMpS)
12051172
12061173 var fx = ( f * Sx / Sc ) / wheelLoadN ;
12071174
1208-
1209- // if (slipSpeedMpS == 0.025f || slipSpeedMpS == 0.05f || slipSpeedMpS == 0.1f || slipSpeedMpS == 0.15f || slipSpeedMpS == 0.2f)
1210- if ( Axle . IsWheelSlip )
1211- {
1212- // 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);
1213-
1214- }
1215-
1216-
12171175 return fx ;
12181176 }
12191177 }
0 commit comments