Skip to content

Commit bae7132

Browse files
committed
1 parent 1daa6a7 commit bae7132

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

Source/Documentation/Manual/cruisecontrol.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ A list of the available .eng file CC parameters follows here below.
138138
"ModeSwitchAllowedWithThrottleNotAtZero", "Switch from manual to auto and vice-versa can occur also when throttle lever is not at 0", "Boolean", "FALSE"
139139
"DisableManualSwitchToAutoWhenSetSpeedNotAtTop", "Manual Switch to Cruise Control Auto Mode can't occur when speed is not set at maximum value and at the same moment train speed is not 0", "Boolean", "FALSE"
140140
"UseTrainBrakeAndDynBrake", "CC uses train brake and dyn brake together", "Boolean", "FALSE"
141+
"UseDynBrake", "CC uses dyn brake", "Boolean", "TRUE"
142+
"TrainBrakeCommandHasPriorityOverCruiseControl", "A manual train braking inhibits Cruise Control to use both dynamic braking and tractive force", "Boolean", "TRUE"
143+
"TrainBrakeCommandHasPriorityOverAcceleratingCruiseControl", "A manual train braking inhibits Cruise Control to use tractive force", "Boolean", "TRUE"
141144
"SpeedDeltaToEnableTrainBrake", "This is the minimum speed delta between actual speed and desired speed for the CC to use also the train brake", "Float(speed)", "5m/s"
142145
"SpeedDeltaToEnableFullTrainBrake", "This is the minimum speed delta between actual speed and desired speed for the CC to use also the train brake with no reduced intensity", "Float(speed)", "10m/s"
143146
"TrainBrakeMinPercentValue", "This is the minimum train brake percent used by the CC. 0 means no braking, 100 means full service braking", "Float(percent)", "30"

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4260,7 +4260,7 @@ public void StartTrainBrakeIncrease(float? target)
42604260
AlerterReset(TCSEvent.TrainBrakeChanged);
42614261
TrainBrakeController.StartIncrease(target);
42624262
TrainBrakeController.CommandStartTime = Simulator.ClockTime;
4263-
if (CruiseControl != null && CruiseControl.TrainBrakeCommandHasPriorityOverCruiseControl)
4263+
if (CruiseControl != null && (CruiseControl.TrainBrakeCommandHasPriorityOverCruiseControl || CruiseControl.TrainBrakeCommandHasPriorityOverAcceleratingCruiseControl))
42644264
{
42654265
CruiseControl.TrainBrakePriority = true;
42664266
}
@@ -4349,7 +4349,8 @@ public void SetTrainBrakeValue(float value)
43494349
if (change != 0)
43504350
{
43514351
new TrainBrakeCommand(Simulator.Log, change > 0, controller.CurrentValue, Simulator.ClockTime);
4352-
if (change > 0 && CruiseControl != null && CruiseControl.TrainBrakeCommandHasPriorityOverCruiseControl) CruiseControl.TrainBrakePriority = true;
4352+
if (change > 0 && CruiseControl != null && ( CruiseControl.TrainBrakeCommandHasPriorityOverCruiseControl || CruiseControl.TrainBrakeCommandHasPriorityOverAcceleratingCruiseControl))
4353+
CruiseControl.TrainBrakePriority = true;
43534354
SignalEvent(Event.TrainBrakeChange);
43544355
AlerterReset(TCSEvent.TrainBrakeChanged);
43554356
}

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public enum SpeedSelectorMode { Parking, Neutral, On, Start }
138138
public bool ZeroSelectedSpeedWhenPassingToThrottleMode = false;
139139
public bool DynamicBrakeCommandHasPriorityOverCruiseControl = true;
140140
public bool TrainBrakeCommandHasPriorityOverCruiseControl = true;
141+
public bool TrainBrakeCommandHasPriorityOverAcceleratingCruiseControl = true;
141142
public bool HasIndependentThrottleDynamicBrakeLever = false;
142143
public bool HasProportionalSpeedSelector = false;
143144
public bool SpeedSelectorIsDiscrete = false;
@@ -146,6 +147,7 @@ public enum SpeedSelectorMode { Parking, Neutral, On, Start }
146147
public bool EnableSelectedSpeedSelectionWhenManualModeSet = false;
147148
public bool ModeSwitchAllowedWithThrottleNotAtZero = false;
148149
public bool UseTrainBrakeAndDynBrake = false;
150+
public bool UseDynBrake = true;
149151
protected float SpeedDeltaToEnableTrainBrake = 5;
150152
protected float SpeedDeltaToEnableFullTrainBrake = 10;
151153
public float MinimumSpeedForCCEffectMpS = 0;
@@ -167,6 +169,7 @@ public enum SpeedSelectorMode { Parking, Neutral, On, Start }
167169
protected bool reducingForce = false;
168170
protected float skidSpeedDegratation = 0;
169171
public bool TrainBrakePriority = false;
172+
public bool TrainBrakePriorityIfCCAccelerating = false;
170173
public bool WasBraking = false;
171174
public bool WasForceReset = true;
172175

@@ -250,13 +253,15 @@ public CruiseControl(CruiseControl other, MSTSLocomotive locomotive)
250253
ZeroSelectedSpeedWhenPassingToThrottleMode = other.ZeroSelectedSpeedWhenPassingToThrottleMode;
251254
DynamicBrakeCommandHasPriorityOverCruiseControl = other.DynamicBrakeCommandHasPriorityOverCruiseControl;
252255
TrainBrakeCommandHasPriorityOverCruiseControl = other.TrainBrakeCommandHasPriorityOverCruiseControl;
256+
TrainBrakeCommandHasPriorityOverAcceleratingCruiseControl = other.TrainBrakeCommandHasPriorityOverAcceleratingCruiseControl;
253257
HasIndependentThrottleDynamicBrakeLever = other.HasIndependentThrottleDynamicBrakeLever;
254258
HasProportionalSpeedSelector = other.HasProportionalSpeedSelector;
255259
DisableManualSwitchToAutoWhenSetSpeedNotAtTop = other.DisableManualSwitchToAutoWhenSetSpeedNotAtTop;
256260
EnableSelectedSpeedSelectionWhenManualModeSet = other.EnableSelectedSpeedSelectionWhenManualModeSet;
257261
SpeedSelectorIsDiscrete = other.SpeedSelectorIsDiscrete;
258262
DoComputeNumberOfAxles = other.DoComputeNumberOfAxles;
259263
UseTrainBrakeAndDynBrake = other.UseTrainBrakeAndDynBrake;
264+
UseDynBrake = other.UseDynBrake;
260265
SpeedDeltaToEnableTrainBrake = other.SpeedDeltaToEnableTrainBrake;
261266
SpeedDeltaToEnableFullTrainBrake = other.SpeedDeltaToEnableFullTrainBrake;
262267
MinimumSpeedForCCEffectMpS = other.MinimumSpeedForCCEffectMpS;
@@ -345,10 +350,12 @@ public void Parse(STFReader stf)
345350
case "zeroselectedspeedwhenpassingtothrottlemode": ZeroSelectedSpeedWhenPassingToThrottleMode = stf.ReadBoolBlock(false); break;
346351
case "dynamicbrakecommandhaspriorityovercruisecontrol": DynamicBrakeCommandHasPriorityOverCruiseControl = stf.ReadBoolBlock(true); break;
347352
case "trainbrakecommandhaspriorityovercruisecontrol": TrainBrakeCommandHasPriorityOverCruiseControl = stf.ReadBoolBlock(true); break;
353+
case "trainbrakecommandhaspriorityoveracceleratingcruisecontrol": TrainBrakeCommandHasPriorityOverAcceleratingCruiseControl = stf.ReadBoolBlock(true); break;
348354
case "hasindependentthrottledynamicbrakelever": HasIndependentThrottleDynamicBrakeLever = stf.ReadBoolBlock(false); break;
349355
case "hasproportionalspeedselector": HasProportionalSpeedSelector = stf.ReadBoolBlock(false); break;
350356
case "speedselectorisdiscrete": SpeedSelectorIsDiscrete = stf.ReadBoolBlock(false); break;
351357
case "usetrainbrakeanddynbrake": UseTrainBrakeAndDynBrake = stf.ReadBoolBlock(false); break;
358+
case "usedynbrake": UseDynBrake = stf.ReadBoolBlock(false); break;
352359
case "speeddeltatoenabletrainbrake": SpeedDeltaToEnableTrainBrake = stf.ReadFloatBlock(STFReader.UNITS.Speed, 5f); break;
353360
case "speeddeltatoenablefulltrainbrake": SpeedDeltaToEnableFullTrainBrake = stf.ReadFloatBlock(STFReader.UNITS.Speed, 10f); break;
354361
case "minimumspeedforcceffect": MinimumSpeedForCCEffectMpS = stf.ReadFloatBlock(STFReader.UNITS.Speed, 0f); break;
@@ -506,15 +513,16 @@ public void Update(float elapsedClockSeconds)
506513
trainBrakePercent = 0;
507514
}
508515
else if ((Locomotive.TrainBrakeController.MaxPressurePSI - Locomotive.BrakeSystem.BrakeLine1PressurePSI > 1 ||
509-
Locomotive.Train.BrakeLine4 > 0) && TrainBrakePriority && !CCIsUsingTrainBrake)
516+
Locomotive.Train.BrakeLine4 > 0) && TrainBrakePriority && !CCIsUsingTrainBrake && (!(TrainBrakeCommandHasPriorityOverAcceleratingCruiseControl && CCThrottleOrDynBrakePercent <= 0) || TrainBrakeCommandHasPriorityOverCruiseControl))
510517
{
511518
reducingForce = true;
512519
timeFromEngineMoved = 0;
513520
if (CCThrottleOrDynBrakePercent > 0)
514521
CCThrottleOrDynBrakePercent = 0;
515522
}
516-
else if (TrainBrakePriority || DynamicBrakePriority || (ThrottleNeutralPosition && SelectedSpeedMpS == 0) || SelectedMaxAccelerationPercent == 0 ||
517-
(ForceResetRequiredAfterBraking &&
523+
else if (TrainBrakePriority && (TrainBrakeCommandHasPriorityOverCruiseControl || TrainBrakeCommandHasPriorityOverAcceleratingCruiseControl && CCThrottleOrDynBrakePercent > 0)
524+
|| DynamicBrakePriority || (ThrottleNeutralPosition && SelectedSpeedMpS == 0) || SelectedMaxAccelerationPercent == 0 ||
525+
(ForceResetRequiredAfterBraking && (!(TrainBrakeCommandHasPriorityOverAcceleratingCruiseControl && CCThrottleOrDynBrakePercent <= 0) || TrainBrakeCommandHasPriorityOverCruiseControl) &&
518526
(!WasForceReset || (WasBraking && SelectedMaxAccelerationPercent > 0))))
519527
{
520528
if (SpeedSelMode == SpeedSelectorMode.Parking)
@@ -528,6 +536,10 @@ public void Update(float elapsedClockSeconds)
528536
float prevTrainBrakePercent = trainBrakePercent;
529537
CalculateRequiredForce(elapsedClockSeconds, Locomotive.AbsWheelSpeedMpS);
530538
CCThrottleOrDynBrakePercent = MathHelper.Clamp(CCThrottleOrDynBrakePercent, -100, 100);
539+
if (CCThrottleOrDynBrakePercent > 0 && ForceResetRequiredAfterBraking && (!WasForceReset || WasBraking && SelectedMaxAccelerationPercent > 0))
540+
{
541+
CCThrottleOrDynBrakePercent = 0;
542+
}
531543
if (CCThrottleOrDynBrakePercent >= 0)
532544
{
533545
Locomotive.ThrottlePercent = CCThrottleOrDynBrakePercent;
@@ -1194,7 +1206,7 @@ public void CalculateRequiredForce(float elapsedClockSeconds, float AbsWheelSpee
11941206
else
11951207
{
11961208
deltaSpeedMpS = SetSpeedMpS + (trainElevation < -0.01 ? trainElevation * (SelectedNumberOfAxles / 12) : 0) - AbsWheelSpeedMpS;
1197-
if (Locomotive.DynamicBrakeAvailable)
1209+
if (Locomotive.DynamicBrakeAvailable && UseDynBrake)
11981210
{
11991211
AccelerationDemandMpSS = (float)-Math.Sqrt(-StartReducingSpeedDeltaDownwards * deltaSpeedMpS);
12001212

@@ -1240,7 +1252,7 @@ public void CalculateRequiredForce(float elapsedClockSeconds, float AbsWheelSpee
12401252
}
12411253
else
12421254
{
1243-
if (Locomotive.DynamicBrakeAvailable)
1255+
if (Locomotive.DynamicBrakeAvailable && UseDynBrake)
12441256
{
12451257
float val = (float)Math.Abs(StartReducingSpeedDeltaDownwards * coeff * ((deltaSpeedMpS + 0.5f) / 3));
12461258
AccelerationDemandMpSS = -(float)Math.Sqrt(val);

0 commit comments

Comments
 (0)