Skip to content

Commit 9da5a60

Browse files
committed
Automatic merge of T1.5.1-770-g1f196a324 and 16 pull requests
- Pull request #570 at 3539862: Experimental glTF 2.0 support with PBR lighting - Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters - Pull request #875 at 43bf33e: Bug fix for https://bugs.launchpad.net/or/+bug/2036346 Player train switching doesn't work with 3D cabs - Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder - Pull request #882 at a055bca: Blueprint/train car operations UI window - Pull request #885 at d9ce84b: feat: Add notifications to Menu - Pull request #886 at 6c0785b: Scene viewer extension to TrackViewer - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #893 at bf8876b: Signal errors - Pull request #894 at 5ff1e73: Correct Decrease Colour - Pull request #896 at 5866028: First implementation of https://blueprints.launchpad.net/or/+spec/specific-sounds-for-ai-trains - Pull request #897 at 0a9d939: feat: Improved system information collection - Pull request #898 at 2d1b44a: Extra line with all the arguments for debugging purposes in logfile - Pull request #899 at c17fdb3: Duplex steam engines - Booster Engine addition - Pull request #903 at a0d2991: first phase downloading from Github - Pull request #904 at 8dc3628: fix: adds downgrade to low precision
18 parents d6cf5ab + 1f196a3 + 3539862 + d00beb9 + 43bf33e + f92de76 + a055bca + d9ce84b + 6c0785b + 1f5ba4c + bf8876b + 5ff1e73 + 5866028 + 0a9d939 + 2d1b44a + c17fdb3 + a0d2991 + 8dc3628 commit 9da5a60

File tree

1 file changed

+69
-35
lines changed
  • Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerTransmissions

1 file changed

+69
-35
lines changed

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

Lines changed: 69 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
using Orts.Simulation.RollingStocks.SubSystems.PowerTransmissions;
3030
using SharpDX.Direct2D1;
3131
using SharpDX.Direct3D9;
32+
using Orts.Formats.OR;
33+
using static Orts.Simulation.RollingStocks.SubSystems.PowerTransmissions.Axle;
3234

3335
namespace Orts.Simulation.RollingStocks.SubSystems.PowerTransmissions
3436
{
@@ -1017,37 +1019,13 @@ void Integrate(float elapsedClockSeconds)
10171019
/// - computes axle dynamic model according to its driveType
10181020
/// - computes wheelslip indicators
10191021
/// </summary>
1020-
/// <param name="timeSpan"></param>
1021-
public virtual void Update(float timeSpan)
1022+
/// <param name="elapsedSeconds"></param>
1023+
public virtual void Update(float elapsedSeconds)
10221024
{
1023-
// Test to determine whether to use Polach or Pacha adhesion
1024-
1025-
// Switches between Polach (high performance) adhesion model and Pacha (low performance) adhesion model depending upon the PC performance
1026-
if(timeSpan < 0.025) // timespan 0.025 = 40 fps screen rate, low timeSpan and high FPS
1027-
{
1028-
UsePolachAdhesion = true;
1029-
}
1030-
else if(timeSpan > 0.033) // timespan 0.033 = 30 fps screen rate, high timeSpan and low FPS
1031-
{
1032-
UsePolachAdhesion = false;
1033-
if (TrainSpeedMpS > 0 )
1034-
{
1035-
var ScreenFrameRate = 1 / timeSpan;
1036-
Trace.TraceInformation("Advanced adhesion model switched to low performance option due to low frame rate {0} at ElapsedClockSeconds of {1}", ScreenFrameRate, timeSpan);
1037-
1038-
}
1039-
1040-
// Set values for Pacha adhesion
1041-
WheelSlipThresholdMpS = MpS.FromKpH(AdhesionK / AdhesionLimit);
1042-
WheelAdhesion = 0.99f;
1043-
MaximumPolachWheelAdhesion = 0.99f;
1044-
1045-
}
1046-
1047-
forceToAccelerationFactor = WheelRadiusM * WheelRadiusM / totalInertiaKgm2;
1048-
1025+
UsePolachAdhesion = AdhesionPrecision.IsPrecisionHigh(elapsedSeconds);
10491026
if (UsePolachAdhesion)
10501027
{
1028+
forceToAccelerationFactor = WheelRadiusM * WheelRadiusM / totalInertiaKgm2;
10511029

10521030
Polach.Update();
10531031
axleStaticForceN = AxleWeightN * SlipCharacteristicsPolach(0);
@@ -1060,6 +1038,15 @@ public virtual void Update(float timeSpan)
10601038
axleStaticForceN = AxleWeightN * SlipCharacteristicsPolach(0);
10611039
}
10621040
}
1041+
else
1042+
{
1043+
// Set values for Pacha adhesion
1044+
WheelSlipThresholdMpS = MpS.FromKpH(AdhesionK / AdhesionLimit);
1045+
WheelAdhesion = 0.99f;
1046+
MaximumPolachWheelAdhesion = 0.99f;
1047+
1048+
forceToAccelerationFactor = WheelRadiusM * WheelRadiusM / totalInertiaKgm2;
1049+
}
10631050

10641051
#if DEBUG_ADHESION
10651052
double[] spd = new double[50];
@@ -1084,9 +1071,9 @@ public virtual void Update(float timeSpan)
10841071
Console.WriteLine("");
10851072
#endif
10861073

1087-
motor?.Update(timeSpan);
1074+
motor?.Update(elapsedSeconds);
10881075

1089-
Integrate(timeSpan);
1076+
Integrate(elapsedSeconds);
10901077
// TODO: We should calculate brake force here
10911078
// Adding and substracting the brake force is correct for normal operation,
10921079
// but during wheelslip this will produce wrong results.
@@ -1114,14 +1101,14 @@ public virtual void Update(float timeSpan)
11141101
{
11151102
IsWheelSlip = IsWheelSlipWarning = true;
11161103
}
1117-
WheelSlipTimeS += timeSpan;
1104+
WheelSlipTimeS += elapsedSeconds;
11181105
}
11191106
else if (Math.Abs(SlipSpeedPercent) > SlipWarningTresholdPercent)
11201107
{
11211108
// Wait some time before indicating wheelslip to avoid false triggers
11221109
if (WheelSlipWarningTimeS > 1) IsWheelSlipWarning = true;
11231110
IsWheelSlip = false;
1124-
WheelSlipWarningTimeS += timeSpan;
1111+
WheelSlipWarningTimeS += elapsedSeconds;
11251112
}
11261113
else
11271114
{
@@ -1130,16 +1117,62 @@ public virtual void Update(float timeSpan)
11301117
WheelSlipWarningTimeS = WheelSlipTimeS = 0;
11311118
}
11321119

1133-
if (timeSpan > 0.0f)
1120+
if (elapsedSeconds > 0.0f)
11341121
{
1135-
slipDerivationMpSS = (SlipSpeedMpS - previousSlipSpeedMpS) / timeSpan;
1122+
slipDerivationMpSS = (SlipSpeedMpS - previousSlipSpeedMpS) / elapsedSeconds;
11361123
previousSlipSpeedMpS = SlipSpeedMpS;
11371124

1138-
slipDerivationPercentpS = (SlipSpeedPercent - previousSlipPercent) / timeSpan;
1125+
slipDerivationPercentpS = (SlipSpeedPercent - previousSlipPercent) / elapsedSeconds;
11391126
previousSlipPercent = SlipSpeedPercent;
11401127
}
11411128
}
11421129

1130+
static class AdhesionPrecision // "static" so all "Axle"s share the same level of precision
1131+
{
1132+
enum AdhesionPrecisionLevel
1133+
{
1134+
/// <summary>
1135+
/// Initial level uses Polach algorithm
1136+
/// </summary>
1137+
High,
1138+
/// <summary>
1139+
/// Low-performance PCs use Pacha's algorithm
1140+
/// </summary>
1141+
Low
1142+
}
1143+
1144+
static AdhesionPrecisionLevel PrecisionLevel = AdhesionPrecisionLevel.High;
1145+
static double TimeOfLatestDowngrade = 0;
1146+
1147+
// Adjustable limits
1148+
const float UpperLimitS = 0.033f; // timespan 0.033 = 30 fps screen rate, high timeSpan and low FPS
1149+
1150+
// Tested by varying the framerate interactively. Did this by opening and closing the HelpWindow after inserting
1151+
// Threading.Thread.Sleep(40);
1152+
// into HelpWindow.PrepareFrame() temporarily.
1153+
public static bool IsPrecisionHigh(float elapsedSeconds)
1154+
{
1155+
// Switches between Polach (high precision) adhesion model and Pacha (low precision) adhesion model depending upon the PC performance
1156+
switch (PrecisionLevel)
1157+
{
1158+
case AdhesionPrecisionLevel.High:
1159+
if (elapsedSeconds > UpperLimitS)
1160+
{
1161+
var screenFrameRate = 1 / elapsedSeconds;
1162+
{
1163+
Trace.TraceInformation($"Advanced adhesion model switched to low precision permanently after low frame rate {screenFrameRate:F1} below limit {1 / UpperLimitS:F0}");
1164+
PrecisionLevel = AdhesionPrecisionLevel.Low;
1165+
}
1166+
}
1167+
break;
1168+
1169+
case AdhesionPrecisionLevel.Low:
1170+
break;
1171+
}
1172+
return (PrecisionLevel == AdhesionPrecisionLevel.High);
1173+
}
1174+
}
1175+
11431176
class PolachCalculator
11441177
{
11451178
Axle Axle;
@@ -1230,6 +1263,7 @@ public void Update()
12301263
polach_Ks = (1.2 * zeroSpeedAdhesion) - 0.26;
12311264
if (polach_Ks < 0.1) polach_Ks = 0.1f;
12321265
}
1266+
12331267
public double SlipCharacteristics(double slipSpeedMpS)
12341268
{
12351269
var polach_uadhesion = zeroSpeedAdhesion * (((1 - polach_A) * Math.Exp(-polach_B * slipSpeedMpS)) + polach_A);

0 commit comments

Comments
 (0)