@@ -516,6 +516,11 @@ public float TransmissionEfficiency
516
516
/// </summary>
517
517
public float CurtiusKnifflerZeroSpeed ;
518
518
519
+ /// <summary>
520
+ /// Simulator FPS
521
+ /// </summary>
522
+ public float ScreenFrameRate ;
523
+
519
524
/// <summary>
520
525
/// Wheel adhesion as calculated by Polach
521
526
/// </summary>
@@ -643,15 +648,6 @@ public void ComputeWheelSlipThresholdMpS()
643
648
}
644
649
}
645
650
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
-
655
651
}
656
652
657
653
/// <summary>
@@ -878,53 +874,47 @@ void Integrate(float elapsedClockSeconds)
878
874
{
879
875
if ( elapsedClockSeconds <= 0 ) return ;
880
876
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 ;
886
881
887
- // Trace.TraceInformation("Algorithim Increase - Steps {0} Err {1}", NumOfSubstepsPS, integratorError);
882
+ var screenFrameUpperLimit = 60 ;
883
+ var screenFrameLowerLimit = 40 ;
888
884
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 ) ;
889
893
}
890
894
else
891
895
{
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 ) ;
899
897
}
900
898
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 ) ;
910
903
if ( float . IsNaN ( ( float ) targetNumOfSubstepsPS ) ) targetNumOfSubstepsPS = 1 ;
911
904
912
905
if ( SlipSpeedMpS > WheelSlipThresholdMpS ) // if in wheel slip then maximise the substeps
913
906
{
914
- targetNumOfSubstepsPS = 130 ;
907
+ targetNumOfSubstepsPS = upperSubStepLimit ;
915
908
}
916
909
917
- // Trace.TraceInformation("Grad - {0} AdhesGrad {1} SlipSpeedMps {2} Threshold {3}", temp, AdhesGrad, SlipSpeedMpS, WheelSlipThresholdMpS);
918
-
919
910
if ( Math . Abs ( integratorError ) < 0.000277 && ! IsWheelSlip && ! IsWheelSlipWarning && SlipSpeedMpS < 0.4 * WheelSlipThresholdMpS )
920
911
{
921
912
if ( -- waitBeforeIntegreationRate <= 0 ) //wait for a while before changing the integration rate
922
913
{
923
- NumOfSubstepsPS -= 2 ;
914
+ NumOfSubstepsPS -= 2 ; // decrease substeps when under low slip conditions
924
915
waitBeforeIntegreationRate = 20 ;
925
916
}
926
917
}
927
- // else if (targetNumOfSubstepsPS > NumOfSubstepsPS && Math.Abs(integratorError) > Math.Max((Math.Abs(SlipSpeedMpS) - 1) * 0.01, 0.001)) // increase substeps
928
918
else if ( targetNumOfSubstepsPS > NumOfSubstepsPS ) // increase substeps
929
919
{
930
920
if ( -- waitBeforeIntegreationRate <= 0 ) //wait for a while before changing the integration rate
@@ -942,13 +932,11 @@ void Integrate(float elapsedClockSeconds)
942
932
}
943
933
}
944
934
945
- if ( NumOfSubstepsPS < lowerLimit )
946
- NumOfSubstepsPS = lowerLimit ;
935
+ if ( NumOfSubstepsPS < lowerSubStepLimit )
936
+ NumOfSubstepsPS = lowerSubStepLimit ;
947
937
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 ;
952
940
953
941
double dt = elapsedClockSeconds / NumOfSubstepsPS ;
954
942
double hdt = dt / 2 ;
@@ -957,18 +945,6 @@ void Integrate(float elapsedClockSeconds)
957
945
for ( int i = 0 ; i < NumOfSubstepsPS ; i ++ )
958
946
{
959
947
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
- */
972
948
var k2 = GetAxleMotionVariation ( AxleSpeedMpS + k1 . Item1 * hdt , hdt ) ;
973
949
var k3 = GetAxleMotionVariation ( AxleSpeedMpS + k2 . Item1 * hdt , hdt ) ;
974
950
var k4 = GetAxleMotionVariation ( AxleSpeedMpS + k3 . Item1 * dt , dt ) ;
@@ -998,8 +974,6 @@ public virtual void Update(float timeSpan)
998
974
axleStaticForceN = AxleWeightN * SlipCharacteristics ( 0 ) ;
999
975
ComputeWheelSlipThresholdMpS ( ) ;
1000
976
1001
- // Trace.TraceInformation("Threshold - Threshold {0} SlipSpeed {1} Speed {2}", WheelSlipThresholdMpS, SlipSpeedMpS, TrainSpeedMpS);
1002
-
1003
977
if ( count < 6 && count ++ == 5 )
1004
978
{
1005
979
TrainSpeedMpS = 10 / 3.6f ;
@@ -1050,7 +1024,6 @@ public virtual void Update(float timeSpan)
1050
1024
if ( WheelSlipTimeS > 1 )
1051
1025
{
1052
1026
IsWheelSlip = IsWheelSlipWarning = true ;
1053
- // Trace.TraceInformation("Wheel Slip Triggered");
1054
1027
}
1055
1028
WheelSlipTimeS += timeSpan ;
1056
1029
}
@@ -1153,13 +1126,9 @@ public void Update()
1153
1126
if ( float . IsNaN ( ( float ) Sy ) ) Sy = 0 ; //avoid NaN when first starting OR
1154
1127
Sy2 = Sy * Sy ;
1155
1128
1156
- // Trace.TraceInformation("Spin - {0} FlangeAngle {1} wheelRadius {2} Speed {3}", spinM1, Axle.WheelFlangeAngleRad, wheelRadiusMM, trainSpeedMpS);
1157
-
1158
1129
Syc = Sy + ( spinM1 * a_HertzianM ) ;
1159
1130
Syc2 = Syc * Syc ;
1160
1131
1161
- // Trace.TraceInformation("Sy - {0} Syc {1} Spin {2} a_hertz {3}", Sy, Syc, spinM1, a_HertzianMM);
1162
-
1163
1132
// 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
1164
1133
// Taking them lower may reduce the stability of the calculations
1165
1134
polach_A = 0.4 ;
@@ -1176,8 +1145,6 @@ public double SlipCharacteristics(double slipSpeedMpS)
1176
1145
{
1177
1146
var polach_uadhesion = zeroSpeedAdhesion * ( ( ( 1 - polach_A ) * Math . Exp ( - polach_B * slipSpeedMpS ) ) + polach_A ) ;
1178
1147
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
-
1181
1148
if ( trainSpeedMpS < 0.05f )
1182
1149
return polach_uadhesion ;
1183
1150
@@ -1205,15 +1172,6 @@ public double SlipCharacteristics(double slipSpeedMpS)
1205
1172
1206
1173
var fx = ( f * Sx / Sc ) / wheelLoadN ;
1207
1174
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
-
1217
1175
return fx ;
1218
1176
}
1219
1177
}
0 commit comments