Skip to content

Commit a4b51ce

Browse files
authored
Merge pull request #1066 from rwf-rr/log-derailment-and-more
Log derailment, using TraceInformation.
2 parents 77a649f + 62c89c1 commit a4b51ce

File tree

1 file changed

+18
-3
lines changed
  • Source/Orts.Simulation/Simulation/RollingStocks

1 file changed

+18
-3
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// COPYRIGHT 2009 - 2022 by the Open Rails project.
1+
// COPYRIGHT 2009 - 2022 by the Open Rails project.
22
//
33
// This file is part of Open Rails.
44
//
@@ -208,6 +208,7 @@ public static Interpolator SteamHeatBoilerFuelUsageGalukpH()
208208
public bool DerailPossible = false;
209209
public bool DerailExpected = false;
210210
public float DerailElapsedTimeS;
211+
public bool HasDerailed = false;
211212

212213
public float MaxHandbrakeForceN;
213214
public float MaxBrakeForceN = 89e3f;
@@ -1735,8 +1736,18 @@ public void UpdateTrainDerailmentRisk(float elapsedClockSeconds)
17351736
{
17361737
DerailExpected = true;
17371738
Simulator.Confirmer.Message(ConfirmLevel.Warning, Simulator.Catalog.GetStringFmt("Car {0} has derailed on the curve.", CarID));
1738-
// Trace.TraceInformation("Car Derail - CarID: {0}, Coupler: {1}, CouplerSmoothed {2}, Lateral {3}, Vertical {4}, Angle {5} Nadal {6} Coeff {7}", CarID, CouplerForceU, CouplerForceUSmoothed.SmoothedValue, TotalWagonLateralDerailForceN, TotalWagonVerticalDerailForceN, WagonCouplerAngleDerailRad, NadalDerailmentCoefficient, DerailmentCoefficient);
1739-
// Trace.TraceInformation("Car Ahead Derail - CarID: {0}, Coupler: {1}, CouplerSmoothed {2}, Lateral {3}, Vertical {4}, Angle {5}", CarAhead.CarID, CarAhead.CouplerForceU, CarAhead.CouplerForceUSmoothed.SmoothedValue, CarAhead.TotalWagonLateralDerailForceN, CarAhead.TotalWagonVerticalDerailForceN, CarAhead.WagonCouplerAngleDerailRad);
1739+
if (!HasDerailed)
1740+
{
1741+
string derailReason = "defect";
1742+
if (CouplerForceU > 0 && CouplerSlackM < 0) { derailReason = "jackknifed"; }
1743+
else if (CouplerForceU < 0 && CouplerSlackM > 0) { derailReason = "stringlined"; }
1744+
Trace.TraceInformation("Car {0} derailed ({1}), on {2} curve with radius {3}, at speed {4}, after traveling {5}",
1745+
CarID, derailReason, GetCurveDirection(), FormatStrings.FormatDistance(CurrentCurveRadiusM, IsMetric), FormatStrings.FormatSpeed(AbsSpeedMpS, IsMetric), FormatStrings.FormatDistance(DistanceM, IsMetric));
1746+
// DistanceM is not a good location measure, as it is based on the train. Two railcars derailing at the same location have a different distance.
1747+
}
1748+
HasDerailed = true;
1749+
// Trace.TraceInformation("Car Derail - CarID: {0}, Coupler: {1}, CouplerSmoothed {2}, Lateral {3}, Vertical {4}, Angle {5} Nadal {6} Coeff {7}", CarID, CouplerForceU, CouplerForceUSmoothed.SmoothedValue, TotalWagonLateralDerailForceN, TotalWagonVerticalDerailForceN, WagonCouplerAngleDerailRad, NadalDerailmentCoefficient, DerailmentCoefficient);
1750+
// Trace.TraceInformation("Car Ahead Derail - CarID: {0}, Coupler: {1}, CouplerSmoothed {2}, Lateral {3}, Vertical {4}, Angle {5}", CarAhead.CarID, CarAhead.CouplerForceU, CarAhead.CouplerForceUSmoothed.SmoothedValue, CarAhead.TotalWagonLateralDerailForceN, CarAhead.TotalWagonVerticalDerailForceN, CarAhead.WagonCouplerAngleDerailRad);
17401751
}
17411752
else if (DerailPossible)
17421753
{
@@ -1746,12 +1757,15 @@ public void UpdateTrainDerailmentRisk(float elapsedClockSeconds)
17461757
else
17471758
{
17481759
DerailElapsedTimeS = 0; // Reset timer if derail is not possible
1760+
HasDerailed = false;
17491761
}
17501762

17511763
if (AbsSpeedMpS < 0.01)
17521764
{
17531765
DerailExpected = false;
17541766
DerailPossible = false;
1767+
DerailElapsedTimeS = 0;
1768+
HasDerailed = false;
17551769
}
17561770

17571771
// if (CarID == "0 - 84" || CarID == "0 - 83" || CarID == "0 - 82" || CarID == "0 - 81" || CarID == "0 - 80" || CarID == "0 - 79")
@@ -1768,6 +1782,7 @@ public void UpdateTrainDerailmentRisk(float elapsedClockSeconds)
17681782
DerailExpected = false;
17691783
DerailPossible = false;
17701784
DerailElapsedTimeS = 0;
1785+
HasDerailed = false;
17711786
}
17721787

17731788

0 commit comments

Comments
 (0)