Skip to content

Commit 00a89a0

Browse files
committed
Handle power limitation for diesels
1 parent 9aecb14 commit 00a89a0

File tree

6 files changed

+36
-29
lines changed

6 files changed

+36
-29
lines changed

Source/Orts.Simulation/Common/Scripting/PowerSupply/ElectricPowerSupply.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,6 @@ protected float PantographVoltageVDC
128128
/// </summary>
129129
protected void SetFilterVoltageV(float voltage) => EpsHost.FilterVoltageV = voltage;
130130

131-
/// <summary>
132-
/// Maximum power of the locomotive
133-
/// </summary>
134-
protected float MaximumPowerW
135-
{
136-
get => EpsHost.MaximumPowerW;
137-
set => EpsHost.MaximumPowerW = value;
138-
}
139-
140131
/// <summary>
141132
/// Sends an event to the circuit breaker
142133
/// </summary>

Source/Orts.Simulation/Common/Scripting/PowerSupply/LocomotivePowerSupply.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ protected DieselEngineState CurrentHelperEnginesState()
8989
return state;
9090
}
9191

92+
/// <summary>
93+
/// Power limit for traction motors
94+
/// </summary>
95+
protected float MaximumPowerW
96+
{
97+
get => LpsHost.MaximumPowerW;
98+
set => LpsHost.MaximumPowerW = value;
99+
}
100+
92101
/// <summary>
93102
/// Current availability of the dynamic brake
94103
/// </summary>

Source/Orts.Simulation/Simulation/RollingStocks/MSTSDieselLocomotive.cs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -685,27 +685,29 @@ protected override void UpdateTractiveForce(float elapsedClockSeconds, float t,
685685

686686
if (TractiveForceCurves == null)
687687
{
688-
// This sets the maximum force of the locomotive, it will be adjusted down if it exceeds the max power of the locomotive.
689-
float maxForceN = Math.Min(t * MaxForceN * (1 - PowerReduction), AbsTractionSpeedMpS == 0.0f ? (t * MaxForceN * (1 - PowerReduction)) : (t * LocomotiveMaxRailOutputPowerW / AbsTractionSpeedMpS));
690-
691-
// Maximum rail power is reduced by apparent throttle factor and the number of engines running (power ratio)
692-
float maxPowerW = LocomotiveMaxRailOutputPowerW * DieselEngineFractionPower * LocomotiveApparentThrottleSetting;
693-
694-
// If unloading speed is in ENG file, and locomotive speed is greater then unloading speed, and less then max speed, then apply a decay factor to the power/force
695-
if (UnloadingSpeedMpS != 0 && AbsTractionSpeedMpS > UnloadingSpeedMpS && AbsTractionSpeedMpS < MaxSpeedMpS && !WheelSlip)
696-
{
697-
// use straight line curve to decay power to zero by 2 x unloading speed
698-
float unloadingspeeddecay = 1.0f - (1.0f / UnloadingSpeedMpS) * (AbsTractionSpeedMpS - UnloadingSpeedMpS);
699-
unloadingspeeddecay = MathHelper.Clamp(unloadingspeeddecay, 0.0f, 1.0f); // Clamp decay within bounds
700-
maxPowerW *= unloadingspeeddecay;
701-
}
702-
703688
if (DieselEngines.HasGearBox)
704689
{
705690
TractiveForceN = DieselEngines.TractiveForceN;
706691
}
707692
else
708693
{
694+
// This sets the maximum force of the locomotive, it will be adjusted down if it exceeds the max power of the locomotive.
695+
float maxForceN = Math.Min(t * MaxForceN * (1 - PowerReduction), AbsTractionSpeedMpS == 0.0f ? (t * MaxForceN * (1 - PowerReduction)) : (t * LocomotiveMaxRailOutputPowerW / AbsTractionSpeedMpS));
696+
697+
// Maximum rail power is reduced by apparent throttle factor and the number of engines running (power ratio)
698+
float maxPowerW = LocomotiveMaxRailOutputPowerW * DieselEngineFractionPower * LocomotiveApparentThrottleSetting;
699+
700+
if (DieselPowerSupply.MaximumPowerW > 0)
701+
maxPowerW = Math.Min(maxPowerW, DieselPowerSupply.MaximumPowerW * LocomotiveApparentThrottleSetting);
702+
703+
// If unloading speed is in ENG file, and locomotive speed is greater then unloading speed, and less then max speed, then apply a decay factor to the power/force
704+
if (UnloadingSpeedMpS != 0 && AbsTractionSpeedMpS > UnloadingSpeedMpS && AbsTractionSpeedMpS < MaxSpeedMpS && !WheelSlip)
705+
{
706+
// use straight line curve to decay power to zero by 2 x unloading speed
707+
float unloadingspeeddecay = 1.0f - (1.0f / UnloadingSpeedMpS) * (AbsTractionSpeedMpS - UnloadingSpeedMpS);
708+
unloadingspeeddecay = MathHelper.Clamp(unloadingspeeddecay, 0.0f, 1.0f); // Clamp decay within bounds
709+
maxPowerW *= unloadingspeeddecay;
710+
}
709711
if (maxForceN * AbsSpeedMpS > maxPowerW)
710712
maxForceN = maxPowerW / AbsTractionSpeedMpS;
711713

@@ -725,6 +727,12 @@ protected override void UpdateTractiveForce(float elapsedClockSeconds, float t,
725727
{
726728
// Tractive force is read from Table using the apparent throttle setting, and then reduced by the number of engines running (power ratio)
727729
TractiveForceN = TractiveForceCurves.Get(LocomotiveApparentThrottleSetting, AbsTractionSpeedMpS) * DieselEngineFractionPower * (1 - PowerReduction);
730+
if (DieselPowerSupply.MaximumPowerW > 0)
731+
{
732+
float maxPowerW = DieselPowerSupply.MaximumPowerW * t;
733+
if (TractiveForceN * AbsTractionSpeedMpS > maxPowerW)
734+
TractiveForceN = maxPowerW / AbsTractionSpeedMpS;
735+
}
728736
}
729737

730738
if (TractiveForceN < 0 && !TractiveForceCurves.AcceptsNegativeValues())

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,9 +2513,9 @@ protected virtual void UpdateTractiveForce(float elapsedClockSeconds, float t, f
25132513
{
25142514
float maxForceN = MaxForceN * t * (1 - PowerReduction);
25152515
float maxPowerW = MaxPowerW;
2516-
if (this is MSTSElectricLocomotive electric && electric.ElectricPowerSupply.MaximumPowerW > 0)
2517-
maxPowerW = electric.ElectricPowerSupply.MaximumPowerW;
25182516
maxPowerW *= t * t * (1 - PowerReduction);
2517+
if (this is MSTSElectricLocomotive electric && electric.ElectricPowerSupply.MaximumPowerW > 0)
2518+
maxPowerW = Math.Min(maxPowerW, electric.ElectricPowerSupply.MaximumPowerW * t);
25192519

25202520
if (maxForceN * AbsTractionSpeedMpS > maxPowerW)
25212521
maxForceN = maxPowerW / AbsTractionSpeedMpS;
@@ -2532,7 +2532,7 @@ protected virtual void UpdateTractiveForce(float elapsedClockSeconds, float t, f
25322532
TractiveForceN = TractiveForceCurves.Get(t, AbsTractionSpeedMpS) * (1 - PowerReduction);
25332533
if (this is MSTSElectricLocomotive electric && electric.ElectricPowerSupply.MaximumPowerW > 0)
25342534
{
2535-
float maxPowerW = electric.ElectricPowerSupply.MaximumPowerW * t * (1 - PowerReduction);
2535+
float maxPowerW = electric.ElectricPowerSupply.MaximumPowerW * t;
25362536
if (TractiveForceN * AbsTractionSpeedMpS > maxPowerW)
25372537
TractiveForceN = maxPowerW / AbsTractionSpeedMpS;
25382538
}

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/ElectricPowerSupply.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public class ScriptedElectricPowerSupply : ScriptedLocomotivePowerSupply
4242
public float PantographVoltageVDC { get; set; }
4343
public float FilterVoltageV { get; set; } = 0;
4444

45-
public float MaximumPowerW;
46-
4745
public ScriptedElectricPowerSupply(MSTSLocomotive locomotive) :
4846
base(locomotive)
4947
{

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/LocomotivePowerSupply.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public abstract class ScriptedLocomotivePowerSupply : ILocomotivePowerSupply
4646

4747
public PowerSupplyState MainPowerSupplyState { get; set; } = PowerSupplyState.PowerOff;
4848
public bool MainPowerSupplyOn => MainPowerSupplyState == PowerSupplyState.PowerOn;
49+
public float MaximumPowerW;
4950
public bool DynamicBrakeAvailable { get; set; } = false;
5051
public float PowerSupplyDynamicBrakePercent { get; set; } = -1;
5152
public float MaximumDynamicBrakePowerW { get; set; } = 0;

0 commit comments

Comments
 (0)