18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-27 21:45:16 +01:00
Files
maszyna/vehicle/brakingcurve.h
jerrrrycho d3e6736f78 fix(ai): the braking margin ends once the independent brake is on (#479)
* fix(ai): the braking margin ends once the independent brake is on

The braking curve outside the final approach keeps the room the brake
takes to fill only while the brake is still to be applied. It took the
train brake handle past running as the only sign that the brake was on.
A vehicle that runs alone, a light locomotive or a railcar such as the
SN61, brakes with its independent brake and leaves the handle in
running, so the margin never ended for it: on every look it planned to
stop short by the distance the brake takes to fill, slowed down too
early, released, braked again, and crawled the last tens of metres to a
W4 or a signal at stop. This followed #264 and #297.

The independent brake now counts as well (braking_curve::brake_acting,
LocalBrakePosA above 0). On td.scn the light EU07 reaches the W4 of
Przystanek 6.6 s sooner and covers the last 100 m in 20.3 s instead of
26.3 s; on a 20 per mille downgrade it reaches a signal at stop 11.7 s
sooner (last 100 m in 20.6 s instead of 31.7 s), with 3 applications of
the independent brake in the last 300 m instead of 5. A train braking
with the train brake runs as before (its physicslog is the same byte
for byte).

* test(scenarios): light locomotive, railcar and train stopping down a 20 per mille gradient

The *_td_downgrade_w4_signal cases run on a line the fragment adds
beside td.scn: 300 m level, then 3000 m down a gradient of 20 per mille
under a wire fed by a substation of its own. The train stops at the W4
of Dol 1500 m down the gradient and then before a signal at stop 1100 m
further down. They run with a light EU07 and an SN61 alone, which brake
with the independent brake, and with an EU07 and three coaches, which
brakes with the train brake. eu07_coaches_td_timetable is that train on
the td/rozklad timetable to Przystanek.

They show the approach to a stop: before the previous commit the light
EU07 needed 31.7 s for the last 100 m to the signal, now 20.6 s; the
train with coaches runs the same in both.

* fix(ai): the braking margin counts the independent brake only on a vehicle that has one

* test(scenarios): the light EU07 and the SN61 stop at the signal down the gradient in time
2026-11-25 05:15:02 +01:00

61 lines
3.0 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
// the deceleration the AI asks for on its way down to a lower speed or a stop ahead, outside of the final
// approach (TController::adjust_desired_speed_for_braking_curve)
namespace braking_curve {
// the deceleration table of the consist brake, by speed (TController::fBrake_a0, fBrake_a1). it is worked out
// for a train only (Obey_train, Bank); in shunting it stays at zero
struct brake_table {
double const *a0; // deceleration at handle position 1, by speed; a0[1..size]
double const *a1; // deceleration added by each quarter of a position, by speed
int size; // entries, up to the vehicle's top speed
double vmax; // the vehicle's top speed [km/h]
// deceleration [m/s2] of a full service application at Kmh
double full_braking(double Kmh) const;
// whether the table is worked out
bool known() const;
};
// resultant acceleration [m/s2] to ask for now so that a steady application of the pneumatic brake takes the train
// from Velocity down to Target [km/h] over Distance [m], with the brake force following the speed the way the
// table says it does (cast iron blocks grip harder as the train slows)
double shaped_demand(double Velocity, double Target, double Distance, double Gravity, brake_table const &Table);
// where the train is on its way down to Target
struct approach {
double speed; // present speed in the direction of travel [km/h]
double target; // speed to get down to [km/h]
double distance; // to where the speed is to be down [m]
double offset; // the braking point that far short of it [m]
double gravity; // tangential acceleration of the gradient [m/s2], negative uphill
double acceleration; // present acceleration of the train [m/s2]
bool brake_applied; // the brake the train slows down with is applied (brake_acting)
double speedup_horizon; // how long the present acceleration lasts while speeding up [s]
double fill_horizon; // how long the brake takes to fill once applied [s]
};
// whether the train is braking already, for approach::brake_applied: the train brake handle is past running
// (Trainbrakeposition above 0), or the independent brake is applied (Localbrakeposition above 0). a vehicle that
// runs alone, a light locomotive or a railcar, brakes with the independent brake and leaves the train brake
// handle in running
bool brake_acting(double Trainbrakeposition, double Localbrakeposition);
// acceleration [m/s2] to ask for now, negative to brake. with the worked out table of a pneumatic brake
// (Pneumatictable) the demand follows the brake: planned from the state the train is in once the brake has
// responded, along the shape of its force over speed. without one (nullptr for another brake, or a table left at
// zero, as in shunting) it is the constant deceleration over the distance left
double demand(approach const &Approach, brake_table const *Pneumatictable);
} // namespace braking_curve