Skip to content

Commit 62c89c1

Browse files
committed
Log derailment, using TraceWarning.
Initial version, using distance travelled. May be updated to use milepost.
1 parent 273f2ef commit 62c89c1

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

+18-3
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;
@@ -1733,8 +1734,18 @@ public void UpdateTrainDerailmentRisk(float elapsedClockSeconds)
17331734
{
17341735
DerailExpected = true;
17351736
Simulator.Confirmer.Message(ConfirmLevel.Warning, Simulator.Catalog.GetStringFmt("Car {0} has derailed on the curve.", CarID));
1736-
// 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);
1737-
// 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);
1737+
if (!HasDerailed)
1738+
{
1739+
string derailReason = "defect";
1740+
if (CouplerForceU > 0 && CouplerSlackM < 0) { derailReason = "jackknifed"; }
1741+
else if (CouplerForceU < 0 && CouplerSlackM > 0) { derailReason = "stringlined"; }
1742+
Trace.TraceInformation("Car {0} derailed ({1}), on {2} curve with radius {3}, at speed {4}, after traveling {5}",
1743+
CarID, derailReason, GetCurveDirection(), FormatStrings.FormatDistance(CurrentCurveRadiusM, IsMetric), FormatStrings.FormatSpeed(AbsSpeedMpS, IsMetric), FormatStrings.FormatDistance(DistanceM, IsMetric));
1744+
// 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.
1745+
}
1746+
HasDerailed = true;
1747+
// 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);
1748+
// 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);
17381749
}
17391750
else if (DerailPossible)
17401751
{
@@ -1744,12 +1755,15 @@ public void UpdateTrainDerailmentRisk(float elapsedClockSeconds)
17441755
else
17451756
{
17461757
DerailElapsedTimeS = 0; // Reset timer if derail is not possible
1758+
HasDerailed = false;
17471759
}
17481760

17491761
if (AbsSpeedMpS < 0.01)
17501762
{
17511763
DerailExpected = false;
17521764
DerailPossible = false;
1765+
DerailElapsedTimeS = 0;
1766+
HasDerailed = false;
17531767
}
17541768

17551769
// if (CarID == "0 - 84" || CarID == "0 - 83" || CarID == "0 - 82" || CarID == "0 - 81" || CarID == "0 - 80" || CarID == "0 - 79")
@@ -1766,6 +1780,7 @@ public void UpdateTrainDerailmentRisk(float elapsedClockSeconds)
17661780
DerailExpected = false;
17671781
DerailPossible = false;
17681782
DerailElapsedTimeS = 0;
1783+
HasDerailed = false;
17691784
}
17701785

17711786

0 commit comments

Comments
 (0)