Skip to content

Commit 4484282

Browse files
committed
Indicate if CC braking is active or not for non self-lapping controllers
1 parent 2391bc0 commit 4484282

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

Source/Orts.Simulation/Common/Scripting/BrakeController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public float IntermediateValue
187187
public List<MSTSNotch> Notches() => Host.Notches;
188188

189189
/// <summary>
190-
/// Fraction of train brake demanded by cruise control
190+
/// Fraction of train brake demanded by cruise control. Returns -1 if CC is inactive
191191
/// </summary>
192192
public float CruiseControlBrakeDemand() => Host.CruiseControlBrakeDemand;
193193

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Controllers/BrakeController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ public float CruiseControlBrakeDemand
156156
{
157157
get
158158
{
159-
if (Locomotive.CruiseControl == null) return 0;
160-
if (this == Locomotive.EngineBrakeController) return Locomotive.CruiseControl.EngineBrakePercent / 100;
161-
else return Locomotive.CruiseControl.TrainBrakePercent / 100;
159+
if (Locomotive.CruiseControl == null) return -1;
160+
if (this == Locomotive.EngineBrakeController) return Locomotive.CruiseControl.EngineBrakePercent / 100 ?? -1;
161+
else return Locomotive.CruiseControl.TrainBrakePercent / 100 ?? -1;
162162
}
163163
}
164164
InterpolatorDiesel2D DynamicBrakeBlendingTable;

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ public float SetSpeedKpHOrMpH
117117
public float MaxDecelerationMpSS = 2;
118118
public float? ThrottlePercent { get; private set;}
119119
public float? DynamicBrakePercent { get; private set;}
120-
public float TrainBrakePercent { get; private set; }
121-
public float EngineBrakePercent { get; private set; }
120+
public float? TrainBrakePercent { get; private set; }
121+
public float? EngineBrakePercent { get; private set; }
122122
protected float trainLength = 0;
123123
public int TrainLengthMeters = 0;
124124
OdoMeter RestrictedRegionOdometer;
@@ -588,8 +588,8 @@ public void Update(float elapsedClockSeconds)
588588
CCThrottleOrDynBrakePercent = 0;
589589
ThrottlePercent = null;
590590
DynamicBrakePercent = null;
591-
TrainBrakePercent = 0;
592-
EngineBrakePercent = 0;
591+
TrainBrakePercent = null;
592+
EngineBrakePercent = null;
593593
return;
594594
}
595595
if (firstIteration) // if this is executed the first time, let's check all other than player engines in the consist, and record them for further throttle manipulation
@@ -643,8 +643,8 @@ public void Update(float elapsedClockSeconds)
643643
CCThrottleOrDynBrakePercent = 0;
644644
ThrottlePercent = null;
645645
DynamicBrakePercent = null;
646-
TrainBrakePercent = 0;
647-
EngineBrakePercent = 0;
646+
TrainBrakePercent = null;
647+
EngineBrakePercent = null;
648648
}
649649
else if (SpeedRegMode == SpeedRegulatorMode.Auto)
650650
{
@@ -755,14 +755,14 @@ public void Update(float elapsedClockSeconds)
755755
if (CCThrottleOrDynBrakePercent > 0 && !tractionAllowed) CCThrottleOrDynBrakePercent = 0;
756756
if (AbsWheelSpeedMpS == 0 && CCThrottleOrDynBrakePercent < 0) CCThrottleOrDynBrakePercent = 0;
757757
CCThrottleOrDynBrakePercent = MathHelper.Clamp(CCThrottleOrDynBrakePercent, -100, 100);
758-
TrainBrakePercent = MathHelper.Clamp(TrainBrakePercent, 0, 100);
758+
TrainBrakePercent = MathHelper.Clamp(TrainBrakePercent.Value, 0, 100);
759759

760760
if (TrainBrakePercent > 0) CCIsUsingTrainBrake = true;
761761
}
762762
else
763763
{
764764
CCThrottleOrDynBrakePercent = 0;
765-
TrainBrakePercent = 0;
765+
TrainBrakePercent = null;
766766
ThrottlePID.Active = false;
767767
DynamicBrakePID.Active = false;
768768
TrainBrakePID.Active = false;
@@ -772,7 +772,8 @@ public void Update(float elapsedClockSeconds)
772772
if (DynamicBrakePriority) DynamicBrakePercent = null;
773773
else if (CCThrottleOrDynBrakePercent < 0) DynamicBrakePercent = -CCThrottleOrDynBrakePercent;
774774
else DynamicBrakePercent = -1;
775-
if (SpeedSelMode == SpeedSelectorMode.Parking && !EngineBrakePriority)
775+
if (EngineBrakePriority) EngineBrakePercent = null;
776+
else if (SpeedSelMode == SpeedSelectorMode.Parking)
776777
{
777778
if (Locomotive.AbsWheelSpeedMpS <= ParkingBrakeEngageSpeedMpS)
778779
EngineBrakePercent = ParkingBrakePercent;
@@ -1380,14 +1381,16 @@ void UpdateTrainBrakePercent(float elapsedClockSeconds, float demandedAccelerati
13801381

13811382
float target = TrainBrakePID.Percent;
13821383

1384+
if (TrainBrakePercent == null) TrainBrakePercent = 0;
1385+
13831386
if (target > TrainBrakePercent && target >= TrainBrakeMinPercentValue)
13841387
{
13851388
if (TrainBrakePercent < TrainBrakeMinPercentValue) TrainBrakePercent = TrainBrakeMinPercentValue;
1386-
TrainBrakePercent = Math.Min(target, TrainBrakePercent + 100 / TrainBrakeFullRangeIncreaseTimeSeconds * elapsedClockSeconds);
1389+
TrainBrakePercent = Math.Min(target, TrainBrakePercent.Value + 100 / TrainBrakeFullRangeIncreaseTimeSeconds * elapsedClockSeconds);
13871390
}
13881391
else if (target < TrainBrakePercent)
13891392
{
1390-
TrainBrakePercent = Math.Max(target, TrainBrakePercent - 100 / TrainBrakeFullRangeDecreaseTimeSeconds * elapsedClockSeconds);
1393+
TrainBrakePercent = Math.Max(target, TrainBrakePercent.Value - 100 / TrainBrakeFullRangeDecreaseTimeSeconds * elapsedClockSeconds);
13911394
if (TrainBrakePercent <= TrainBrakeMinPercentValue)
13921395
{
13931396
if (target == 0) TrainBrakePercent = 0;

0 commit comments

Comments
 (0)