mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 22:55:16 +01:00
* fix(ai): a train standing past a signal when its speed table is traced hasn't passed it Since #409 a point of the speed table found behind the head counts as passed only when the head had it ahead once, but a point found up to 5 m behind the head still counted as seen ahead (SeenAheadTolerance), whether the train moved or stood. A train set at a stand 0.5-4.5 m past a signal at stop therefore found the signal behind its head at its first look ahead, the next update marked it elapsed, and the test mode ended with "signal passed at danger" at 13.6 s with the train at 0 km/h (EU07 on td.scn at stacja1_j; set 6 m or 20 m past, no report). The tolerance is kept for a moving train, which may be just passing a point found at its head. A standing train passes nothing: a point found behind its head counts as seen ahead only once an update finds it ahead. The rule moves out of TSpeedPos into vehicle/signalpassing.{h,cpp}, so it is unit tested; the blackbox record of passed signals follows it as before. Measured with the head set 0.5-6 m past and 0.5-2 m short of the signal on tor1k: the distance the scan finds is the head's own distance from the memory cell (to the micrometre there), so a train standing 0.5 m short still gets the signal ahead and passes it if it goes on. Tests: tests/unit/test_signal_passing.cpp (6 cases), and the scenario cases test_mode_standing_1m_past_signal and test_mode_standing_4m_past_signal (fragment td_past_red_signal.scn), which ended as signals passed at danger before and run into their timeout now. * test(scenarios): the shunting AI stops before a signal at stop on td.scn Two cases for the shunting fix of #409, left out of it: an EU07 with no timetable (its AI shunts) starting at 30 km/h about 150 m before the exit signal stacja1_j at stop, alone (eu07_td_shunt_red_signal) and pushing three coaches (eu07_td_shunt_push_red_signal), has to stop before the signal and stay there. They come from #340, whose braking was sharper; run on the code of #409 they stop after 145 m and 141 m, with the signal 151 m from the start, so the checks of #340 (no more than 150 m, below 40 km/h) hold as they were. * fix(sonar): count the metres of the signal passing test in an integer SonarCloud rule cpp:S2193 (a for loop counter of floating type) flagged the loop that moves the head a metre at a time in tests/unit/test_signal_passing.cpp and made the new reliability rating of the pull request fail the quality gate. The counter is now an int; it took whole values only, so every case runs the same number of steps as before. * fix(ai): the gap of a standing train a few decimetres short of a signal noted at seen_ahead_when_found
129 lines
4.5 KiB
C++
129 lines
4.5 KiB
C++
#include "stdafx.h"
|
|
#include "doctest.h"
|
|
|
|
#include "vehicle/signalpassing.h"
|
|
|
|
// when a signal in the AI's speed table counts as passed by the train (TController::CheckSignalPassed): the test
|
|
// mode reports a signal at stop passed that way as "passed at danger", the blackbox records every passed signal. a
|
|
// train set or standing past a signal at the start of a scenario didn't pass it; within 5 m of the signal the test
|
|
// mode used to report it all the same.
|
|
|
|
namespace {
|
|
|
|
// a point of the speed table the way TSpeedPos keeps it: found by the scan of the route, then updated as the head
|
|
// moves on (TController::TableCheck: UpdateDistance, Update, CheckSignalPassed)
|
|
struct table_point {
|
|
double distance; // ahead of the head [m], negative behind it
|
|
bool seen_ahead;
|
|
bool elapsed{false};
|
|
int passes{0}; // reports of the point passed
|
|
|
|
table_point(double const Distance, bool const Standing)
|
|
: distance(Distance), seen_ahead(signal_passing::seen_ahead_when_found(Distance, Standing)) {
|
|
move(0.0); // the first update comes with the next check of the table, the train hasn't moved yet
|
|
}
|
|
|
|
// the head moves Metres on, and the table updates the point
|
|
void move(double const Metres) {
|
|
distance -= Metres;
|
|
auto const elapsedbefore{elapsed};
|
|
elapsed = elapsed || distance < 0.0;
|
|
seen_ahead = signal_passing::seen_ahead_on_update(distance, seen_ahead);
|
|
if (signal_passing::passed_now(elapsedbefore, elapsed, seen_ahead)) {
|
|
++passes;
|
|
}
|
|
}
|
|
|
|
// the head moves Metres on in steps of a metre
|
|
void run(double const Metres) {
|
|
for (int moved{0}; moved < Metres; ++moved) {
|
|
move(1.0);
|
|
}
|
|
}
|
|
};
|
|
|
|
auto constexpr standing{true};
|
|
auto constexpr moving{false};
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("signal passing: a train standing past a signal when its table is traced hasn't passed it") {
|
|
auto behind{0.0};
|
|
// 1-4.5 m: reported as passed at danger before; 20 m: the train standing across the signal of #409
|
|
SUBCASE("0.5 m") { behind = 0.5; }
|
|
SUBCASE("1 m") { behind = 1.0; }
|
|
SUBCASE("2 m") { behind = 2.0; }
|
|
SUBCASE("3 m") { behind = 3.0; }
|
|
SUBCASE("4 m") { behind = 4.0; }
|
|
SUBCASE("4.9 m") { behind = 4.9; }
|
|
SUBCASE("20 m") { behind = 20.0; }
|
|
CAPTURE(behind);
|
|
|
|
table_point signal{-behind, standing};
|
|
CHECK_FALSE(signal.seen_ahead);
|
|
// standing there a while, then pulling away from it
|
|
for (auto check{0}; check < 10; ++check) {
|
|
signal.move(0.0);
|
|
}
|
|
signal.run(200.0);
|
|
CHECK(signal.passes == 0);
|
|
}
|
|
|
|
TEST_CASE("signal passing: a train standing short of a signal passes it when it moves on") {
|
|
auto ahead{0.0};
|
|
SUBCASE("at the signal") { ahead = 0.0; }
|
|
SUBCASE("0.5 m") { ahead = 0.5; }
|
|
SUBCASE("10 m") { ahead = 10.0; }
|
|
SUBCASE("150 m") { ahead = 150.0; }
|
|
CAPTURE(ahead);
|
|
|
|
table_point signal{ahead, standing};
|
|
CHECK(signal.seen_ahead);
|
|
signal.move(0.0);
|
|
CHECK(signal.passes == 0);
|
|
signal.run(ahead + 50.0);
|
|
CHECK(signal.passes == 1);
|
|
}
|
|
|
|
TEST_CASE("signal passing: a moving train passing a signal its table finds just behind the head passes it") {
|
|
// the table traced anew in motion, the head right at the signal: the distance is found in steps of a metre,
|
|
// so a signal just ahead may come out a little behind
|
|
auto behind{0.0};
|
|
SUBCASE("0.5 m") { behind = 0.5; }
|
|
SUBCASE("3 m") { behind = 3.0; }
|
|
SUBCASE("at the tolerance") { behind = signal_passing::moving_tolerance; }
|
|
CAPTURE(behind);
|
|
|
|
table_point signal{-behind, moving};
|
|
CHECK(signal.seen_ahead);
|
|
CHECK(signal.passes == 1);
|
|
signal.run(100.0);
|
|
CHECK(signal.passes == 1);
|
|
}
|
|
|
|
TEST_CASE("signal passing: a signal found further behind a moving train than the tolerance wasn't passed by it") {
|
|
table_point signal{-(signal_passing::moving_tolerance + 0.5), moving};
|
|
CHECK_FALSE(signal.seen_ahead);
|
|
signal.run(100.0);
|
|
CHECK(signal.passes == 0);
|
|
}
|
|
|
|
TEST_CASE("signal passing: a train that overruns a signal and stops past it passes it once") {
|
|
// the overrun counts while the train moves; a table traced again with the train standing 3 m past the signal
|
|
// (a change of direction and back, a new order) doesn't count it again
|
|
table_point approach{150.0, moving};
|
|
approach.run(153.0);
|
|
CHECK(approach.passes == 1);
|
|
|
|
table_point traced_again{-3.0, standing};
|
|
traced_again.run(50.0);
|
|
CHECK(traced_again.passes == 0);
|
|
}
|
|
|
|
TEST_CASE("signal passing: the report of a pass needs the point to become elapsed in this very update") {
|
|
CHECK(signal_passing::passed_now(false, true, true));
|
|
CHECK_FALSE(signal_passing::passed_now(true, true, true)); // elapsed before
|
|
CHECK_FALSE(signal_passing::passed_now(false, false, true)); // still ahead
|
|
CHECK_FALSE(signal_passing::passed_now(false, true, false)); // the head never had it ahead
|
|
}
|