Skip to content

Commit 39938b2

Browse files
committed
Adjust adhesion / friction coefficient
1 parent ed282a5 commit 39938b2

File tree

1 file changed

+52
-45
lines changed

1 file changed

+52
-45
lines changed

Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
//#define ALLOW_ORTS_SPECIFIC_ENG_PARAMETERS
4343

4444
// Debug for Advanced Adhesion Model
45-
//#define DEBUG_ADHESION
45+
// #define DEBUG_ADHESION
4646

4747
using Microsoft.Xna.Framework;
4848
using Microsoft.Xna.Framework.Graphics;
@@ -223,6 +223,10 @@ public float CurrentLocomotiveSteamHeatBoilerWaterCapacityL
223223
float WheelSlipTimeS;
224224
float WheelStopSlipTimeS;
225225
float CurrentWheelSlipAdhesionMultiplier;
226+
float DebugTimer; // Used for debugging adhesion coefficient
227+
bool DebugSpeedReached = false; // Used for debugging adhesion coefficient
228+
float DebugSpeedIncrement = 1; // Used for debugging adhesion coefficient
229+
float DebugSpeed = 1; // Used for debugging adhesion coefficient
226230

227231
// parameters for Track Sander based upon compressor air and abrasive table for 1/2" sand blasting nozzle @ 50psi
228232
public float MaxTrackSandBoxCapacityM3 = Me3.FromFt3(40.0f); // Capacity of sandbox - assume 40.0 cu ft
@@ -2906,39 +2910,59 @@ public virtual void UpdateFrictionCoefficient(float elapsedClockSeconds)
29062910
{
29072911
float BaseuMax = (Curtius_KnifflerA / (MpS.ToKpH(AbsSpeedMpS) + Curtius_KnifflerB) + Curtius_KnifflerC); // Base Curtius - Kniffler equation - u = 0.33, all other values are scaled off this formula
29082912
float SandingFrictionCoefficientFactor = 1.0f;
2909-
//Set the friction coeff due to weather
2910-
if (Simulator.WeatherType == WeatherType.Rain || Simulator.WeatherType == WeatherType.Snow)
2913+
2914+
//Set the friction coeff due to weather - uses the vlaues set in the precipitation module to determine whether clear, rain or snow.
2915+
2916+
// Adjust clear weather for precipitation presence, ie base value between 60% and 80%
2917+
// note lowest friction will be for drizzle (light) rain; friction will increase for precipitation higher than drizzle rail
2918+
if (!Simulator.Paused)
29112919
{
2912-
if (Train.SlipperySpotDistanceM < 0)
2920+
var fogBaseFrictionCoefficientFactor = 0.0f;
2921+
var pricBaseFrictionCoefficientFactor = 0.0f;
2922+
float pric = Simulator.Weather.PricipitationIntensityPPSPM2 * 1000;
2923+
// precipitation will calculate a base coefficient value between 60% (light rain) and 80% (heavy rain) - this will be a factor that is used to adjust the base value - assume linear value between upper and lower precipitation values
2924+
if (pric >= 0.5)
2925+
pricBaseFrictionCoefficientFactor = Math.Min((pric - 0.5f) * 0.0078f + 0.6f, 0.8f); // should give a value between 0.6 and 0.8
2926+
else
2927+
pricBaseFrictionCoefficientFactor = 0.6f + 0.8f * (0.5f - pric); // should give a transition value between 1.0 and 0.6 as rain starts
2928+
2929+
// Adjust adhesion for impact of fog - default = 20000m = 20km
2930+
float fog = Simulator.Weather.FogDistance;
2931+
if (fog < 20000) // as fog thickens then decrease adhesion
29132932
{
2914-
Train.SlipperySpotLengthM = 10 + 40 * (float)Simulator.Random.NextDouble();
2915-
Train.SlipperySpotDistanceM = Train.SlipperySpotLengthM + 2000 * (float)Simulator.Random.NextDouble();
2933+
fogBaseFrictionCoefficientFactor = Math.Min((fog * 2.75e-4f + 0.6f), 1.0f); // If fog is less then 2km then it will impact friction, decrease adhesion to 60% (same as light rain transition)
29162934
}
2917-
if (Train.SlipperySpotDistanceM < Train.SlipperySpotLengthM)
2935+
else
29182936
{
2919-
BaseFrictionCoefficientFactor = 0.8f;
2937+
fogBaseFrictionCoefficientFactor = 1;
29202938
}
2921-
if (Simulator.WeatherType == WeatherType.Rain) // Wet weather
2939+
2940+
BaseFrictionCoefficientFactor = Math.Min(fogBaseFrictionCoefficientFactor, pricBaseFrictionCoefficientFactor);
2941+
}
2942+
2943+
// Random slippery track
2944+
if (Train.SlipperySpotDistanceM < 0)
2945+
{
2946+
Train.SlipperySpotLengthM = 10 + 40 * (float)Simulator.Random.NextDouble();
2947+
Train.SlipperySpotDistanceM = Train.SlipperySpotLengthM + 2000 * (float)Simulator.Random.NextDouble();
2948+
}
2949+
if (Train.SlipperySpotDistanceM < Train.SlipperySpotLengthM)
2950+
{
2951+
if (BaseFrictionCoefficientFactor > 0.6 && BaseFrictionCoefficientFactor < 0.8)
29222952
{
2923-
if (Simulator.Settings.AdhesionProportionalToWeather && AdvancedAdhesionModel && !Simulator.Paused) // Adjust clear weather for precipitation presence
2924-
// ie base value between 60% and 80% (TODO)
2925-
// note lowest friction will be for drizzle (light) rain; friction will increase for precipitation higher than drizzle rail
2926-
{
2927-
float pric = Simulator.Weather.PricipitationIntensityPPSPM2 * 1000;
2928-
// precipitation will calculate a base coefficient value between 60% (light rain) and 80% (heavy rain) - this will be a factor that is used to adjust the base value - assume linear value between upper and lower precipitation values
2929-
BaseFrictionCoefficientFactor = Math.Min((pric * 0.0078f + 0.6f), 0.8f); // should give a minimum value between 60% and 80%
2930-
}
2931-
else // if not proportional to precipitation use fixed friction value of 0.8 x friction coefficient value
2932-
{
2933-
BaseFrictionCoefficientFactor = 0.8f;
2934-
}
2953+
BaseFrictionCoefficientFactor = 0.6f;
29352954
}
2936-
else // Snow weather
2955+
else
29372956
{
2938-
BaseFrictionCoefficientFactor = 0.6f;
2957+
BaseFrictionCoefficientFactor = 0.8f;
29392958
}
2959+
}
29402960

2941-
//add sander - more effective in wet weather, so increases adhesion by more
2961+
BaseFrictionCoefficientFactor = MathHelper.Clamp(BaseFrictionCoefficientFactor, 0.5f, 1.0f);
2962+
2963+
if (Simulator.WeatherType == WeatherType.Rain || Simulator.WeatherType == WeatherType.Snow)
2964+
{
2965+
//sander - more effective in wet weather, so increases adhesion by more
29422966
if (AbsSpeedMpS < SanderSpeedOfMpS && CurrentTrackSandBoxCapacityM3 > 0.0 && MainResPressurePSI > 80.0 && (AbsSpeedMpS > 0))
29432967
{
29442968
if (SanderSpeedEffectUpToMpS > 0.0f)
@@ -2947,7 +2971,7 @@ public virtual void UpdateFrictionCoefficient(float elapsedClockSeconds)
29472971
{
29482972
SandingFrictionCoefficientFactor = (1.0f - 0.5f / SanderSpeedEffectUpToMpS * AbsSpeedMpS) * 1.75f;
29492973
BaseFrictionCoefficientFactor *= SandingFrictionCoefficientFactor;
2950-
2974+
29512975
}
29522976
}
29532977
else
@@ -2960,27 +2984,9 @@ public virtual void UpdateFrictionCoefficient(float elapsedClockSeconds)
29602984
}
29612985
}
29622986
}
2963-
else // Default to Dry (Clear) weather
2987+
else // dry weather
29642988
{
2965-
2966-
if (Simulator.Settings.AdhesionProportionalToWeather && AdvancedAdhesionModel && !Simulator.Paused) // Adjust clear weather for fog presence
2967-
{
2968-
float fog = Simulator.Weather.FogDistance;
2969-
if (fog > 2000)
2970-
{
2971-
BaseFrictionCoefficientFactor = 1.0f; // if fog is not too thick don't change the friction - minimal fog stay at clear adhesion
2972-
}
2973-
else
2974-
{
2975-
BaseFrictionCoefficientFactor = Math.Min((fog * 2.75e-4f + 0.6f), 1.0f); // If fog is less then 2km then it will impact friction, decrease adhesion to 60% (same as light rain transition)
2976-
}
2977-
}
2978-
else // if not proportional to fog use fixed friction value approximately equal to default 0.33 (will vary if adhesion parameters set), thus factor will be 1.0 x friction coefficient of 0.33
2979-
{
2980-
BaseFrictionCoefficientFactor = 1.0f;
2981-
}
2982-
2983-
//add sander - not as effective in dry weather
2989+
//sander - not as effective in dry weather
29842990
if (AbsSpeedMpS < SanderSpeedOfMpS && CurrentTrackSandBoxCapacityM3 > 0.0 && MainResPressurePSI > 80.0 && (AbsSpeedMpS > 0))
29852991
{
29862992
if (SanderSpeedEffectUpToMpS > 0.0f)
@@ -3000,6 +3006,7 @@ public virtual void UpdateFrictionCoefficient(float elapsedClockSeconds)
30003006
}
30013007
}
30023008
}
3009+
30033010
}
30043011

30053012
// For wagons use base Curtius-Kniffler adhesion factor - u = 0.33

0 commit comments

Comments
 (0)