Since #187 the braking curve towards a stop or a lower speed leaves room for
the time the brake takes to respond, as long as the train brake handle is
still in the running position. The horizon it takes has the AI's old
look-ahead, (1 - a0) * 30/3.6 s, about 7-8 s, as its floor; at 60 km/h that
is over 100 m, up to half of the braking distance. Stops at signals were
tuned with it. A vehicle that brakes with its independent brake (an SN61, a
light engine) leaves the train brake handle where it is, so it kept that
room the whole way in: it braked early and gently, came down to 10 km/h
some 50 m out and crawled the rest, applying power and the brake in turn.
Making for a passenger stop (the point the train is to stop at, found by the
scan of the route, is a W4), the room now covers only the time the brake
takes to fill (half its application time), without the look-ahead floor.
Stops at signals and anything else keep the room as it was.
When a vehicle ahead is closer than the stop the scan found, the train makes
for that vehicle, so the room is the full one again.
- The tractive force that tells the start on the train brake is over is
projected on the direction of travel: Ft is in the vehicle's own frame, so
a locomotive driven from its rear cab, or turned the other way in the
consist, counted as nothing.
- Rolling back faster than 0.5 km/h ends the start on the train brake, so
the rules for a train slipping back apply the brakes again.
- One threshold for an up gradient that rolls a standing train back,
EU07_AI_UPHILLGRAVITY (-0.025 m/s2, about 2.5 per mille), for the stop
hold, the locomotive brake on rollback, the start, uphill_brake_committed()
and hold_train_coming_to_stand_uphill(); the stop hold and the rollback
rule started at 0.5 per mille before, on almost level track.
- hold_train_coming_to_stand_uphill() brakes on the brake's response time
only for a train that is not to pull up further.
- Starting against the brake keeps the train Ready only at a standstill; in
motion a braking force left in the train stops it as before.
Whether a train is at a passenger stop (IsAtPassengerStop) was checked against
the final approach margins fMinProximityDist and fMaxProximityDist, which are
themselves set from that flag: 10-15 m and 15-40 m at a stop, 8 m and 50 m
otherwise. With the two sets different, the flag switched on and off on every
other scan of the route on the way to a W4. Each time the train went from a
final approach to a stop 50 m long to one 15 m long and back: braking in one
scan, full power below the 10 km/h coasting speed in the next. Close to the
stop the braking demand did not hold the train to a standstill, and below
1 km/h the stop counted as done, so an SN61 drove off without ever standing
still (#290).
The margins are now worked out in train_proximity_margins(), and the check of
the stop uses the margins of a passenger stop whatever the flag is at the
moment. A vehicle that is not a train keeps the present ones, as before.
Takes care of the last two Sonar remarks, with no change in what the AI does:
- S134: the braking curve followed outside the final approach moves out of
adjust_desired_speed_for_target_speed() into
adjust_desired_speed_for_braking_curve(), with early returns.
- S6004: deltaAcc of increase_train_brake() is declared in the
init-statement of its if.
No change in what the AI or the distributor does:
- S134: the step of the train brake sized from the consist brake table
moves out of IncBrake() into increase_train_brake(), with early returns.
- S134, S1066: while starting uphill, the check of the released brakes
leaves Ready as it was by assigning the flag instead of nesting an if.
- S6004: the uphill condition of control_uphill_start(), and the target
cylinder pressure of TNESt3::CheckState(), are declared in the
init-statement of their if.
- S5350: the loop summing the tractive force walks the consist through a
pointer to const.
- S3776: the cylinder nozzle calibration for the AL2 relay moves out of
TNESt3::SetSize() into ScaleNozzlesForAL2().
No change in what the AI does; only the structure of the code that came in
with the braking changes:
- S107: shaped_braking_demand() takes the consist brake table as a struct
instead of four separate parameters; its lambdas capture explicitly.
- S3358: brake_response_horizon() picks the BrakeDelay entry without a
nested conditional operator.
- S5276: the speed passed to braking_distance_multiplier() is converted to
float explicitly, as it was implicitly before.
- S134: the stop case of the proximity range is an else-if of its own, and
its body a method of its own, adjust_desired_speed_for_final_approach(),
with early returns instead of nested ifs. The cargo train threshold
push is a conditional subtraction instead of a nested if.
- S3776: pick_optimal_speed() hands the uncoupling stages and the uphill
stand to set_velocity_for_uncoupling() and
hold_train_coming_to_stand_uphill().
Starting uphill the AI released the train brake (and the locomotive
brake with it) at once, while the power came on only later: a train on
10 per mille rolled back 20-30 m (E186 with 19 container wagons), and an
E189 with 7 Z2 coaches rolled back for minutes without power, because
the brake applied again for the rollback kept the power off. Many
locomotives cannot pull while their own cylinder is under pressure
(asynchronous drives switch to braking, others have a control pressure
switch), so holding the train on the locomotive brake is no way out.
A train standing on an up gradient with the train brake applied now
starts as a driver of a heavy train does:
- the train brake stays applied, the locomotive brake is released and
the locomotive's own share of the train brake is let off with the
releaser;
- the power is applied against the braked train (Ready does not hold
it back meanwhile, and the rule that brakes a train slipping back
is off);
- the train brake is released only once the tractive force exceeds 1.1
times the gradient force, the train moves forward, or after 45 s if
the locomotive cannot hold the train on its own power.
Multiple units are not affected.
Changes to how the AI works the train brake on the way to a lower speed
or a stop, so that it uses few, early applications instead of a late
deep one:
- Approaching a lower speed, the deceleration may fall short of the
demand by only half of a step (fBrake_a1) before the brake is applied
harder. With a full step the demand crept up meanwhile and a long G
train got its next step many seconds too late.
- The shortfall is checked every 3 s. If it keeps growing at a handle
left alone for longer than the brake takes to respond, the AI adds a
small step at once instead of waiting until the margin calls for a
deep one. A shortfall that shrinks on its own (brake still filling,
blocks gripping harder at lower speed) does not trigger it.
- Releasing, a position short of the first one counts as giving the
minimum stage of the distributor, not less.
- Holding the speed on a descent, the predicted excess speed is taken
off over the time the brake takes to respond, not at once, so a slow
brake does not get a deep application that then takes as long to
release.
Uphill a long train often came to a stand with its brake on the way
off and rolled back several metres: the AI released the train brake
to 0 about 20 m short of the stop (the gradient alone would have
stopped the train short of the stopping window), applied only the
first step again at the last moment, and a G train cannot apply its
brake again within the few seconds the gradient takes to stop it.
Coming to a stand on an up gradient (also when only part of the train
is on it) the AI now:
- applies the brake before the train stops on the gradient alone, once
the time left to the stand is no longer than half of what the brake
takes to apply;
- does not let the train coast on or pull up while the brake is applied
and the gradient would stop the train sooner than the brake of the
consist can be released;
- does not release the train brake any further below 10 km/h on the
way to a stand (unless the train is to be driven on);
- puts the locomotive brake on below 3 km/h when the train will reach
the point it is to stop at (not when it has slowed down short of it
and is to pull up), and at once if the train rolls back.
The condition added for holding the speed uphill near a stop pushed the
cognitive complexity of control_tractive_force() to 26, over the 25
SonarCloud allows. It now lives in is_too_fast_uphill(); the behaviour
is unchanged.
* fix(ai): release what the AI was holding when the player takes over
* fix(ai): keep the light selector lookup within its table, Sonar findings of the handover
- the light selector size comes from the vehicle definition (LightsList Size)
and isn't limited, while the table holds 18 positions; a bigger selector
read past the table, and so did a table index other than the front or
rear one. Only the positions the table holds are looked at now, and the
selector stays where it is for a bad table index (cpp:S2259),
- the lambdas of the handover capture what they use explicitly (cpp:S3608),
- the chained assignments resetting the headlight state on the AI taking
over are split (cpp:S1121).
- end the charging position when the control reservoir of any vehicle, the
locomotive included, rises 0.05 bar above the nominal pipe pressure
- standing and unable to depart for 10 s: allow the charging position
regardless of the equivalent pipe pressure and the train type
Resolve the conflicts with the merged nested ifs (#194) in
control_tractive_force() and control_braking_force(): the conditions keep
the new flattened form, with this branch's changes carried into them.
The new braking curve below plans the stop at the signal itself unless
the stopping point moves with it (in testing, trains stopped 0-3 m past
the signal), so both go in one change.
1. The braking curve.
The braking curve towards a lower speed or a stop assumed a constant
deceleration from the present speed over the whole distance. A pneumatic
brake does not work like that:
- it acts on the state the train is in once it has applied; while the
train is still speeding up (downhill), plan from the speed it will have
reached by then, over the distance left by then;
- cast iron blocks grip harder as the train slows, so a constant
deceleration plan asks for too much at the start and then releases;
follow the shape of the consist brake table (fBrake_a0/a1) over speed
instead (shaped_braking_demand), over the distance left once the brake
has had its fill time;
- no power while the train is still above the speed it is braking for.
IncBrake() only adds braking when the brake table says the present
position is not enough. When the table overestimates the consist (see
the previous rapid step fix, or a descent), the train keeps slowing too
little with the handle held. After the full fill time with the handle
unchanged, believe the train rather than the table (fBrakeHeldTime).
When the AI asks for no braking and the train is still slowing down more
than that, release. With the gentler plan above the demand eases off
early, and without this a heavy freight train in G came to a stand a few
hundred metres before a W4 with its brake still on (seen in testing).
2. The stopping window.
In train running the final approach to a stop signal began at
fMaxProximityDist (15-40 m, cargo 25-50 m), aimed at half of
fMinProximityDist (10-15 m, cargo 20-25 m), and set VelDesired = 0,
which asks for hard braking whatever the distance left. Where a train
came to a stand depended on how it entered that phase: on the test
sceneries anywhere from 1 to 45 m short of the signal on the flat and
25-42 m uphill for heavy freight.
For train running only (a W4 stop point, shunting and coupling keep the
old margins and the old final approach):
- stop 8-15 m short of the signal whatever the length of the train, aim
at the middle of that window (stopping_margin) both with the braking
curve and in the final approach, and ask there only for what the
distance left takes, following the consist brake table;
- start the final approach 50 m out (cargo 60 m) whether the train is
moving or standing; it used to be 15-40 m while moving and 50 m once
stopped, and with the gentler final approach above a train that came
to a stand between the two released to creep closer and, uphill,
rolled back and tried again;
- uphill, while the gradient alone would bring the train to a stand short
of the window, keep it rolling at no more than the speed the gradient
can take off by then, with power if needed;
- uphill, put the train brake on as the train comes to a stand, keep it
on while it stands, and apply it for real if the train rolls back. This
is done at the very end of pick_optimal_speed(): the adjustments made
before it assume a train moving forward and can raise the demand back
to "no braking" (with the rule placed earlier, EMUs rolled back up to
90 m in testing). The EMU branch of
control_braking_force() gets the "slipping back" condition the wagon
branch has always had.
3. Known limitation.
Heavy trains of wagons with the ESt3AL2 distributor (413S, 601W and
alike) respond more slowly than the AI expects: with the present brake
model the distributor fills the AL2 relay chamber, whose capacity is set
to 2 in TNESt3::SetSize (Przekladniki[i]->CreateCap(i)), through
orifices sized for about 1 l, so these wagons need 34 s to reach 95 %
cylinder pressure in G against 21 s for a plain ESt3. On a 20 per mille
descent an ET22 with 20 loaded 413S wagons overran the stop signal by up
to 6.5 m in 6 of 24 runs at x20 with this change. With the relay chamber
at 1 l and the release orifices at about 80 % of their diameter, as the
author of the brake model suggested, none of them did (0 of 16).
Two changes that only work together: the first on its own lets a heavy
freight train brake less on a descent than it needs (in testing an
ET42 with 30 loaded wagons overran the stop signal by 16-48 m at 20 per
mille), the second makes the hold on a descent what it should be.
The comparison that decides whether the AI may skip its reaction time
between two brake steps stays on the brake-only demand, as before: it
is about how much brake is asked for, and a heavy train in G approaching
a stop on a descent needs its brake built up at once. Compared in the
resultant frame, that train built up its brake one step per reaction
time and overran the signal (16 copies of the ET42 train, x20:
22 of 32 overruns with the comparison moved, 0 of 48 with it kept).
1. Compare the measured deceleration in the same frame.
Going downhill, adjust_desired_speed_for_current_speed() subtracts the
gravity component from AccDesired, so that IncBrake() sizes the handle
position for what the brake alone has to deliver. control_braking_force()
then compares that brake-only value with AbsAccS, which is the resultant
acceleration and already contains the gravity. On a 20 per mille descent
the two differ by about 0.2 m/s2, so the AI asked for more braking than
the target needed and then released, and repeated that.
Keep the subtracted part in fAccDesiredGravity and add it back wherever
AccDesired is compared with AbsAccS. It is zero everywhere else (flat,
uphill, braking test), so the behaviour there does not change.
2. Hold the speed with one continuous law.
On a descent the AI looks ahead to decide whether it will exceed the
target speed. The look-ahead was (1 - a0) * 30 / 3.6 s, a few seconds,
while a pneumatic brake in G takes tens of seconds to apply or to
release; the AI therefore acted on an estimate the train had already
left behind. The demand then jumped between the braking threshold above
the target and a lerp towards full acceleration below it, and with the
brake that slow this turned into long alternating applications and
releases.
- look ahead for half the brake application time while the train is
speeding up and half the release time while it is slowing down
(brake_response_horizon), never less than before;
- use one law on both sides of the target, proportional to the
predicted difference, and hold a band just below the limit that widens
with the gradient (pneumatic up to 3 km/h, EP/electric up to 1.5 km/h);
- once below a lower limit ahead, hold that limit instead of speeding up
towards the line speed and braking again.
- The warning signal is no longer going to be played for an obnoxiously long amount of time by AI drivers when driving vehicles with a manual warning signal switch, most notably EN57.
- A new `moveDepartureWarned` driving flag has been created to accomodate this behavior.
- Added the action time counter and the missing driving flags to the Vehicle AI section.