mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 21:45:16 +01:00
* fix(ai): the driver tells of standing with its pantographs up and no voltage An AI driver of an electric vehicle standing past the end of the overhead wire, or under a wire switched off, never gets out of Prepare_engine: the voltage PrepareEngine() waits for doesn't come. It waited without a word (eu07/maszyna#421, L053 poranek with an ET21 on TME222158). Now it says so in the log, once per episode, with the vehicle's name and position, telling a missing wire (no raised pantograph found one) from a wire without voltage. It keeps trying, so towed back under the wire or with the power switched on the vehicle still gets prepared. The decision is ai_power (vehicle/aipower), in the core library with unit tests; scenario case et21_td_no_wire_reports puts an ET21 on a track of its own with no wire next to td.scn. * refactor(ai): the power stall report without Sonar issues stall::none becomes stall::not_stalled (none shadowed a global enumerator), using enum in check(), and an explicit cast of the pantograph count. No change in behaviour. * fix(ai): the power stall report is a traction log line It went out as a generic error, so a scenery that keeps its wire off on purpose couldn't mute it with logs.filter like the other traction lines.
106 lines
4.5 KiB
C++
106 lines
4.5 KiB
C++
#include "stdafx.h"
|
|
#include "doctest.h"
|
|
|
|
#include "vehicle/aipower.h"
|
|
|
|
// the AI driver of an electric vehicle standing with its pantographs up and no voltage at them: what it makes of
|
|
// it, and when it tells of it in the log (eu07/maszyna#421)
|
|
|
|
namespace {
|
|
|
|
using ai_power::stall;
|
|
|
|
// standing with the pantographs up, past the end of the overhead wire
|
|
ai_power::state past_the_wire() {
|
|
ai_power::state state;
|
|
state.collector = true;
|
|
state.power = false;
|
|
state.standing = true;
|
|
state.pantographs_up = true;
|
|
state.wire = false;
|
|
return state;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("ai power: standing with the pantographs up and no wire above them is a stall") {
|
|
CHECK(ai_power::check(past_the_wire()) == stall::no_wire);
|
|
}
|
|
|
|
TEST_CASE("ai power: a wire above the raised pantographs which carries no voltage is told apart") {
|
|
auto state{past_the_wire()};
|
|
state.wire = true;
|
|
|
|
CHECK(ai_power::check(state) == stall::no_voltage);
|
|
}
|
|
|
|
TEST_CASE("ai power: with the voltage there, or without a pantograph to take it, there is nothing to tell") {
|
|
auto powered{past_the_wire()};
|
|
powered.power = true; // at the pantographs, or from the rest of the train through its high voltage cable
|
|
auto diesel{past_the_wire()};
|
|
diesel.collector = false;
|
|
|
|
CHECK(ai_power::check(powered) == stall::not_stalled);
|
|
CHECK(ai_power::check(diesel) == stall::not_stalled);
|
|
}
|
|
|
|
TEST_CASE("ai power: moving, or the pantographs not up yet, it only waits") {
|
|
auto moving{past_the_wire()};
|
|
moving.standing = false; // coasting through a gap of the wire, say
|
|
auto rising{past_the_wire()};
|
|
rising.pantographs_up = false; // the air for the pantographs still being pumped up
|
|
|
|
CHECK(ai_power::check(moving) == stall::waiting);
|
|
CHECK(ai_power::check(rising) == stall::waiting);
|
|
}
|
|
|
|
TEST_CASE("ai power: a stall is reported once it lasted report_delay, and only once") {
|
|
ai_power::reporter reporter;
|
|
|
|
CHECK_FALSE(reporter.update(stall::no_wire, 100.0).has_value());
|
|
CHECK_FALSE(reporter.update(stall::no_wire, 100.0 + ai_power::report_delay - 0.5).has_value());
|
|
auto const report{reporter.update(stall::no_wire, 100.0 + ai_power::report_delay)};
|
|
REQUIRE(report.has_value());
|
|
CHECK(*report == stall::no_wire);
|
|
// the driver keeps trying to prepare the vehicle, without telling of it again
|
|
CHECK_FALSE(reporter.update(stall::no_wire, 100.0 + ai_power::report_delay + 1.0).has_value());
|
|
CHECK_FALSE(reporter.update(stall::no_wire, 1000.0).has_value());
|
|
}
|
|
|
|
TEST_CASE("ai power: the voltage coming back ends the stall, the next one is reported again") {
|
|
ai_power::reporter reporter;
|
|
reporter.update(stall::no_wire, 0.0);
|
|
REQUIRE(reporter.update(stall::no_wire, ai_power::report_delay).has_value());
|
|
|
|
// towed back under the wire: the vehicle gets prepared
|
|
CHECK_FALSE(reporter.update(stall::not_stalled, 100.0).has_value());
|
|
// and later stands without voltage again, under a wire switched off this time
|
|
CHECK_FALSE(reporter.update(stall::no_voltage, 200.0).has_value());
|
|
auto const report{reporter.update(stall::no_voltage, 200.0 + ai_power::report_delay)};
|
|
REQUIRE(report.has_value());
|
|
CHECK(*report == stall::no_voltage);
|
|
}
|
|
|
|
TEST_CASE("ai power: moving or lowering the pantographs restarts the count but doesn't end a reported stall") {
|
|
ai_power::reporter reporter;
|
|
reporter.update(stall::no_wire, 0.0);
|
|
// the vehicle moves before the stall is reported: the count starts again once it stands
|
|
CHECK_FALSE(reporter.update(stall::waiting, 20.0).has_value());
|
|
CHECK_FALSE(reporter.update(stall::no_wire, 25.0).has_value());
|
|
CHECK_FALSE(reporter.update(stall::no_wire, 25.0 + ai_power::report_delay - 1.0).has_value());
|
|
REQUIRE(reporter.update(stall::no_wire, 25.0 + ai_power::report_delay).has_value());
|
|
// still with no voltage, the vehicle moved (pushed a bit) and stands again: no second report
|
|
CHECK_FALSE(reporter.update(stall::waiting, 100.0).has_value());
|
|
CHECK_FALSE(reporter.update(stall::no_wire, 110.0).has_value());
|
|
CHECK_FALSE(reporter.update(stall::no_wire, 110.0 + 2.0 * ai_power::report_delay).has_value());
|
|
}
|
|
|
|
TEST_CASE("ai power: the report names the vehicle, where it stands and why") {
|
|
auto const nowire{ai_power::message(stall::no_wire, "et21-367", {1817.4, 0.38, 4785.94})};
|
|
auto const novoltage{ai_power::message(stall::no_voltage, "et21-367", {1817.4, 0.38, 4785.94})};
|
|
|
|
CHECK(nowire == "AI [et21-367]: can't start, no overhead wire above its raised pantographs (at 1817.40, 0.38, 4785.94); it waits for the voltage");
|
|
CHECK(novoltage.find("no voltage in the overhead wire") != std::string::npos);
|
|
CHECK(novoltage.find("et21-367") != std::string::npos);
|
|
}
|