18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-27 21:45:16 +01:00

AI: say so when standing with the pantographs up and no voltage (#344)

* 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.
This commit is contained in:
jerrrrycho
2026-11-25 06:15:09 +01:00
committed by GitHub
parent 8c8d5ff5cc
commit 4d12693376
9 changed files with 320 additions and 6 deletions

View File

@@ -564,6 +564,7 @@ set(CORE_SOURCES
"scripting/scriptscreenkernels.cpp"
"scripting/scriptscreendrawing.cpp"
"simulation/simulationtestrules.cpp"
"vehicle/aipower.cpp"
"vehicle/aiwire.cpp"
"vehicle/blackbox.cpp"
"utilities/physicslog.cpp"

View File

@@ -301,6 +301,12 @@ couple and neither shows up: the black box has to have the last car of the stand
writes nothing to the log when couplers catch). Nothing reports a result, so both end on the 60 s
test timeout.
`et21_td_no_wire_reports` (issue #421, fragment `td_no_wire.scn`) adds a 200 m track of its own,
with no overhead wire, 400 m off the line of td.scn (every track of td.scn is under the wire), with
an ET21 and its AI driver on it. The pantographs go up and find no wire, so the locomotive can't
start: the driver has to say so in the log, once, naming the locomotive and where it stands, and
not mistake it for a wire without voltage. It ends on the standstill.
`eu07_td_cold_connect` (fragment `td_cold_connect.scn`) has an EU07 with a hand brake
(`4E-ZEZ_GREY`; the plain `4e` has none) standing cold on track 1 of Stacja1 (trainset velocity 0,
so it starts with the hand brake on) and two coaches standing 45 m ahead of it. Its driver sleeps

View File

@@ -0,0 +1,27 @@
{
"description": "ET21 with an AI driver on a track of td.scn's own with no overhead wire: it raises the pantographs, finds no wire and can't start; the driver tells of it in the log, once, and keeps waiting for the voltage (eu07/maszyna#421). The test ends on the standstill.",
"base_scenery": "td.scn",
"fragment": "td_no_wire.scn",
"vars": {
"consist": "node -1 0 {{vehicle}} dynamic pkp\\et21_v2 ET21-367 3e2 0 headdriver 0 0 enddynamic"
},
"test_config": [
"test.standstill 300"
],
"expect": "standstill",
"timeout": 900,
"checks": [
{
"type": "log_contains",
"pattern": "AI \\[autotest_et21_td_no_wire_reports\\]: can't start, no overhead wire above its raised pantographs \\(at -?[\\d.]+, -?[\\d.]+, -?[\\d.]+\\)"
},
{
"type": "log_lacks",
"pattern": "no voltage in the overhead wire at its raised pantographs"
},
{
"type": "distance",
"max": 1
}
]
}

View File

@@ -0,0 +1,18 @@
// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed.
// a piece of track of its own, 200 m long and with no overhead wire above it, 400 m off the line of td.scn
// (all of whose tracks are under the wire), and an electric locomotive with an AI driver standing on it.
// the driver raises the pantographs, which find no wire, and waits in Prepare_engine for the voltage for good
// (eu07/maszyna#421); it tells of it in the log once.
node -1 0 autotest_no_wire track normal 200.0 1.435 0.15 25.0 20 0 flat vis
rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1
-400.0 0.2 0.0 0.0 //point 1
0.0 0.0 0.0 //control vector 1
0.0 0.0 0.0 //control vector 2
-400.0 0.2 200.0 0.0 //point 2
0
endtrack
// no timetable: the driver goes shunting; 0.01 km/h has it prepare the vehicle and wait for a signal (at 0 it sleeps)
trainset none autotest_no_wire 100.0 0.01
{{consist}}
endtrainset

View File

@@ -0,0 +1,105 @@
#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);
}

View File

@@ -3248,15 +3248,15 @@ bool TController::PrepareEngine()
close_line_breaker();
}
auto const sufficientpantographpressure { (
is_emu() ?
2.5 : // Ra 2013-12: Niebugocław mówi, że w EZT podnoszą się przy 2.5
3.5 )
+ 0.1 }; // leeway margin
if( mvPantographUnit->EnginePowerSource.SourceType == TPowerSource::CurrentCollector
&& mvPantographUnit->EnginePowerSource.CollectorParameters.CollectorsNo > 0 ) {
// if our pantograph unit isn't a pantograph-devoid fallback
auto const sufficientpantographpressure { (
is_emu() ?
2.5 : // Ra 2013-12: Niebugocław mówi, że w EZT podnoszą się przy 2.5
3.5 )
+ 0.1 }; // leeway margin
if (mvPantographUnit->PantPress < sufficientpantographpressure) {
// załączenie małej sprężarki
if( false == mvPantographUnit->PantAutoValve ) {
@@ -3286,6 +3286,9 @@ bool TController::PrepareEngine()
auto const ispoweravailable =
mvControlling->EnginePowerSource.SourceType != TPowerSource::CurrentCollector
|| std::max(mvControlling->GetTrainsetHighVoltage(), mvControlling->PantographVoltage) > mvControlling->EnginePowerSource.CollectorParameters.MinV;
// standing with the pantographs up and no voltage, nothing the driver does starts the vehicle. it says so, and keeps
// trying: towed back under the wire, or with the power switched on, the vehicle gets prepared after all
report_power_stall( ispoweravailable, sufficientpantographpressure );
bool isready = false;
@@ -3372,6 +3375,39 @@ bool TController::PrepareEngine()
return iEngineActive;
}
// tells in the log, once, of standing with the pantographs up and no voltage at them, past the end of the overhead
// wire or under a wire switched off (eu07/maszyna#421). Poweravailable is what PrepareEngine() found, Pantographpressure
// the air the pantographs need to rise
void
TController::report_power_stall( bool const Poweravailable, double const Pantographpressure ) {
ai_power::state state;
state.collector = mvControlling->EnginePowerSource.SourceType == TPowerSource::CurrentCollector;
state.power = Poweravailable;
state.standing = mvOccupied->Vel < EU07_AI_NOMOVEMENT;
if( mvPantographUnit->PantPress >= Pantographpressure ) {
state.pantographs_up =
mvPantographUnit->Pantographs[ end::front ].is_active
|| mvPantographUnit->Pantographs[ end::rear ].is_active;
}
// the pantographs of the vehicle carrying them hold the wire they found above them
if( auto const *carrier { pVehicle->FindPantographCarrier() };
carrier != nullptr && carrier->MoverParameters == mvPantographUnit ) {
auto const pantographcount { std::min<int>( carrier->iAnimType[ ANIM_PANTS ], static_cast<int>( carrier->MoverParameters->Pantographs.size() ) ) };
for( auto index { 0 }; index < pantographcount; ++index ) {
if( true == carrier->MoverParameters->Pantographs[ index ].is_active
&& carrier->pants[ index ].fParamPants->hvPowerWire != nullptr ) {
state.wire = true;
}
}
}
// a user driving the vehicle sees the voltmeters for themselves
if( auto const stall { m_powerstall.update( AIControllFlag ? ai_power::check( state ) : ai_power::stall::waiting, ElapsedTime ) };
stall.has_value() ) {
ErrorLog( ai_power::message( *stall, pVehicle->asName, pVehicle->GetPosition() ), logtype::traction );
}
}
// wyłączanie silnika (test wyłączenia, a część wykonawcza tylko jeśli steruje komputer)
bool TController::ReleaseEngine() {
/*

View File

@@ -20,6 +20,7 @@ http://mozilla.org/MPL/2.0/.
#include "utilities/translation.h"
#include "application/driverhints.h"
#include "vehicle/blackbox.h"
#include "vehicle/aipower.h"
auto const EU07_AI_ACCELERATION = 0.05;
auto const EU07_AI_NOACCELERATION = -0.05;
@@ -683,6 +684,9 @@ public:
bool CheckVehicles( TOrders user = Wait_for_orders );
private:
bool PrepareEngine();
// tells in the log, once, of standing with the pantographs up and no voltage (eu07/maszyna#421)
void report_power_stall( bool const Poweravailable, double const Pantographpressure );
ai_power::reporter m_powerstall; // the reports of report_power_stall()
void close_line_breaker();
bool ReleaseEngine();
void Doors( bool const Open, int const Side = 0 );

56
vehicle/aipower.cpp Normal file
View File

@@ -0,0 +1,56 @@
/*
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/.
*/
#include "stdafx.h"
#include "vehicle/aipower.h"
#include <format>
namespace ai_power {
stall check(state const &State) {
using enum stall;
if (false == State.collector || true == State.power) {
return not_stalled;
}
if (false == State.standing || false == State.pantographs_up) {
return waiting;
}
return State.wire ? no_voltage : no_wire;
}
std::optional<stall> reporter::update(stall const Stall, double const Now) {
if (Stall == stall::not_stalled) {
m_since.reset();
m_reported = false;
return std::nullopt;
}
if (Stall == stall::waiting) {
m_since.reset();
return std::nullopt;
}
if (false == m_since.has_value()) {
m_since = Now;
}
if (true == m_reported || Now - *m_since < report_delay) {
return std::nullopt;
}
m_reported = true;
return Stall;
}
std::string message(stall const Stall, std::string const &Name, glm::dvec3 const &Position) {
auto const reason{
Stall == stall::no_wire ?
"no overhead wire above its raised pantographs" :
"no voltage in the overhead wire at its raised pantographs"};
return std::format("AI [{}]: can't start, {} (at {:.2f}, {:.2f}, {:.2f}); it waits for the voltage", Name, reason, Position.x, Position.y, Position.z);
}
} // namespace ai_power

61
vehicle/aipower.h Normal file
View File

@@ -0,0 +1,61 @@
/*
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
#include <optional>
#include <string>
#include <glm/glm.hpp>
// an AI driver of an electric vehicle standing with its pantographs up and no voltage at them: past the end of the
// overhead wire, or under a wire which is switched off. no driver can start such a vehicle, it waits in
// TController::PrepareEngine() until the voltage comes, towed back under the wire or the power switched on. the
// driver tells of it in the log, once, instead of waiting without a word (eu07/maszyna#421)
namespace ai_power {
// what the driver knows of the power of the vehicle when it prepares it
struct state {
bool collector{false}; // the vehicle takes its power from the overhead wire
bool power{false}; // there is the voltage the vehicle needs, at its pantographs or from the rest of the train
bool standing{false}; // the vehicle stands
bool pantographs_up{false}; // a pantograph is raised, with the air to hold it up
bool wire{false}; // a raised pantograph found a wire above it
};
enum class stall {
not_stalled, // the voltage is there, or the vehicle doesn't take it from the wire
waiting, // no voltage, but nothing to tell yet: the vehicle moves, or its pantographs aren't up
no_wire, // standing with the pantographs up and no wire above them
no_voltage // standing with a pantograph up at a wire which carries no voltage
};
stall check(state const &State);
// how long [s] the vehicle stands with its pantographs up and no voltage before the driver tells of it. the
// pantographs need a few seconds to rise and the voltage a moment to come, a gap under a section insulator is
// shorter still
inline constexpr double report_delay{30.0};
// tells of a stall once: one report while it lasts. the voltage coming back ends it, and the next one is reported
// again; moving, or the pantographs going down, only restarts the count of report_delay
class reporter {
public:
// one look at the vehicle at the time Now [s]: the stall to report now, if any
std::optional<stall> update(stall Stall, double Now);
private:
std::optional<double> m_since; // when the vehicle began to stand with the pantographs up and no voltage
bool m_reported{false}; // the stall has been reported
};
// the line of the log telling of the stall of the vehicle Name standing at Position
std::string message(stall Stall, std::string const &Name, glm::dvec3 const &Position);
} // namespace ai_power