Skip to content

Commit 27e5ffb

Browse files
authored
Merge pull request #945 from cesarBLG/locomotive-power-information
Display tractive force instead of compensated out force
2 parents 502cbbe + f5872fd commit 27e5ffb

File tree

7 files changed

+45
-46
lines changed

7 files changed

+45
-46
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ public string GetDPDebugStatus()
10741074
status.AppendFormat("{0} {1}\t", GetStringAttribute.GetPrettyName(Direction), Flipped ? Simulator.Catalog.GetString("(flipped)") : "");
10751075
status.AppendFormat("{0}\t", IsLeadLocomotive() || RemoteControlGroup < 0 ? "———" : RemoteControlGroup == 0 ? Simulator.Catalog.GetString("Sync") : Simulator.Catalog.GetString("Async"));
10761076
status.AppendFormat("{0}\t", FormatStrings.FormatFuelVolume(DieselLevelL, IsMetric, IsUK));
1077-
status.AppendFormat("{0}{1}", FormatStrings.FormatForce(MotiveForceN, IsMetric), CouplerOverloaded ? "???" : "");
1077+
status.AppendFormat("{0}{1}", FormatStrings.FormatForce(TractiveForceN, IsMetric), CouplerOverloaded ? "???" : "");
10781078
status.Append(DieselEngines.GetDPStatus());
10791079

10801080
return status.ToString();
@@ -1120,8 +1120,8 @@ public string GetDpuStatus(bool dataDpu, CABViewControlUnits loadUnits = CABView
11201120

11211121
// Load
11221122
var data = 0f;
1123-
if (FilteredMotiveForceN != 0)
1124-
data = Math.Abs(this.FilteredMotiveForceN);
1123+
if (FilteredTractiveForceN != 0)
1124+
data = Math.Abs(this.FilteredTractiveForceN);
11251125
else
11261126
data = Math.Abs(TractiveForceN);
11271127
if (DynamicBrakePercent > 0)

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ public enum TractionMotorTypes
494494
public float SaveAdhesionFilter;
495495
public float AdhesionConditions;
496496

497-
public float FilteredMotiveForceN;
497+
public float FilteredTractiveForceN;
498498

499499
public double CommandStartTime;
500500

@@ -2170,7 +2170,7 @@ public override void Update(float elapsedClockSeconds)
21702170
AntiSlip = true; // Always set AI trains to AntiSlip
21712171
SimpleAdhesion(); // Simple adhesion model used for AI trains
21722172
AdvancedAdhesionModel = false;
2173-
if (Train.IsActualPlayerTrain) FilteredMotiveForceN = CurrentFilter.Filter(MotiveForceN, elapsedClockSeconds);
2173+
if (Train.IsActualPlayerTrain) FilteredTractiveForceN = CurrentFilter.Filter(TractiveForceN, elapsedClockSeconds);
21742174
WheelSpeedMpS = Flipped ? -AbsSpeedMpS : AbsSpeedMpS; //make the wheels go round
21752175
break;
21762176
case Train.TRAINTYPE.STATIC:
@@ -2228,7 +2228,7 @@ public override void Update(float elapsedClockSeconds)
22282228
}
22292229

22302230
//Force to display
2231-
FilteredMotiveForceN = CurrentFilter.Filter(MotiveForceN, elapsedClockSeconds);
2231+
FilteredTractiveForceN = CurrentFilter.Filter(TractiveForceN, elapsedClockSeconds);
22322232
break;
22332233
default:
22342234
break;
@@ -2263,7 +2263,7 @@ public override void Update(float elapsedClockSeconds)
22632263
UpdateHornAndBell(elapsedClockSeconds);
22642264

22652265
UpdateSoundVariables(elapsedClockSeconds);
2266-
PrevMotiveForceN = MotiveForceN;
2266+
PrevTractiveForceN = TractiveForceN;
22672267
base.Update(elapsedClockSeconds);
22682268

22692269
#if DEBUG_ADHESION
@@ -5243,10 +5243,10 @@ public virtual float GetDataOf(CabViewControl cvc)
52435243
{
52445244
//float rangeFactor = direction == 0 ? (float)cvc.MaxValue : (float)cvc.MinValue;
52455245
float rangeFactor = direction == 0 ? MaxCurrentA : (float)cvc.MinValue;
5246-
if (FilteredMotiveForceN != 0)
5247-
data = this.FilteredMotiveForceN / MaxForceN * rangeFactor;
5246+
if (FilteredTractiveForceN != 0)
5247+
data = FilteredTractiveForceN / MaxForceN * rangeFactor;
52485248
else
5249-
data = this.LocomotiveAxles[cvc.ControlId].DriveForceN / MaxForceN * rangeFactor;
5249+
data = TractiveForceN / MaxForceN * rangeFactor;
52505250
data = Math.Abs(data);
52515251
}
52525252
if (DynamicBrakePercent > 0 && MaxDynamicBrakeForceN > 0)
@@ -5273,7 +5273,7 @@ public virtual float GetDataOf(CabViewControl cvc)
52735273
if (cvc.ControlType.Type == CABViewControlTypes.AMMETER_ABS) data = Math.Abs(data);
52745274
break;
52755275
}
5276-
data = this.MotiveForceN / MaxForceN * MaxCurrentA;
5276+
data = TractiveForceN / MaxForceN * MaxCurrentA;
52775277
if (cvc.ControlType.Type == CABViewControlTypes.AMMETER_ABS) data = Math.Abs(data);
52785278
break;
52795279
}
@@ -5289,10 +5289,10 @@ public virtual float GetDataOf(CabViewControl cvc)
52895289
data = 0.0f;
52905290
if (ThrottlePercent > 0)
52915291
{
5292-
if (FilteredMotiveForceN != 0)
5293-
data = this.FilteredMotiveForceN / MaxForceN * MaxCurrentA;
5292+
if (FilteredTractiveForceN != 0)
5293+
data = FilteredTractiveForceN / MaxForceN * MaxCurrentA;
52945294
else
5295-
data = this.LocomotiveAxles[cvc.ControlId].DriveForceN / MaxForceN * MaxCurrentA;
5295+
data = TractiveForceN / MaxForceN * MaxCurrentA;
52965296
data = Math.Abs(data);
52975297
}
52985298
if (DynamicBrake && DynamicBrakePercent > 0 && MaxDynamicBrakeForceN > 0)
@@ -5310,10 +5310,10 @@ public virtual float GetDataOf(CabViewControl cvc)
53105310
if (cvc is CVCGauge && ((CVCGauge)cvc).Orientation == 0)
53115311
direction = ((CVCGauge)cvc).Direction;
53125312
data = 0.0f;
5313-
if (FilteredMotiveForceN != 0)
5314-
data = this.FilteredMotiveForceN;
5313+
if (FilteredTractiveForceN != 0)
5314+
data = FilteredTractiveForceN;
53155315
else
5316-
data = this.LocomotiveAxles[cvc.ControlId].DriveForceN;
5316+
data = TractiveForceN;
53175317
if (DynamicBrake && DynamicBrakePercent > 0)
53185318
{
53195319
data = DynamicBrakeForceN;
@@ -5358,10 +5358,10 @@ public virtual float GetDataOf(CabViewControl cvc)
53585358
if (cvc is CVCGauge && ((CVCGauge)cvc).Orientation == 0)
53595359
direction = ((CVCGauge)cvc).Direction;
53605360
data = 0.0f;
5361-
if (FilteredMotiveForceN != 0)
5362-
data = Math.Abs(this.FilteredMotiveForceN);
5361+
if (FilteredTractiveForceN != 0)
5362+
data = Math.Abs(FilteredTractiveForceN);
53635363
else
5364-
data = Math.Abs(this.LocomotiveAxles[cvc.ControlId].DriveForceN);
5364+
data = Math.Abs(TractiveForceN);
53655365
if (DynamicBrake && DynamicBrakePercent > 0)
53665366
{
53675367
data = -Math.Abs(DynamicBrakeForceN);
@@ -5407,9 +5407,9 @@ public virtual float GetDataOf(CabViewControl cvc)
54075407
data = 0.0f;
54085408
if (Math.Abs(SpeedMpS) == 0.0f)
54095409
data = 0.0f;
5410-
else if (Math.Abs(FilteredMotiveForceN) - Math.Abs(BrakeForceN + DynamicBrakeForceN) > 0)
5411-
data = Math.Abs(this.FilteredMotiveForceN);
5412-
else if (Math.Abs(FilteredMotiveForceN) - Math.Abs(BrakeForceN + DynamicBrakeForceN) < 0)
5410+
else if (Math.Abs(FilteredTractiveForceN) - Math.Abs(BrakeForceN + DynamicBrakeForceN) > 0)
5411+
data = Math.Abs(FilteredTractiveForceN);
5412+
else if (Math.Abs(FilteredTractiveForceN) - Math.Abs(BrakeForceN + DynamicBrakeForceN) < 0)
54135413
data = -Math.Abs(BrakeForceN + DynamicBrakeForceN);
54145414
switch (cvc.Units)
54155415
{

Source/Orts.Simulation/Simulation/RollingStocks/MSTSSteamLocomotive.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6284,10 +6284,7 @@ protected override void UpdateTractiveForce(float elapsedClockSeconds, float loc
62846284
{
62856285
absStartTractiveEffortN = Math.Abs(TractiveForceN); // update to new maximum TE
62866286
}
6287-
}
6288-
6289-
MotiveForceSmoothN.Update(elapsedClockSeconds, MotiveForceN);
6290-
MotiveForceSmoothedN = MotiveForceSmoothN.SmoothedValue;
6287+
}
62916288
if (float.IsNaN(MotiveForceN))
62926289
MotiveForceN = 0;
62936290

Source/Orts.Simulation/Simulation/RollingStocks/MSTSWagon.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,9 @@ public enum WindowState
172172
public float Curtius_KnifflerC = 0.161f; // speedMpS * 3.6 + B
173173
public float AdhesionK = 0.7f; //slip characteristics slope
174174
public float AxleInertiaKgm2; //axle inertia
175-
public float WheelSpeedMpS;
176175
public float WheelSpeedSlipMpS; // speed of wheel if locomotive is slipping
177176
public float SlipWarningThresholdPercent = 70;
178177
public MSTSNotchController WeightLoadController; // Used to control freight loading in freight cars
179-
public float AbsWheelSpeedMpS; // Math.Abs(WheelSpeedMpS) is used frequently in the subclasses, maybe it's more efficient to compute it once
180178

181179
public Axles LocomotiveAxles; // Only used at locomotives for efficiency
182180

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/CruiseControl.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,11 +1465,11 @@ public float GetDataOf(CabViewControl cvc)
14651465
}
14661466
break;
14671467
case CABViewControlTypes.ORTS_MOTIVE_FORCE:
1468-
data = Locomotive.FilteredMotiveForceN;
1468+
data = Locomotive.FilteredTractiveForceN;
14691469
break;
14701470
case CABViewControlTypes.ORTS_MOTIVE_FORCE_KILONEWTON:
1471-
if (Locomotive.FilteredMotiveForceN > Locomotive.DynamicBrakeForceN)
1472-
data = (float)Math.Round(Locomotive.FilteredMotiveForceN / 1000, 0);
1471+
if (Locomotive.FilteredTractiveForceN > Locomotive.DynamicBrakeForceN)
1472+
data = (float)Math.Round(Locomotive.FilteredTractiveForceN / 1000, 0);
14731473
else if (Locomotive.DynamicBrakeForceN > 0)
14741474
data = -(float)Math.Round(Locomotive.DynamicBrakeForceN / 1000, 0);
14751475
break;

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,13 +1038,10 @@ public void Update(float elapsedClockSeconds)
10381038

10391039
DemandedThrottlePercent = Math.Max(DemandedThrottlePercent, ReverseThrottleRPMTab[Locomotive.DieselPowerSupply.DieselEngineMinRpm]);
10401040

1041-
if (Locomotive.Direction == Direction.Reverse)
1042-
Locomotive.PrevMotiveForceN *= -1f;
1043-
10441041
if ((State == DieselEngineState.Running) && (Locomotive.ThrottlePercent > 0))
10451042
{
1046-
var abstempMotiveForce = Math.Abs(Locomotive.PrevMotiveForceN);
1047-
OutputPowerW = ( abstempMotiveForce > 0 ? abstempMotiveForce * Locomotive.AbsSpeedMpS : 0) / Locomotive.DieselEngines.NumOfActiveEngines;
1043+
var abstempTractiveForce = Math.Abs(Locomotive.PrevTractiveForceN);
1044+
OutputPowerW = ( abstempTractiveForce > 0 ? abstempTractiveForce * Locomotive.AbsWheelSpeedMpS : 0) / Locomotive.DieselEngines.NumOfActiveEngines;
10481045
}
10491046
else
10501047
{

Source/Orts.Simulation/Simulation/RollingStocks/TrainCar.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ public float ConvectionFactor
299299
public float _SpeedMpS; // meters per second; updated by train physics, relative to direction of car 50mph = 22MpS
300300
public float _PrevSpeedMpS;
301301
public float AbsSpeedMpS; // Math.Abs(SpeedMps) expression is repeated many times in the subclasses, maybe this deserves a class variable
302+
public float WheelSpeedMpS;
303+
public float AbsWheelSpeedMpS; // Math.Abs(WheelSpeedMpS) is used frequently in the subclasses, maybe it's more efficient to compute it once
302304
public float CouplerSlackM; // extra distance between cars (calculated based on relative speeds)
303305
public int HUDCouplerForceIndication = 0; // Flag to indicate whether coupler is 1 - pulling, 2 - pushing or 0 - neither
304306
public float CouplerSlack2M; // slack calculated using draft gear force
@@ -548,11 +550,16 @@ public Direction Direction
548550
public float PreviousSteamBrakeCylinderPressurePSI;
549551

550552
// TrainCar.Update() must set these variables
551-
public float MotiveForceN; // ie motor power in Newtons - signed relative to direction of car -
552-
public float TractiveForceN = 0f; // Raw tractive force for electric sound variable2
553-
public SmoothedData MotiveForceSmoothN = new SmoothedData(0.5f);
554-
public float MotiveForceSmoothedN;
555-
public float PrevMotiveForceN;
553+
/// <summary>
554+
/// Force transmitted to rail, excluding brake force
555+
/// Adhesion-corrected tractive force
556+
/// </summary>
557+
public float MotiveForceN;
558+
/// <summary>
559+
/// Tractive force generated by the engine(s)
560+
/// </summary>
561+
public float TractiveForceN = 0f;
562+
public float PrevTractiveForceN;
556563
// Gravity forces have negative values on rising grade.
557564
// This means they have the same sense as the motive forces and will push the train downhill.
558565
public float GravityForceN; // Newtons - signed relative to direction of car.
@@ -2198,8 +2205,8 @@ public virtual string GetDebugStatus()
21982205
String.Format("{0}", FormatStrings.FormatSpeedDisplay(SpeedMpS, IsMetric)),
21992206
loco.DieselEngines[0].GearBox.HuDShaftRPM,
22002207
// For Locomotive HUD display shows "forward" motive power (& force) as a positive value, braking power (& force) will be shown as negative values.
2201-
FormatStrings.FormatPower((MotiveForceN) * SpeedMpS, IsMetric, false, false),
2202-
String.Format("{0}{1}", FormatStrings.FormatForce(MotiveForceN, IsMetric), WheelSlip ? "!!!" : WheelSlipWarning ? "???" : ""),
2208+
FormatStrings.FormatPower(TractiveForceN * WheelSpeedMpS, IsMetric, false, false),
2209+
String.Format("{0}{1}", FormatStrings.FormatForce(TractiveForceN, IsMetric), WheelSlip ? "!!!" : WheelSlipWarning ? "???" : ""),
22032210
Simulator.Catalog.GetString(locomotivetypetext)
22042211
);
22052212
}
@@ -2213,8 +2220,8 @@ public virtual string GetDebugStatus()
22132220
ThrottlePercent,
22142221
String.Format("{0}", FormatStrings.FormatSpeedDisplay(SpeedMpS, IsMetric)),
22152222
// For Locomotive HUD display shows "forward" motive power (& force) as a positive value, braking power (& force) will be shown as negative values.
2216-
FormatStrings.FormatPower((MotiveForceN) * SpeedMpS, IsMetric, false, false),
2217-
String.Format("{0}{1}", FormatStrings.FormatForce(MotiveForceN, IsMetric), WheelSlip ? "!!!" : WheelSlipWarning ? "???" : ""),
2223+
FormatStrings.FormatPower(TractiveForceN * WheelSpeedMpS, IsMetric, false, false),
2224+
String.Format("{0}{1}", FormatStrings.FormatForce(TractiveForceN, IsMetric), WheelSlip ? "!!!" : WheelSlipWarning ? "???" : ""),
22182225
Simulator.Catalog.GetString(locomotivetypetext)
22192226
);
22202227
}

0 commit comments

Comments
 (0)