18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-19 22:44:59 +01:00
Files
maszyna/vehicle/brakingcurve.h
maj00r 267d5b3a8f AI: shunting brakes for a stop point again; test mode: no false SPAD for a train set across a signal (#409)
* fix(ai): shunting AI brakes for a stop point again, the braking curve doesn't plan from a brake table left at zero

The braking curve outside the final approach plans from the consist brake table since ce87aa0e (#187, merged
with #264) whenever the brake is pneumatic. That table is worked out only for train running (Obey_train, Bank);
in shunting it stays at zero, the planned full braking falls to its floor of 0.01 m/s2, and the demand comes out
at a few hundredths of a m/s2, above the shunting brake threshold of -0.2. A shunting engine then rolled on
without braking until the final approach, too late, and ran through the signal it was to stop at (seed
480873929 of l053_poranek: ep07p-2003 at sandomierz_g4_sem_info, sm42-1096, et22-654).

With no worked out table the curve is again the constant deceleration over the distance left, as it was before
ce87aa0e and as #187 meant to keep it for shunting. Train running is unchanged.

The curve moves out of TController into vehicle/brakingcurve.{h,cpp} so that it is unit tested:
tests/unit/test_braking_curve.cpp checks a shunting engine braking to a stop point with the zeroed table, and
that a train with a worked out table gets the same demand as before.

* test(ai): pin the train braking-curve demand to the results of the code before the move

A brake table that grips harder as the train slows and a gradient, so that a wrong gravity sign, table index or a dropped term in the shaped demand shows; the expected values were worked out with the code removed from TController::adjust_desired_speed_for_braking_curve.

* fix(test): a train set across a signal doesn't pass it at danger the moment the AI first looks at it

The speed table takes in events up to a train length behind the head, so a signal the train stands across at the start of a scenario is found already behind the head, becomes elapsed on its first update, and the test mode reported it as passed at danger (calkowo_lotos: st43-189 at mac_daleko3_sem_info, manewrowo3: st43-100 at suw_szopa_a02_sem_info, both at 13.6 s with the train at a stand, the signal 20 m behind the head). A point now counts as passed only when the head of the train had it ahead once; the blackbox record of passed signals follows the same rule.

* fix(test): a signal found up to 5 m behind the head still counts as seen ahead

The distance to an event is found in steps of a metre from the position of its memory cell, so a signal just ahead of the head (a train stopped short of it when the autopilot takes over, or set right at it at the start) could come out slightly behind it, and passing it would not be reported. The trains set across a signal that the previous commit is about stood 20 m past it.

Still not reported: a signal crossed while the speed table is being traced anew in motion (a Timetable: command to a running train, the autopilot taking over in motion), as it is found behind the head when the trace is made.

* docs(test): say what the seen-ahead tolerance gives up

A train set less than 5 m past a signal at stop is still reported to pass it at danger: standing that close it can't be told from a train stopped just short of the signal, which the tolerance is there for.

---------

Co-authored-by: maj00r <maj00r@host>
2026-11-19 04:55:33 +01:00

55 lines
2.6 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 train brake handle is past running
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]
};
// 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