Skip to content

Commit 0488826

Browse files
committed
Do not move brake lever when applying brakes
1 parent 6e2f0ba commit 0488826

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ public abstract class BrakeController : AbstractTrainScriptClass
120120
/// Gives the list of notches
121121
/// </summary>
122122
public Func<List<MSTSNotch>> Notches;
123+
/// <summary>
124+
/// Fraction of train brake demanded by cruise control
125+
/// </summary>
126+
public Func<float> CruiseControlBrakeDemand;
123127

124128
/// <summary>
125129
/// Sets the current value of the brake controller lever

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4134,7 +4134,7 @@ public void StartTrainBrakeIncrease(float? target)
41344134
AlerterReset(TCSEvent.TrainBrakeChanged);
41354135
TrainBrakeController.StartIncrease(target);
41364136
TrainBrakeController.CommandStartTime = Simulator.ClockTime;
4137-
if (CruiseControl != null)
4137+
if (CruiseControl != null && CruiseControl.TrainBrakeCommandHasPriorityOverCruiseControl)
41384138
{
41394139
CruiseControl.TrainBrakePriority = true;
41404140
}
@@ -4223,7 +4223,7 @@ public void SetTrainBrakeValue(float value)
42234223
if (change != 0)
42244224
{
42254225
new TrainBrakeCommand(Simulator.Log, change > 0, controller.CurrentValue, Simulator.ClockTime);
4226-
if (change > 0 && CruiseControl != null) CruiseControl.TrainBrakePriority = true;
4226+
if (change > 0 && CruiseControl != null && CruiseControl.TrainBrakeCommandHasPriorityOverCruiseControl) CruiseControl.TrainBrakePriority = true;
42274227
SignalEvent(Event.TrainBrakeChange);
42284228
AlerterReset(TCSEvent.TrainBrakeChanged);
42294229
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ public void Initialize()
389389
Script.StepSize = () => StepSize;
390390
Script.UpdateValue = () => UpdateValue;
391391
Script.Notches = () => Notches;
392+
Script.CruiseControlBrakeDemand = () => Locomotive.CruiseControl != null ? Locomotive.CruiseControl.TrainBrakePercent/100 : 0;
392393

393394
Script.SetCurrentValue = (value) => CurrentValue = value;
394395
Script.SetUpdateValue = (value) => UpdateValue = value;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,16 @@ public override void UpdatePressure(ref float pressureBar, float elapsedClockSec
225225
}
226226
}
227227

228+
float ccdemand = CruiseControlBrakeDemand();
229+
if (ccdemand > 0)
230+
{
231+
pressureBar = Math.Min(MaxPressureBar() - MinReductionBar() * (1 - ccdemand) - FullServReductionBar() * ccdemand, pressureBar);
232+
epState = ccdemand;
233+
}
234+
228235
if (pressureBar < 0)
229236
pressureBar = 0;
237+
230238
epControllerState = epState;
231239
}
232240

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ public float SetSpeedMpS
8080
public bool AntiWheelSpinEquipped = false;
8181
public float AntiWheelSpinSpeedDiffThreshold = 0.5f;
8282
public float DynamicBrakeMaxForceAtSelectorStep = 0;
83-
protected float trainBrakePercent = 0;
83+
float trainBrakePercent;
84+
public float TrainBrakePercent { get { return trainBrakePercent; }}
8485
protected float trainLength = 0;
8586
public int TrainLengthMeters = 0;
8687
public float CurrentSelectedSpeedMpS = 0;
@@ -131,6 +132,7 @@ public enum SpeedSelectorMode { Parking, Neutral, On, Start }
131132
public bool ForceResetIncludeDynamicBrake = false;
132133
public bool ZeroSelectedSpeedWhenPassingToThrottleMode = false;
133134
public bool DynamicBrakeCommandHasPriorityOverCruiseControl = true;
135+
public bool TrainBrakeCommandHasPriorityOverCruiseControl = true;
134136
public bool HasIndependentThrottleDynamicBrakeLever = false;
135137
public bool HasProportionalSpeedSelector = false;
136138
public bool SpeedSelectorIsDiscrete = false;
@@ -248,6 +250,7 @@ public CruiseControl(CruiseControl other, MSTSLocomotive locomotive)
248250
ForceResetIncludeDynamicBrake = other.ForceResetIncludeDynamicBrake;
249251
ZeroSelectedSpeedWhenPassingToThrottleMode = other.ZeroSelectedSpeedWhenPassingToThrottleMode;
250252
DynamicBrakeCommandHasPriorityOverCruiseControl = other.DynamicBrakeCommandHasPriorityOverCruiseControl;
253+
TrainBrakeCommandHasPriorityOverCruiseControl = other.TrainBrakeCommandHasPriorityOverCruiseControl;
251254
HasIndependentThrottleDynamicBrakeLever = other.HasIndependentThrottleDynamicBrakeLever;
252255
HasProportionalSpeedSelector = other.HasProportionalSpeedSelector;
253256
DisableManualSwitchToManualWhenSetForceNotAtZero = other.DisableManualSwitchToManualWhenSetForceNotAtZero;
@@ -347,6 +350,7 @@ public void Parse(STFReader stf)
347350
case "forceresetincludedynamicbrake": ForceResetIncludeDynamicBrake = stf.ReadBoolBlock(false); break;
348351
case "zeroselectedspeedwhenpassingtothrottlemode": ZeroSelectedSpeedWhenPassingToThrottleMode = stf.ReadBoolBlock(false); break;
349352
case "dynamicbrakecommandhaspriorityovercruisecontrol": DynamicBrakeCommandHasPriorityOverCruiseControl = stf.ReadBoolBlock(true); break;
353+
case "trainbrakecommandhaspriorityovercruisecontrol": TrainBrakeCommandHasPriorityOverCruiseControl = stf.ReadBoolBlock(true); break;
350354
case "hasindependentthrottledynamicbrakelever": HasIndependentThrottleDynamicBrakeLever = stf.ReadBoolBlock(false); break;
351355
case "hasproportionalspeedselector": HasProportionalSpeedSelector = stf.ReadBoolBlock(false); break;
352356
case "speedselectorisdiscrete": SpeedSelectorIsDiscrete = stf.ReadBoolBlock(false); break;
@@ -540,10 +544,6 @@ public void Update(float elapsedClockSeconds)
540544
Locomotive.ThrottlePercent = 0;
541545
Locomotive.DynamicBrakePercent = -CCThrottleOrDynBrakePercent;
542546
}
543-
if (prevTrainBrakePercent != trainBrakePercent && !TrainBrakePriority)
544-
{
545-
Locomotive.TrainBrakeController.SetPercent(trainBrakePercent); // TODO: do not move actual train brake lever
546-
}
547547
IsActive = true;
548548
}
549549
if (!IsActive && wasActive)

0 commit comments

Comments
 (0)