Skip to content

Commit 808af64

Browse files
committed
Automatic merge of T1.6-rc6-37-g6dd094783 and 17 pull requests
- Pull request #1086 at e10390b: Add Settings Exporter tool (copy settings to INI, etc) - Pull request #1091 at 2e06f85: Automatic speed control - Pull request #1104 at 86d38a2: Handle simple adhesion within the axle module - Pull request #1115 at 270f22f: Do not activate ETS switch if no suitable cars are attached - Pull request #1120 at ba3c47f: Automatically Calculate Friction Values if Missing - Pull request #1121 at 91d2d26: Manually Override Articulation - Pull request #1130 at 8ae6bb7: Fix F9 points to an incorrect car ID. - Pull request #1139 at 03c6f8f: Fix for bug https://bugs.launchpad.net/or/+bug/2117357. - Pull request #1142 at a24747c: Fix Light Position Calculation for Deeper Hierarchy Levels - Pull request #1143 at 71e57d2: Status in Work Orders popup set too fast - Pull request #1144 at cd790b9: update Spanish translations - Pull request #1145 at 875b084: Content Manager: Fix exception when searching; path was added twice to search list. - Pull request #1146 at ec44b47: Fix for pantograph events not sent in AI trains - Pull request #1082 at 5845a1a: Allow variable water level in glass gauge - Pull request #1081 at 689494b: Brake cuts power unification - Pull request #1124 at fab5457: Built-in PBL2 brake controller - Pull request #1128 at 58de4c3: Particle Emitter Overhaul
19 parents 08834b4 + 6dd0947 + e10390b + 2e06f85 + 86d38a2 + 270f22f + ba3c47f + 91d2d26 + 8ae6bb7 + 03c6f8f + a24747c + 71e57d2 + cd790b9 + 875b084 + ec44b47 + 5845a1a + 689494b + fab5457 + 58de4c3 commit 808af64

File tree

14 files changed

+995
-1082
lines changed

14 files changed

+995
-1082
lines changed

Source/Documentation/Manual/cruisecontrol.rst

Lines changed: 79 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@ A paragraph is devoted to each of the above topics.
3333
Operation Modes
3434
===============
3535

36-
The CC Speed Regulator can be in 4 different states (or modes), that is:
36+
The CC Speed Regulator can be in two different states (or modes), that is:
3737

3838
1) *Manual*, when the automatic cruise control is disabled and the driver
3939
controls the speed through throttle and brakes as if there were no CC.
4040
2) *Auto*, when the automatic cruise control is enabled, and therefore
4141
the speed is automatically controlled
42-
3) *Testing*, not implemented at the moment
43-
4) *AVV*, not implemented at the moment.
4442

4543
Switching between Manual and Auto mode can be configured to occur either
4644
by a specific cabview control (*ORTS_SELECTED_SPEED_REGULATOR_MODE*) or
@@ -94,10 +92,16 @@ A list of the available .eng file CC parameters follows here below.
9492
"SpeedIsMpH", "KpH if missing", "Boolean", "FALSE"
9593
"MaxForceSteps", "Usually will be 100 meaning 100%, but some locos have limited force steps", "Integer", "0"
9694
"SpeedSelectorStepTimeSeconds", "How fast the selected speed lever adds speed", "Float", "0.1"
97-
"DynamicBrakeMaxForceAtSelectorStep", "The brake will reach 100% at this step, the lower the step, the lower the max brake percent", "Integer", "1"
9895
"NominalSpeedStep", "When pressing Shift+A or Shift+D how many speed units should the selected speed change ", "Integer", "0"
96+
"SpeedSelectorDelayTimeBeforeUpdating", "Time that the speed selector has to be kept unchanged before updating the set speed", "Seconds", "0"
9997
"StartReducingSpeedDelta", "The lower number, the sooner the regulator will decrease power", "Float", "1"
10098
"StartReducingSpeedDeltaDownwards", "If present and different from zero, overrides the above parameter for dynamic braking", "Float", "0"
99+
"SpeedDeltaToStartAccelerating", "Difference between train speed and set speed before applying throttle", "Float (speed)", "0"
100+
"SpeedDeltaToStartBraking", "Difference between train speed and set speed before applying brakes", "Float (speed)", "0.5 m/s"
101+
"SpeedDeltaToStopAccelerating", "Difference between train speed and set speed below which throttle is closed", "Float (speed)", "0"
102+
"SpeedDeltaToStopBraking", "Difference between train speed and set speed below which brakes are released", "Float (speed)", "0.5 m/s"
103+
"SpeedDeltaAcceleratingOffset", "Speed delta at which the demanded acceleration is 0", "Float (speed)", "0"
104+
"SpeedDeltaBrakingOffset", "Speed delta at which the demanded deceleration is 0", "Float (speed)", "0"
101105
"ForceRegulatorAutoWhenNonZeroSpeedSelected", "When a non zero speed is selected, the regulator is set to auto", "Boolean", "FALSE"
102106
"ForceRegulatorAutoWhenNonZeroSpeedSelectedAndThrottleAtZero", "Self explaining", "Boolean", "FALSE"
103107
"MaxForceKeepSelectedStepWhenManualModeSet", "Self explaining", "Boolean", "FALSE"
@@ -107,43 +111,43 @@ A list of the available .eng file CC parameters follows here below.
107111
"ThrottleFullRangeDecreaseTimeSeconds", "Time in seconds needed for the regulator to pass from 100 to 0% of power", "Seconds", "5"
108112
"DynamicBrakeFullRangeIncreaseTimeSeconds", "Same as above, but for dynamic braking", "Seconds", "5"
109113
"DynamicBrakeFullRangeDecreaseTimeSeconds", "Same as above, but for dynamic braking", "Seconds", "5"
110-
"TrainBrakeFullRangeIncreaseTimeSeconds", "Same as above, but for train brakes", "Seconds", "10"
111-
"TrainBrakeFullRangeDecreaseTimeSeconds", "Same as above, but for train brakes", "Seconds", "5"
114+
"TrainBrakeFullRangeIncreaseTimeSeconds", "Same as above, but for train brakes", "Seconds", "6"
115+
"TrainBrakeFullRangeDecreaseTimeSeconds", "Same as above, but for train brakes", "Seconds", "6"
116+
"SpeedDeltaFunctionMode", "Algorithm used to convert speed delta to required acceleration. Recommended to use Linear mode, Sqrt mode is deprecated", "String", "Sqrt"
117+
"ThrottlePID", "Proportional, Integral and Derivative coefficients used to convert demanded acceleration to throttle percent. Changing it is not recommended", "Floats", ""
118+
"DynamicBrakePID", "Proportional, Integral and Derivative coefficients used to convert demanded deceleration to dynamic brake percent. Changing it is not recommended", "Floats", ""
119+
"TrainBrakePID", "Proportional, Integral and Derivative coefficients used to convert demanded deceleration to train brake percent. Changing it is not recommended", "Floats", ""
112120
"DefaultForceStep", "When OR is started, this will be the selected force step, usually set at 0", "Integer", "1"
113121
"DisableCruiseControlOnThrottleAndZeroSpeed", "If train is stationary and throttle is increased and CC is still in auto, this will revert the mode to manual", "Boolean", "FALSE"
114122
"DisableCruiseControlOnThrottleAndZeroForce", "If train is moving and throttle is increased and CC is still in auto and selected force is zero, this will revert the mode to manual", "Boolean", "FALSE"
115123
"DynamicBrakeCommandHasPriorityOverCruiseControl", "When cruise control is in Auto, manually activating the dynamic brake has priority", "Boolean", "TRUE"
116124
"HasIndependentThrottleDynamicBrakeLever", "The cabview is equipped with a combined Throttle-Dynamic brake lever independent from the CC controls", "Boolean", "FALSE"
117125
"DoComputeNumberOfAxles", "Number of train axles automatically computed at game start", "Boolean", "FALSE"
118-
"AntiWheelSpinEquipped", "Self explaining. Note: if there are multiple locos in the consist, the loco with most speed diff takes the decision to activate", "Boolean", "FALSE"
119-
"AntiWheelSpinSpeedDiffThreshold", "The speed difference (MpS) between wheel speed and train speed that activates the anti spin system and reduces power", "Boolean", "FALSE"
120126
"ParkingBrakeEngageSpeed", "The speed when automatic parking brake will be engaged if present", "Float (speed)", "0"
121127
"ParkingBrakePercent", "To what engine brake percent should the parking brake be set if engaged", "Float", "0"
122128
"MaxPowerThreshold", "At this speed, no matter what max force was selected by the driver, the regulator will lineary reach force to 100%", "Float (speed)", "0"
123129
"SafeSpeedForAutomaticOperationMpS", "Some locos/systems need the 'confirm to drive' button to be held until the safe speed is reached. This is the speed above which the loco will continue delivering power.", "Float (speed)", "0"
124130
"ContinuousSpeedIncreasing", " ", "Logical", "FALSE"
125-
"PowerBreakoutAmpers", "Some locos are unable to maintain power when current is lower than this value. In that case, a breakout is generated and the power goes to 0", "Float(Amperes)", "100"
126-
"PowerBreakoutSpeedDelta", "Obsolete", "Float", "100"
127-
"PowerResumeSpeedDelta", "When breakout was activated, this is the speed hysteresis, when speed is reduced by this value the engine will resume power", "Float", "100"
128131
"PowerReductionDelayPaxTrain", "Time required for the loco to reach maximum percent of power set in PowerReductionValue until the whole train is in pull on its couplers for passenger trains", "Float (seconds)", "0"
129132
"PowerReductionDelayCargoTrain", "Time required for the loco to reach maximum percent of power set in PowerReductionValue until the whole train is in pull on its couplers for freight trains", "Float (seconds)", "0"
130133
"PowerReductionValue", "Maximum power in % to maintain until PowerReductionDelay is reached", "Float", "100"
131134
"DisableZeroForceStep", "Minimum force step is limited above zero", "Boolean", "FALSE"
135+
"DisableZeroSelectedSpeedStep", "The minimum speed that can be selected is greater than 0", "Boolean", "FALSE"
132136
"UseThrottleAsSpeedSelector", "if ControllerCruiseControlLogic is set to SpeedOnly, throttle when in Auto mode will change the maximum CC speed", "Boolean", "FALSE"
133137
"UseThrottleAsForceSelector", "if ControllerCruiseControlLogic is set to None, throttle when in Auto mode will change the maximum CC Force", "Boolean", "FALSE"
134-
"UseThrottleInCombinedControl", "Throttle is used as force selector or speed selector even if in combined control, to be used in conjunction of one of the two above parameters", "Boolean", "FALSE"
135138
"ControllerCruiseControlLogic", "Can have values 'None', 'SpeedOnly', 'Full'", "Enum", "Full"
136139
"HasProportionalSpeedSelector", "Speed selector is performed by a lever ranging from 0 to max speed", "Boolean", "FALSE"
137-
"SpeedSelectorIsDiscrete", "Speed selected can have only values multiple of NominalSpeedStep, even if selection is through mouse", "Boolean", "FALSE"
140+
"SpeedSelectorIsDiscrete", "Speed selected can have only values multiple of NominalSpeedStep", "Boolean", "TRUE"
138141
"ModeSwitchAllowedWithThrottleNotAtZero", "Switch from manual to auto and vice-versa can occur also when throttle lever is not at 0", "Boolean", "FALSE"
139142
"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"
140143
"UseTrainBrakeAndDynBrake", "CC uses train brake and dyn brake together", "Boolean", "FALSE"
141144
"UseDynBrake", "CC uses dyn brake", "Boolean", "TRUE"
142145
"TrainBrakeCommandHasPriorityOverCruiseControl", "A manual train braking inhibits Cruise Control to use both dynamic braking and tractive force", "Boolean", "TRUE"
143146
"TrainBrakeCommandHasPriorityOverAcceleratingCruiseControl", "A manual train braking inhibits Cruise Control to use tractive force", "Boolean", "TRUE"
147+
"BrakeCommandHasPriorityOverASCBraking", "A manual train brake command inhibits the Automatic Speed Control braking, even if the latter is more restrictive", "Boolean", "FALSE"
148+
"ASCSpeedTakesPriorityOverSpeedSelector", "Set speed demanded by the Automatic Speed Control system overrides the speed selected by the driver, even if the latter is lower", "Boolean", "FALSE"
144149
"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"
145-
"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"
146-
"TrainBrakeMinPercentValue", "This is the minimum train brake percent used by the CC. 0 means no braking, 100 means full service braking", "Float(percent)", "30"
150+
"TrainBrakeMinPercentValue", "This is the minimum train brake percent used by the CC. 0 means no braking, 100 means full service braking", "Float(percent)", "10"
147151
"TrainBrakeMaxPercentValue", "As above for maximum value. It must not be too high to avoid that the brake is not fully released timely", "Float(percent)", "85"
148152
"ThrottleNeutralPosition", "The zero throttle position is neutral in auto mode, that is in such position the CC does not intervene", "Boolean", "FALSE"
149153
"MinimumSpeedForCCEffect", "Below this speed CC has no effect", "Float(speed)", "0"
@@ -162,6 +166,7 @@ found in the table here below.
162166
"RegulatorManual",
163167
"RegulatorTest",
164168
"EngageForceOnNonZeroSpeed",
169+
"EngageParkingOnZeroSpeed",
165170
"StartFromZero", "No need to confirm you want to drive. If speed is set above zero, the train starts to move"
166171
"SelectorNeutral",
167172
"SelectorOn",
@@ -180,27 +185,42 @@ block within the .eng file.
180185

181186
Train brake usage occurs when the delta between the actual train speed and
182187
the target speed is higher than parameter SpeedDeltaToEnableTrainBrake.
183-
Between this delta and SpeedDeltaToEnableFullTrainBrake the train brake is
184-
set at TrainBrakeMinPercentValue. Above SpeedDeltaToEnableFullTrainBrake
185-
the train brake is continuously adjusted to achieve a constant deceleration.
186-
In other words, when the speed delta is high, train braking is adjusted to
187-
obtain a constant deceleration when dynamic braking is not enough; when train decelerates
188-
and delta reduces to SpeedDeltaToEnableFullTrainBrake the train brake is reduced to
189-
TrainBrakeMinPercentValue. When train decelerates further and delta reduces to
190-
SpeedDeltaToEnableTrainBrake the train brake is released. By adjusting these
191-
parameters to the locomotive and a typical train it pulls, it can be made sure that
192-
the brake pipe is fully recharged when the target speed is reached. Else the
193-
train speed could be significantly reduced below the target speed.
194-
195-
An example of the relevant lines in the CruiseControl
196-
block within the .eng file follows here::
197-
198-
UseTrainBrakeAndDynBrake ( True ) comment (** CC uses train brake and dyn brake together **)
199-
SpeedDeltaToEnableTrainBrake ( 15km/h ) comment (** This is the minimum speed delta between actual speed and desired speed for the CC to use also the train brake **)
200-
SpeedDeltaToEnableFullTrainBrake ( 30km/h ) comment (** 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 **)
188+
Above this value, the train brake is continuously adjusted to achieve
189+
the target deceleration. If available, dynamic brake takes priority. Only when
190+
the requested dynamic brake percent exceeds MinDynamicBrakePercentToEnableTrainBrake,
191+
the train brake is activated to supplement dynamic brakes.
192+
193+
UseTrainBrakeAndDynBrake ( True ) comment (** CC uses train brake and dyn brake together **)
194+
SpeedDeltaToEnableTrainBrake ( 5km/h ) comment (** This is the minimum speed delta between actual speed and desired speed for the CC to use also the train brake **)
201195
TrainBrakeMinPercentValue ( 10 ) comment (** This is the minimum train brake percent used by the CC, where 0 means no braking and 100 full braking **)
202196
TrainBrakeMaxPercentValue ( 60 ) comment (** As above for maximum value. It must not be too high to avoid that the brake is not fully released timely **)
203197
198+
Speed and force selectors
199+
-------------------------
200+
Speed and force selectors with custom notches can be defined in the ``EngineControllers`` block of the ENG file,
201+
using ``orts_speed_selector`` and ``orts_force_selector`` controller names. The range should be between 0 and 1,
202+
where 0 means zero force/speed and 1 means maximum force/speed.
203+
204+
Example::
205+
206+
Engine (
207+
EngineControllers (
208+
ORTS_Speed_Selector ( 0 1 0.1 0
209+
NumNotches ( 0 )
210+
ORTSDelayTimeBeforeUpdating ( 0.5s )
211+
)
212+
ORTS_Force_Selector ( 0 1 0.1 0
213+
NumNotches ( 4
214+
Notch ( 0 0 )
215+
Notch ( 0.25 0 )
216+
Notch ( 0.5 0 )
217+
Notch ( 1 0 )
218+
)
219+
)
220+
)
221+
)
222+
223+
204224
Multi Position Controller (MPC)
205225
-------------------------------
206226

@@ -279,6 +299,32 @@ MPC is connected. Controllers linked may be either "Throttle" or
279299
The boolean parameter *CanControlTrainBrake*, which is false by
280300
default, is optional.
281301

302+
Automatic Speed Control
303+
=======================
304+
Cab signaling systems can be integrated with speed control systems to automatically
305+
respect speed restrictions and stop at signals and station stops. The
306+
:ref:`Train Control System scripts <features-scripting-tcs>` can request a setpoint
307+
speed for the cruise control system, eliminating the need for the driver to manually
308+
adjust the train speed. The interface consists of two variables available from
309+
the TCS script:
310+
311+
.. code-block:: csharp
312+
313+
float? SetSpeedMpS
314+
315+
This variable, if not null, instructs the cruise control system to adjust
316+
the train speed in order to reach the requested setpoint.
317+
318+
.. code-block:: csharp
319+
320+
float SetSpeedAccelerationMpS
321+
322+
This variable controls the requested acceleration when the train is at the set speed.
323+
When the set speed is constant because the TCS is supervising a ceiling speed,
324+
the requested acceleration should be 0. However, during a braking curve,
325+
as the set speed is decreasing, the requested acceleration should be negative,
326+
matching the deceleration of the braking curve.
327+
282328
.. _cruisecontrol-cabviewcontrolstable:
283329

284330
Cruise Control Cabview Controls
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// COPYRIGHT 2025 by the Open Rails project.
2+
//
3+
// This file is part of Open Rails.
4+
//
5+
// Open Rails is free software: you can redistribute it and/or modify
6+
// it under the terms of the GNU General Public License as published by
7+
// the Free Software Foundation, either version 3 of the License, or
8+
// (at your option) any later version.
9+
//
10+
// Open Rails is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
// GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License
16+
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.
17+
18+
using System;
19+
20+
namespace ORTS.Common
21+
{
22+
/// <summary>
23+
/// Modified PID controller that converts requested force/acceleration to throttle or brake percent
24+
/// </summary>
25+
public class AccelerationController
26+
{
27+
public float Percent { get; private set; }
28+
public float PPercent { get; private set; }
29+
public float IPercent { get; private set; }
30+
public float DPercent { get; private set; }
31+
private float TotalError;
32+
private float LastTarget;
33+
private float LastError;
34+
private bool active;
35+
private readonly float[] Coefficients;
36+
private float ProportionalFactor;
37+
private float IntegralFactor;
38+
private float DerivativeFactor;
39+
public float Tolerance;
40+
public bool Active
41+
{
42+
set
43+
{
44+
if (active != value)
45+
{
46+
LastTarget = 0;
47+
LastError = 0;
48+
TotalError = 0;
49+
Percent = 0;
50+
active = value;
51+
}
52+
}
53+
get
54+
{
55+
return active;
56+
}
57+
}
58+
public AccelerationController(float p, float i, float d = 0)
59+
{
60+
Coefficients = new float[] { 100 * p, 100 * i, 100 * d };
61+
}
62+
protected AccelerationController(AccelerationController o)
63+
{
64+
Coefficients = o.Coefficients;
65+
}
66+
public AccelerationController Clone()
67+
{
68+
return new AccelerationController(this);
69+
}
70+
/// <summary>
71+
/// Adjust PID coefficients according to the maximum force/acceleration
72+
/// </summary>
73+
/// <param name="maxAccelerationMpSS">Maximum force or acceleration developed with controller at 100%</param>
74+
public void Adjust(float maxAccelerationMpSS)
75+
{
76+
ProportionalFactor = Coefficients[0] / maxAccelerationMpSS;
77+
IntegralFactor = Coefficients[1] / maxAccelerationMpSS;
78+
DerivativeFactor = Coefficients[2] / maxAccelerationMpSS;
79+
}
80+
public void Update(float elapsedClockSeconds, float targetAccelerationMpSS, float currentAccelerationMpSS, float minPercent = 0, float maxPercent = 100)
81+
{
82+
if (!Active) Active = true;
83+
float error = targetAccelerationMpSS - currentAccelerationMpSS;
84+
TotalError += (error + LastError) * elapsedClockSeconds / 2;
85+
PPercent = ProportionalFactor * targetAccelerationMpSS;
86+
IPercent = IntegralFactor * TotalError;
87+
DPercent = elapsedClockSeconds > 0 && DerivativeFactor > 0 ? DerivativeFactor * (error - LastError) / elapsedClockSeconds : 0;
88+
Percent = PPercent + IPercent + DPercent;
89+
if (Percent <= minPercent)
90+
{
91+
if (PPercent > minPercent && IntegralFactor > 0) TotalError = (minPercent - PPercent) / IntegralFactor;
92+
else if (TotalError < 0) TotalError = 0;
93+
Percent = minPercent;
94+
}
95+
if (Percent >= maxPercent)
96+
{
97+
if (PPercent < maxPercent && IntegralFactor > 0) TotalError = (maxPercent - PPercent) / IntegralFactor;
98+
else if (TotalError > 0) TotalError = 0;
99+
Percent = maxPercent;
100+
}
101+
LastTarget = targetAccelerationMpSS;
102+
LastError = error;
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)