From 5a20f86fd0b42d46e17b7ce1b5094fbb46c53e17 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sat, 7 Nov 2026 19:18:37 +0100 Subject: [PATCH 1/3] feat: line breaker before the pantographs, Cntrl.PantRequiresMain (#68) New optional .fiz key Cntrl.PantRequiresMain (default No, every existing vehicle unchanged). With Yes, as on Czech-built locomotives: - the line breaker closes on the low voltage circuits, without traction voltage, and the undervoltage trip doesn't open it (overvoltage and the other trips still do); - a pantograph valve opens and stays open only while the vehicle's line breaker is closed, so opening it drops the pantographs. The AI (TController::PrepareEngine) closes the line breaker before raising the pantographs for such a vehicle; the line breaker steps moved into TController::close_line_breaker(). test::start_up() follows the same order. Game data: to use it, PantRequiresMain=Yes goes on the Cntrl. line of dynamic/pkp/ep05_v2/ep05.fiz, ep05v1.fiz and dynamic/cd/181_v2/181_cz1.fiz, 18x_pl.fiz (left for later, not part of this change). (#68) --- McZapkie/MOVER.h | 4 + McZapkie/Mover.cpp | 19 ++- tests/unit/drive.cpp | 7 ++ tests/unit/test_mains_before_pantographs.cpp | 117 +++++++++++++++++++ vehicle/Driver.cpp | 31 +++-- vehicle/Driver.h | 1 + 6 files changed, 164 insertions(+), 15 deletions(-) create mode 100644 tests/unit/test_mains_before_pantographs.cpp diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 199c65a0c..24a0a3fc4 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -2093,6 +2093,10 @@ class TMoverParameters double MainsInitTime{0.0}; // config, initialization time (in seconds) of the main circuit after it receives power, before it can be closed double MainsInitTimeCountdown{0.0}; // current state of main circuit initialization, remaining time (in seconds) until it's ready start_t MainsStart{start_t::manual}; + // config, .fiz Cntrl.PantRequiresMain: the line breaker closes without traction voltage and holds without it, and the + // pantographs rise and stay up only while it's closed (Czech locomotives); off, the pantographs come first and the line + // breaker needs their voltage + bool PantographsRequireMains{false}; bool LineBreakerClosesOnlyAtNoPowerPos{false}; bool ControlPressureSwitch{false}; // activates if the main pipe and/or brake cylinder pressure aren't within operational levels bool HasControlPressureSwitch{true}; diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 330e8eb8f..36ad8a52e 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -1735,7 +1735,8 @@ void TMoverParameters::MainsCheck(double const Deltatime) break; } } - auto const maincircuitpowersupply{std::abs(localvoltage) > 0.1 || GetTrainsetHighVoltage() > 0.1}; + // a line breaker closed ahead of the pantographs gets ready on the low voltage circuits + auto const maincircuitpowersupply{std::abs(localvoltage) > 0.1 || GetTrainsetHighVoltage() > 0.1 || (PantographsRequireMains && (Power24vIsAvailable || Power110vIsAvailable))}; if (true == maincircuitpowersupply) { @@ -2327,7 +2328,8 @@ void TMoverParameters::PantographsCheck(double const /*Timestep*/) valve.is_active = (valve.spring ? lowvoltagepower : true) // spring actuator needs power to maintain non-default state && (manualcontrol && lowvoltagepower ? false == valve.is_disabled : true) // needs power to change state, without it just pass through && (manualcontrol && lowvoltagepower ? false == PantAllDown : true) && - (valve.is_active || (manualcontrol && lowvoltagepower && valve.is_enabled) || (autostart && lowvoltagepower)); // shouldn't ever get this far but, eh + (Mains || false == PantographsRequireMains) // fed through the closed line breaker, where it comes first + && (valve.is_active || (manualcontrol && lowvoltagepower && valve.is_enabled) || (autostart && lowvoltagepower)); // shouldn't ever get this far but, eh auto const pantographexists{EnginePowerSource.SourceType == TPowerSource::CurrentCollector && EnginePowerSource.CollectorParameters.PhysicalLayout & 1 << pant_id}; @@ -3683,7 +3685,8 @@ bool TMoverParameters::MainSwitchCheck() const case ElectricInductionMotor: { // TODO: check whether we can simplify this check and skip the outer EngineType switch - powerisavailable = EnginePowerSourceVoltage() > 0.5 * EnginePowerSource.MaxVoltage; + // closed ahead of the pantographs, the line breaker runs on the low voltage circuits + powerisavailable = PantographsRequireMains ? Power24vIsAvailable || Power110vIsAvailable : EnginePowerSourceVoltage() > 0.5 * EnginePowerSource.MaxVoltage; break; } default: @@ -3693,7 +3696,8 @@ bool TMoverParameters::MainSwitchCheck() const } return powerisavailable && (ScndCtrlPos == 0 || EngineType == ElectricInductionMotor) && MainsInitTimeCountdown <= 0.0 && - (ConvOvldFlag == false || ConverterOverloadRelayOffWhenMainIsOff) && true == GroundRelay && true == NoVoltRelay && true == OvervoltageRelay && LastSwitchingTime > CtrlDelay && + (ConvOvldFlag == false || ConverterOverloadRelayOffWhenMainIsOff) && true == GroundRelay && (true == NoVoltRelay || PantographsRequireMains) && true == OvervoltageRelay && + LastSwitchingTime > CtrlDelay && (HasCamshaft ? IsMainCtrlActualNoPowerPos() : LineBreakerClosesOnlyAtNoPowerPos ? IsMainCtrlNoPowerPos() : true) && @@ -5698,7 +5702,8 @@ double TMoverParameters::TractionForce(double dt) OvervoltageRelay = EnginePowerSource.SourceType != TPowerSource::CurrentCollector || voltage <= EnginePowerSource.CollectorParameters.MaxV || false == EnginePowerSource.CollectorParameters.OVP; // wywalanie szybkiego z powodu niewłaściwego napięcia - EventFlag |= true == Mains && (false == NoVoltRelay || false == OvervoltageRelay) && + // (a line breaker closed ahead of the pantographs holds without voltage) + EventFlag |= true == Mains && ((false == NoVoltRelay && false == PantographsRequireMains) || false == OvervoltageRelay) && MainSwitch(false, TrainType == dt_EZT ? range_t::unit : range_t::local); // TODO: check whether we need to send this EMU-wide break; } @@ -5707,7 +5712,8 @@ double TMoverParameters::TractionForce(double dt) { // TODO: check if we can use instead the code for electricseriesmotor // nie wchodzić w funkcję bez potrzeby - if (Mains && (std::max(GetTrainsetHighVoltage(), PantographVoltage) < EnginePowerSource.CollectorParameters.MinV || + // (a line breaker closed ahead of the pantographs holds without voltage) + if (Mains && ((std::max(GetTrainsetHighVoltage(), PantographVoltage) < EnginePowerSource.CollectorParameters.MinV && false == PantographsRequireMains) || std::max(GetTrainsetHighVoltage(), PantographVoltage) > EnginePowerSource.CollectorParameters.MaxV + 200)) { MainSwitch(false, TrainType == dt_EZT ? range_t::unit : range_t::local); // TODO: check whether we need to send this EMU-wide @@ -10934,6 +10940,7 @@ void TMoverParameters::LoadFIZ_Cntrl(std::string const &line) auto lookup = starts.find(extract_value("MainStart", line)); MainsStart = lookup != starts.end() ? lookup->second : start_t::manual; } + extract_value(PantographsRequireMains, "PantRequiresMain", line, ""); // battery { auto lookup = starts.find(extract_value("BatteryStart", line)); diff --git a/tests/unit/drive.cpp b/tests/unit/drive.cpp index 0ee5adb2b..b03eeac2d 100644 --- a/tests/unit/drive.cpp +++ b/tests/unit/drive.cpp @@ -169,6 +169,13 @@ bool start_up(driven Driven, track const &Track, double Seconds, trace *Trace) { if (diesel) { prepare_diesel(Driven); } + if (controlling.PantographsRequireMains && false == controlling.Mains) { + // the pantographs rise only through the closed line breaker, which closes without their voltage + for (int i = 0; i < 3 && cab.DirActive <= 0; ++i) { + cab.DirectionForward(); + } + close_line_breaker(Driven); + } if (collector) { raise_pantographs(Driven); } diff --git a/tests/unit/test_mains_before_pantographs.cpp b/tests/unit/test_mains_before_pantographs.cpp new file mode 100644 index 000000000..01f6e1197 --- /dev/null +++ b/tests/unit/test_mains_before_pantographs.cpp @@ -0,0 +1,117 @@ +#include "stdafx.h" +#include "doctest.h" +#include "drive.h" + +// the order of the line breaker and the pantographs (eu07/maszyna#68): on Polish locomotives the pantographs +// come first and the line breaker closes on their voltage; on Czech ones (Cntrl.PantRequiresMain) the line +// breaker closes first, without voltage, and the pantographs rise and stay up only while it's closed + +namespace { + +constexpr test::track line{0.15, 0.0, test::catenary_3kv}; + +test::definition ep05(bool const Mainsfirst) { + auto definition{test::definition::fiz("ep05_v2/ep05")}; + if (Mainsfirst) { + definition.set("Cntrl", "PantRequiresMain", "Yes"); + } + return definition; +} + +// battery and cab on, direction set and the relays reset, the pantographs on the main reservoir's air +void prepare(test::vehicle &Loco) { + Loco.hold_main_reservoir(6.0); + Loco->bPantKurek3 = true; + Loco->BatterySwitch(true); + Loco->CabActivisation(); + for (int i = 0; i < 3 && Loco->DirActive <= 0; ++i) { + Loco->DirectionForward(); + } + Loco.run(2.0, line); + Loco->RelayReset(relay_t::maincircuitground | relay_t::tractionnmotoroverload | relay_t::primaryconverteroverload); + Loco.run(2.0, line); +} + +void raise_pantograph(test::vehicle &Loco) { + Loco->OperatePantographsValve(operation_t::enable); + Loco->OperatePantographValve(end::rear, operation_t::enable); + Loco.run(5.0, line); +} + +void close_line_breaker(test::vehicle &Loco) { + Loco->MainSwitch(true); + Loco.run(2.0, line); +} + +} // namespace + +TEST_CASE("mains before pantographs: without the flag the line breaker needs the pantographs' voltage, as before") { + test::vehicle loco{ep05(false), 0.0, "test", 1}; + REQUIRE_FALSE(loco->PantographsRequireMains); + prepare(loco); + close_line_breaker(loco); + CHECK_FALSE(loco->Mains); + raise_pantograph(loco); + CHECK(loco->Pantographs[end::rear].is_active); + CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv)); + close_line_breaker(loco); + CHECK(loco->Mains); + // the pantographs stay up with the line breaker open, and the line breaker opens without voltage + loco->MainSwitch(false); + loco.run(2.0, line); + CHECK(loco->Pantographs[end::rear].is_active); + close_line_breaker(loco); + REQUIRE(loco->Mains); + loco->OperatePantographValve(end::rear, operation_t::disable); + loco.run(2.0, line); + CHECK_FALSE(loco->Mains); +} + +TEST_CASE("mains before pantographs: with the flag the pantographs rise only through the closed line breaker") { + test::vehicle loco{ep05(true), 0.0, "test", 1}; + REQUIRE(loco->PantographsRequireMains); + prepare(loco); + // the pantographs stay down while the line breaker is open + raise_pantograph(loco); + CHECK_FALSE(loco->Pantographs[end::rear].is_active); + CHECK(loco->PantographVoltage == 0.0); + // the line breaker closes without voltage, and the pantograph rises through it + close_line_breaker(loco); + CHECK(loco->Mains); + raise_pantograph(loco); + CHECK(loco->Pantographs[end::rear].is_active); + CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv)); + CHECK(loco->Mains); + // opening the line breaker drops the pantograph, which stays down until the line breaker closes again + loco->MainSwitch(false); + loco.run(2.0, line); + CHECK_FALSE(loco->Mains); + CHECK_FALSE(loco->Pantographs[end::rear].is_active); + CHECK(loco->PantographVoltage == 0.0); + // a pantograph lowered under the closed line breaker leaves it closed + close_line_breaker(loco); + raise_pantograph(loco); + REQUIRE(loco->Pantographs[end::rear].is_active); + loco->OperatePantographValve(end::rear, operation_t::disable); + loco.run(5.0, line); + CHECK_FALSE(loco->Pantographs[end::rear].is_active); + CHECK(loco->Mains); +} + +TEST_CASE("mains before pantographs: with the flag the line breaker still needs the battery") { + test::vehicle loco{ep05(true), 0.0, "test", 1}; + loco.hold_main_reservoir(6.0); + loco.run(2.0, line); + close_line_breaker(loco); + CHECK_FALSE(loco->Mains); +} + +TEST_CASE("mains before pantographs: with the flag the driver's start-up gets the locomotive ready") { + // test::start_up() takes the AI's steps of TController::PrepareEngine(), the line breaker first here + test::vehicle loco{ep05(true), 0.0, "test", 1}; + auto driven{test::driving(loco)}; + REQUIRE(test::start_up(driven, line)); + CHECK(loco->Mains); + CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv)); + CHECK(test::is_ready(driven)); +} diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 08f0c0d24..8605ebab5 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -2679,6 +2679,20 @@ void TController::SetDriverPsyche() { } } +// closes the line breaker, or starts the engine, the relays reset first +void TController::close_line_breaker() +{ + cue_action( driver_hint::mastercontrollersetzerospeed ); + // consist-wide ground relay reset + cue_action( driver_hint::maincircuitgroundreset ); + cue_action( driver_hint::tractionnmotoroverloadreset ); + if( mvOccupied->EngineType == TEngineType::DieselEngine ) { + // specjalnie dla SN61 żeby nie zgasł + cue_action( driver_hint::mastercontrollersetidle ); + } + cue_action( driver_hint::linebreakerclose ); +} + bool TController::PrepareEngine() { // odpalanie silnika // HACK: don't immediately activate inert vehicle in case the simulation is about to replace us with human driver @@ -2702,6 +2716,13 @@ bool TController::PrepareEngine() } } + if( mvControlling->PantographsRequireMains + && IsAnyLineBreakerOpen ) { + // the pantographs rise only through the closed line breaker, which closes without their voltage + PrepareDirection(); + close_line_breaker(); + } + if( mvPantographUnit->EnginePowerSource.SourceType == TPowerSource::CurrentCollector && mvPantographUnit->EnginePowerSource.CollectorParameters.CollectorsNo > 0 ) { // if our pantograph unit isn't a pantograph-devoid fallback @@ -2756,15 +2777,7 @@ bool TController::PrepareEngine() } if( IsAnyLineBreakerOpen ) { // activate main circuit or engine - cue_action( driver_hint::mastercontrollersetzerospeed ); - // consist-wide ground relay reset - cue_action( driver_hint::maincircuitgroundreset ); - cue_action( driver_hint::tractionnmotoroverloadreset ); - if( mvOccupied->EngineType == TEngineType::DieselEngine ) { - // specjalnie dla SN61 żeby nie zgasł - cue_action( driver_hint::mastercontrollersetidle ); - } - cue_action( driver_hint::linebreakerclose ); + close_line_breaker(); } else { // main circuit or engine is on, set up vehicle devices and controls diff --git a/vehicle/Driver.h b/vehicle/Driver.h index f88e115ac..78aaf1abb 100644 --- a/vehicle/Driver.h +++ b/vehicle/Driver.h @@ -592,6 +592,7 @@ public: bool CheckVehicles( TOrders user = Wait_for_orders ); private: bool PrepareEngine(); + void close_line_breaker(); bool ReleaseEngine(); void Doors( bool const Open, int const Side = 0 ); // returns true if any vehicle in the consist has an open door From c4dc2ccb3519156d0b4c390795012b5e7a2cbdec Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 8 Nov 2026 13:00:51 +0100 Subject: [PATCH 2/3] =?UTF-8?q?docs:=20PantRequiresMain=20is=20for=20the?= =?UTF-8?q?=20EU05,=20EP05=20and=20=C4=8CD=20181=20family,=20not=20every?= =?UTF-8?q?=20Czech=20locomotive=20(#68)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The comment on the flag named Czech locomotives in general; the EP03 doesn't get it. --- McZapkie/MOVER.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 24a0a3fc4..c08797c50 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -2094,7 +2094,7 @@ class TMoverParameters double MainsInitTimeCountdown{0.0}; // current state of main circuit initialization, remaining time (in seconds) until it's ready start_t MainsStart{start_t::manual}; // config, .fiz Cntrl.PantRequiresMain: the line breaker closes without traction voltage and holds without it, and the - // pantographs rise and stay up only while it's closed (Czech locomotives); off, the pantographs come first and the line + // pantographs rise and stay up only while it's closed (EU05, EP05, ČD 181 family); off, the pantographs come first and the line // breaker needs their voltage bool PantographsRequireMains{false}; bool LineBreakerClosesOnlyAtNoPowerPos{false}; From 226eaabb7b2f78f4ee474be342d15e7ae1bc1b53 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 11 Nov 2026 21:54:20 +0100 Subject: [PATCH 3/3] fix: behind a line breaker closed ahead of the pantographs the main circuit still needs the voltage Review of #272. The closed line breaker used to mean there's traction voltage, the undervoltage trip opening it without one. With PantRequiresMain=Yes it closes on the battery and holds without voltage, so everything that took Mains for "the main circuit is live" ran with the pantographs down, lowered for a section, or under a dead catenary. - MainCircuitPowered(): the line breaker closed, and on a vehicle with PantRequiresMain and current collectors also the voltage at least MinV (what the undervoltage trip takes). For every other vehicle it is Mains. It feeds the converter (and through it the 110 V and a compressor on it), a compressor on the main circuit, the heating from the main circuit, the motor blowers, the blowers of the starting resistors, the current of the series motors and the induction motor drive. - The undervoltage relay of such a vehicle opens the line contactors, as the line breaker opening did elsewhere: the camshaft goes back to zero and the motors get no current, also not the generator current a closed circuit without voltage gave. The relay picks up again with the voltage back and the master controller at zero or the first position, so the start begins anew instead of the camshaft running back up to the position left on the controller. Vehicles without the key are unchanged: the golden traces recorded before the change compare exactly. --- McZapkie/MOVER.h | 12 +- McZapkie/Mover.cpp | 51 +++- tests/unit/test_mains_before_pantographs.cpp | 240 ++++++++++++++++++- 3 files changed, 287 insertions(+), 16 deletions(-) diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 09a8c7dc9..c14a263fe 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -2165,7 +2165,8 @@ class TMoverParameters bool JointEngineStart{true}; // config, .fiz Cntrl.PantRequiresMain: the line breaker closes without traction voltage and holds without it, and the // pantographs rise and stay up only while it's closed (EU05, EP05, ČD 181 family); off, the pantographs come first and the line - // breaker needs their voltage + // breaker needs their voltage. what the main circuit feeds still needs the voltage (MainCircuitPowered()), and without + // it the undervoltage relay opens the line contactors (NoVoltRelay) bool PantographsRequireMains{false}; bool LineBreakerClosesOnlyAtNoPowerPos{false}; bool ControlPressureSwitch{false}; // activates if the main pipe and/or brake cylinder pressure aren't within operational levels @@ -2232,7 +2233,9 @@ class TMoverParameters double PantPress = 0.0; /*Cisnienie w zbiornikach pantografow*/ bool PantPressSwitchActive{false}; // state of the pantograph pressure switch. gets primed at defined pressure level in pantograph air system bool PantPressLockActive{false}; // pwr system state flag. fires when pressure switch activates by pantograph pressure dropping below defined level - bool NoVoltRelay{true}; // switches off if the power level drops below threshold + // switches off if the power level drops below threshold, which opens the line breaker; with PantographsRequireMains + // it opens the line contactors instead, and switches back on only with the master controller at zero or the first position + bool NoVoltRelay{true}; bool OvervoltageRelay{true}; // switches off if the power level goes above threshold bool s_CAtestebrake = false; // hunter-091012: zmienna dla testu ca std::array, 4> PowerCircuits; // 24v, 110v, 3x400v and 3000v power circuits, voltage from local sources and current draw pairs @@ -2661,6 +2664,11 @@ class TMoverParameters bool HeatingSwitch(bool const State, range_t const Notify = range_t::consist); void HeatingSwitch_(bool const State); double EnginePowerSourceVoltage() const; // returns voltage of defined main engine power source + // whether the main circuit feeds what runs on it (the converter, a compressor, the heating, the motor and resistor + // blowers, the traction motors): the line breaker closed, and where it closes ahead of the pantographs and holds + // without traction voltage (PantographsRequireMains) also the voltage there, at least the one the undervoltage + // trip takes. everywhere else it's the same as Mains + bool MainCircuitPowered() const; /*-funkcje typowe dla lokomotywy elektrycznej*/ void LowVoltagePowerCheck(double const Deltatime); diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 0d5561b06..f7ed6457d 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -438,7 +438,7 @@ double TMoverParameters::Current(double n, double U) // writepaslog("Delta ", FloatToStr(Delta)); // writepaslog("DeltaQ ", FloatToStr(DeltaQ)); // writepaslog("U ", FloatToStr(U)); - if (Mains) + if (MainCircuitPowered()) { if (U > 0) MotorCurrent = (U1 - Isf * Rz - Mn * motor_param(SP).fi * n + std::sqrt(Delta)) / (2.0 * Rz); @@ -1952,7 +1952,7 @@ void TMoverParameters::PowerCouplersCheck(double const /*Deltatime*/, coupling c case TPowerSource::Main: { // HACK: main circuit can be fed through couplers, so we explicitly check pantograph supply here - localvoltage = true == Mains ? PantographVoltage : 0.0; + localvoltage = MainCircuitPowered() ? PantographVoltage : 0.0; break; } default: @@ -2209,7 +2209,7 @@ void TMoverParameters::ConverterCheck(double const Timestep) if (ConverterAllow && ConverterAllowLocal && false == ConvOvldFlag && false == PantPressLockActive // HACK: allow carriages to operate converter without (missing) fuse prerequisite - && (Power > 1.0 ? Mains : GetTrainsetHighVoltage() > 0.0)) + && (Power > 1.0 ? MainCircuitPowered() : GetTrainsetHighVoltage() > 0.0)) { // delay timer can be optionally configured, and is set anew whenever converter goes off if (ConverterStartDelayTimer <= 0.0) @@ -2295,7 +2295,7 @@ void TMoverParameters::HeatingCheck(double const /*Timestep*/) } case TPowerSource::Main: { - voltage = true == Mains ? std::max(GetTrainsetHighVoltage(), PantographVoltage) : 0.0; + voltage = MainCircuitPowered() ? std::max(GetTrainsetHighVoltage(), PantographVoltage) : 0.0; break; } default: @@ -2406,7 +2406,7 @@ void TMoverParameters::MotorBlowersCheck(double const Timestep) // TODO: bind properly power source when ld is in place (blower.start_type == start_t::battery ? Power24vIsAvailable : blower.start_type == start_t::converter ? Power110vIsAvailable : - Mains) // power source + MainCircuitPowered()) // power source // breaker condition disabled until it's implemented in the class data // && ( true == blower.breaker ) && false == disable && @@ -3980,6 +3980,25 @@ double TMoverParameters::EnginePowerSourceVoltage() const 0.0; } +// whether the main circuit feeds what runs on it: the converter, a compressor, the heating, the motor and resistor +// blowers, the traction motors +bool TMoverParameters::MainCircuitPowered() const +{ + if (false == Mains) + { + return false; + } + if (false == PantographsRequireMains || EnginePowerSource.SourceType != TPowerSource::CurrentCollector) + { + // the closed line breaker says it all: the undervoltage trip opens it without traction voltage, and an engine + // which runs is its own supply + return true; + } + // closed ahead of the pantographs the line breaker holds without the voltage, which the undervoltage trip isn't + // there to vouch for + return EnginePowerSourceVoltage() >= EnginePowerSource.CollectorParameters.MinV; +} + // ************************************************************************************************* // Q: 20160711 // zwiększenie nastawy hamulca @@ -4573,7 +4592,7 @@ void TMoverParameters::CompressorCheck(double dt) } // the main circuit, also for a compressor driven by the engine, otherwise the low voltage - auto const compressorpower{CompressorPower == 0 || CompressorPower == 3 ? Mains : Power110vIsAvailable}; + auto const compressorpower{CompressorPower == 0 || CompressorPower == 3 ? MainCircuitPowered() : Power110vIsAvailable}; CompressorPowerTime = compressorpower ? CompressorPowerTime + dt : 0.0; auto const compressorready{compressorpower && CompressorPowerTime >= CompressorStartDelay}; // TBD: split CompressorAllow into separate enable/disable flags, inherit compressor from basic_device @@ -5910,7 +5929,7 @@ double TMoverParameters::TractionForce(double dt) case TEngineType::ElectricSeriesMotor: { - if (true == Mains) + if (MainCircuitPowered()) { switch (RVentType) { @@ -6042,7 +6061,13 @@ double TMoverParameters::TractionForce(double dt) { // update the state of voltage relays auto const voltage{std::max(GetTrainsetHighVoltage(), PantographVoltage)}; - NoVoltRelay = EnginePowerSource.SourceType != TPowerSource::CurrentCollector || voltage >= EnginePowerSource.CollectorParameters.MinV; + // where the line breaker holds without voltage (closed ahead of the pantographs) the undervoltage relay opens the + // line contactors instead, see MotorConnectorsCheck(). it picks up again only with the master controller back + // where a start begins, as the line breaker it stands in for wouldn't close on a running position either: at + // zero, or at the first position, which is the first resistance step, where the line contactors close on any + // start, and where the AI waits for them rather than going back to zero + auto const novoltrelaypicksup{false == PantographsRequireMains || NoVoltRelay || MainCtrlPowerPos() <= 1}; + NoVoltRelay = EnginePowerSource.SourceType != TPowerSource::CurrentCollector || (voltage >= EnginePowerSource.CollectorParameters.MinV && novoltrelaypicksup); OvervoltageRelay = EnginePowerSource.SourceType != TPowerSource::CurrentCollector || voltage <= EnginePowerSource.CollectorParameters.MaxV || false == EnginePowerSource.CollectorParameters.OVP; // wywalanie szybkiego z powodu niewłaściwego napięcia @@ -6578,7 +6603,7 @@ double TMoverParameters::TractionForce(double dt) case TEngineType::ElectricInductionMotor: { - if (true == Mains && !SecuritySystem.is_engine_blocked()) + if (MainCircuitPowered() && !SecuritySystem.is_engine_blocked()) { double ActiveInverters = 0.0; for (auto const &inv : Inverters) @@ -7496,7 +7521,11 @@ bool TMoverParameters::MotorConnectorsCheck() return false; } - auto const connectorsoff{false == Mains || true == FuseFlag || true == StLinSwitchOff || DirActive == 0}; + // a line breaker closed ahead of the pantographs holds without voltage; what cuts the motors off there is its + // undervoltage relay, which elsewhere opens the line breaker + auto const undervoltage{PantographsRequireMains && false == NoVoltRelay}; + + auto const connectorsoff{false == Mains || undervoltage || true == FuseFlag || true == StLinSwitchOff || DirActive == 0}; return false == connectorsoff; } @@ -7871,7 +7900,7 @@ void TMoverParameters::CheckEIMIC(double dt) eimic = 0; } - auto const eimicpowerenabled{(true == Mains || Power == 0.0) && (!SpringBrake.IsActive || !SpringBrakeCutsOffDrive) && !LockPipe && DirAbsolute != 0}; + auto const eimicpowerenabled{(MainCircuitPowered() || Power == 0.0) && (!SpringBrake.IsActive || !SpringBrakeCutsOffDrive) && !LockPipe && DirAbsolute != 0}; auto const eimicdoorenabled{(SpringBrake.IsActive && ReleaseParkingBySpringBrakeWhenDoorIsOpen)}; double eimic_max = 0.0; if (Doors.instances[side::left].open_permit == false && Doors.instances[side::right].open_permit == false) diff --git a/tests/unit/test_mains_before_pantographs.cpp b/tests/unit/test_mains_before_pantographs.cpp index 01f6e1197..e9c70bb4c 100644 --- a/tests/unit/test_mains_before_pantographs.cpp +++ b/tests/unit/test_mains_before_pantographs.cpp @@ -4,11 +4,16 @@ // the order of the line breaker and the pantographs (eu07/maszyna#68): on Polish locomotives the pantographs // come first and the line breaker closes on their voltage; on Czech ones (Cntrl.PantRequiresMain) the line -// breaker closes first, without voltage, and the pantographs rise and stay up only while it's closed +// breaker closes first, without voltage, and the pantographs rise and stay up only while it's closed. what the +// main circuit feeds still needs the voltage there: the converter and the rest don't run behind a line breaker +// closed on the battery alone, and the traction motors get cut off when the voltage goes namespace { constexpr test::track line{0.15, 0.0, test::catenary_3kv}; +// a catenary without voltage, and one below the voltage the locomotive works on (Power: MinV, 1900 V) +constexpr test::track dead{0.15, 0.0, 0.0}; +constexpr test::track weak{0.15, 0.0, 1000.0}; test::definition ep05(bool const Mainsfirst) { auto definition{test::definition::fiz("ep05_v2/ep05")}; @@ -32,10 +37,10 @@ void prepare(test::vehicle &Loco) { Loco.run(2.0, line); } -void raise_pantograph(test::vehicle &Loco) { +void raise_pantograph(test::vehicle &Loco, test::track const &Track = line) { Loco->OperatePantographsValve(operation_t::enable); Loco->OperatePantographValve(end::rear, operation_t::enable); - Loco.run(5.0, line); + Loco.run(5.0, Track); } void close_line_breaker(test::vehicle &Loco) { @@ -43,6 +48,42 @@ void close_line_breaker(test::vehicle &Loco) { Loco.run(2.0, line); } +// the converter and the compressor switched on, the main reservoir left to the compressor from now on +void switch_auxiliaries_on(test::vehicle &Loco) { + Loco->ConverterSwitch(true); + Loco->CompressorSwitch(true); + Loco.hold_main_reservoir(-1.0); +} + +// what the main reservoir gains over the given time [bar]; the compressor of the locomotive adds some 0.07 bar a second +double reservoir_gain(test::vehicle &Loco, double const Seconds, test::track const &Track) { + auto const before{Loco->CompressedVolume}; + Loco.run(Seconds, Track); + return (Loco->CompressedVolume - before) / Loco->VeselVolume; +} + +// the locomotive started up the way the driver does it, the brakes released, then the master controller taken to the +// given position a notch a second, the camshaft following it +void get_under_power(test::vehicle &Loco, test::driven const &Driven, int const Position) { + REQUIRE(test::start_up(Driven, line)); + test::release_brakes(Driven.cab); + test::drive(Driven, line, 20.0); + // until the pressure switch lets the line contactors close + for (int i = 0; i < 120 && Loco->ControlPressureSwitch; ++i) { + test::drive(Driven, line, 1.0); + } + for (int i = 0; i < Position; ++i) { + Loco->IncMainCtrl(1); + test::drive(Driven, line, 1.0); + } + test::drive(Driven, line, 2.0); + REQUIRE(Loco->MainCtrlPos == Position); + REQUIRE(Loco->MainCtrlActualPos == Position); + REQUIRE(Loco->RList[Position].R > 0.0); // a resistance position + REQUIRE(Loco->StLinFlag); + REQUIRE(std::abs(Loco->Im) > 10.0); +} + } // namespace TEST_CASE("mains before pantographs: without the flag the line breaker needs the pantographs' voltage, as before") { @@ -115,3 +156,196 @@ TEST_CASE("mains before pantographs: with the flag the driver's start-up gets th CHECK(loco->PantographVoltage == doctest::Approx(test::catenary_3kv)); CHECK(test::is_ready(driven)); } + +// the closed line breaker used to tell there's traction voltage, the undervoltage trip opening it without one. closed +// ahead of the pantographs it tells nothing of the kind, so what the main circuit feeds checks the voltage itself + +TEST_CASE("mains before pantographs: with the flag the converter and the compressor wait for the traction voltage") { + test::vehicle loco{ep05(true), 0.0, "test", 1}; + prepare(loco); + close_line_breaker(loco); + REQUIRE(loco->Mains); + REQUIRE(loco->PantographVoltage == 0.0); + switch_auxiliaries_on(loco); + REQUIRE(loco->ConverterAllow); + REQUIRE(loco->CompressorAllow); + + // the line breaker closed on the battery, the pantographs down: there's nothing to run them on + CHECK(reservoir_gain(loco, 20.0, line) < 0.01); + CHECK(loco->Mains); + CHECK_FALSE(loco->MainCircuitPowered()); + CHECK_FALSE(loco->ConverterFlag); + CHECK_FALSE(loco->Power110vIsAvailable); + CHECK_FALSE(loco->CompressorFlag); + + // the pantograph up: the converter starts, and the compressor on its 110 V + raise_pantograph(loco); + REQUIRE(loco->PantographVoltage == doctest::Approx(test::catenary_3kv)); + CHECK(reservoir_gain(loco, 10.0, line) > 0.1); + CHECK(loco->MainCircuitPowered()); + CHECK(loco->ConverterFlag); + CHECK(loco->Power110vIsAvailable); + CHECK(loco->CompressorFlag); + + // the voltage gone they stop, behind the line breaker which stays closed + auto const *track{&line}; + SUBCASE("the pantograph lowered again") { + loco->OperatePantographValve(end::rear, operation_t::disable); + loco.run(5.0, line); + REQUIRE_FALSE(loco->Pantographs[end::rear].is_active); + } + SUBCASE("no voltage in the catenary") { + track = &dead; + loco.run(5.0, dead); + REQUIRE(loco->Pantographs[end::rear].is_active); + } + SUBCASE("the voltage in the catenary below the one the locomotive works on") { + track = &weak; + loco.run(5.0, weak); + REQUIRE(loco->PantographVoltage == doctest::Approx(weak.voltage)); + } + CHECK(reservoir_gain(loco, 10.0, *track) < 0.01); + CHECK(loco->Mains); + CHECK_FALSE(loco->MainCircuitPowered()); + CHECK_FALSE(loco->ConverterFlag); + CHECK_FALSE(loco->Power110vIsAvailable); + CHECK_FALSE(loco->CompressorFlag); +} + +TEST_CASE("mains before pantographs: with the flag whatever else the main circuit feeds waits for the traction voltage too") { + // a compressor on the main circuit rather than the converter's 110 V, the motor blowers, the blowers of the starting + // resistors, the heating + test::vehicle loco{ep05(true).set("Brake", "CompressorPower", "Main"), 0.0, "test", 1}; + REQUIRE(loco->CompressorPower == 0); + REQUIRE(loco->HeatingPowerSource.SourceType == TPowerSource::Main); + prepare(loco); + close_line_breaker(loco); + REQUIRE(loco->Mains); + loco->CompressorSwitch(true); + loco->MotorBlowersSwitch(true, end::front); + loco->RVentForceOn = true; + loco->HeatingSwitch(true); + loco.hold_main_reservoir(-1.0); + + CHECK(reservoir_gain(loco, 10.0, line) < 0.01); + CHECK_FALSE(loco->CompressorFlag); + CHECK_FALSE(loco->MotorBlowers[end::front].is_active); + CHECK(loco->RventRot == 0.0); + CHECK_FALSE(loco->Heating); + + SUBCASE("nor do they run on a voltage below the one the locomotive works on") { + raise_pantograph(loco, weak); + REQUIRE(loco->PantographVoltage == doctest::Approx(weak.voltage)); + CHECK(reservoir_gain(loco, 10.0, weak) < 0.01); + CHECK(loco->Mains); + CHECK_FALSE(loco->CompressorFlag); + CHECK_FALSE(loco->MotorBlowers[end::front].is_active); + CHECK(loco->RventRot == 0.0); + CHECK_FALSE(loco->Heating); + } + SUBCASE("with the voltage they do") { + raise_pantograph(loco); + REQUIRE(loco->PantographVoltage == doctest::Approx(test::catenary_3kv)); + CHECK(reservoir_gain(loco, 10.0, line) > 0.1); + CHECK(loco->CompressorFlag); + CHECK(loco->MotorBlowers[end::front].is_active); + CHECK(loco->RventRot > 0.0); + CHECK(loco->Heating); + } +} + +TEST_CASE("mains before pantographs: without the flag the converter and the compressor run behind the closed line breaker, as before") { + test::vehicle loco{ep05(false), 0.0, "test", 1}; + prepare(loco); + raise_pantograph(loco); + close_line_breaker(loco); + REQUIRE(loco->Mains); + switch_auxiliaries_on(loco); + CHECK(reservoir_gain(loco, 10.0, line) > 0.1); + CHECK(loco->MainCircuitPowered()); + CHECK(loco->ConverterFlag); + CHECK(loco->Power110vIsAvailable); + CHECK(loco->CompressorFlag); + // too low a voltage opens the line breaker, and they stop with it + loco.run(5.0, weak); + CHECK_FALSE(loco->Mains); + CHECK_FALSE(loco->MainCircuitPowered()); + CHECK_FALSE(loco->ConverterFlag); + CHECK_FALSE(loco->Power110vIsAvailable); + CHECK_FALSE(loco->CompressorFlag); +} + +// the undervoltage trip was also what cut the traction motors off when the voltage went: the line contactors open +// with the line breaker, which then doesn't close on a running position. where the line breaker holds without +// voltage, its undervoltage relay opens the line contactors itself, until the master controller is back where a +// start begins + +TEST_CASE("mains before pantographs: with the flag the line contactors open when the traction voltage goes, and the start begins anew") { + test::vehicle loco{ep05(true), 0.0, "test", 1}; + auto driven{test::driving(loco)}; + get_under_power(loco, driven, 5); + + // the voltage goes: the line breaker holds, the pantograph stays up, the motors are cut off + test::drive(driven, dead, 3.0); + CHECK(loco->Mains); + CHECK(loco->Pantographs[end::rear].is_active); + CHECK_FALSE(loco->NoVoltRelay); + CHECK_FALSE(loco->StLinFlag); + CHECK(loco->Im == 0.0); + + // the voltage back, with the master controller still where it was: the camshaft went down to zero and stays + // there, the motors still cut off; the converter is back on its own + test::drive(driven, line, 10.0); + REQUIRE(loco->PantographVoltage == doctest::Approx(test::catenary_3kv)); + REQUIRE(loco->MainCtrlPos == 5); + CHECK(loco->Mains); + CHECK(loco->ConverterFlag); + CHECK_FALSE(loco->NoVoltRelay); + CHECK_FALSE(loco->StLinFlag); + CHECK(loco->MainCtrlActualPos == 0); + CHECK(loco->Im == 0.0); + + SUBCASE("the master controller back at zero: the start goes as usual") { + while (loco->MainCtrlPos > 0 && loco->DecMainCtrl(1)) { + // down to zero + } + REQUIRE(loco->MainCtrlPos == 0); + test::drive(driven, line, 1.0); + CHECK(loco->NoVoltRelay); + CHECK_FALSE(loco->StLinFlag); + for (int i = 0; i < 3; ++i) { + loco->IncMainCtrl(1); + test::drive(driven, line, 2.0); + } + CHECK(loco->StLinFlag); + CHECK(loco->MainCtrlActualPos == 3); + CHECK(std::abs(loco->Im) > 10.0); + } + SUBCASE("the master controller back at the first position, where the line contactors close on a start") { + while (loco->MainCtrlPos > 1 && loco->DecMainCtrl(1)) { + // down to the first position + } + REQUIRE(loco->MainCtrlPos == 1); + test::drive(driven, line, 2.0); + CHECK(loco->NoVoltRelay); + CHECK(loco->StLinFlag); + CHECK(loco->MainCtrlActualPos == 1); + } +} + +TEST_CASE("mains before pantographs: without the flag the line breaker opens when the traction voltage goes, as before") { + test::vehicle loco{ep05(false), 0.0, "test", 1}; + auto driven{test::driving(loco)}; + get_under_power(loco, driven, 5); + + test::drive(driven, dead, 3.0); + CHECK_FALSE(loco->Mains); + CHECK_FALSE(loco->StLinFlag); + CHECK(loco->Im == 0.0); + // and stays open with the voltage back + test::drive(driven, line, 10.0); + CHECK_FALSE(loco->Mains); + CHECK_FALSE(loco->StLinFlag); + CHECK(loco->MainCtrlActualPos == 0); + CHECK(loco->Im == 0.0); +}