diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index d96e0d10c..21c9ba7e4 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -2373,6 +2373,11 @@ class TMoverParameters int EIMCtrlEmergencyPositions() const; // whether the master controller is in its emergency brake position (EIMCtrlType 2 with EIMCtrlMainEmergency) bool IsMainCtrlEmergencyPos() const; + // the master controller position sent to the coupled vehicles ("MainCtrl"), the same with and without + // EIMCtrlMainEmergency: the Elf's positions without the emergency brake one, which goes as the full braking + int MainCtrlPosForCoupled() const; + // the master controller position of this vehicle for one received from a coupled vehicle ("MainCtrl") + int MainCtrlPosFromCoupled(int Position) const; /*! pomocniczy nastawnik:*/ bool IncScndCtrl(int CtrlSpeed); bool DecScndCtrl(int CtrlSpeed); diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 3499e16b3..cd4573ca0 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -2537,7 +2537,7 @@ bool TMoverParameters::IncMainCtrl(int CtrlSpeed) if (true == OK) { - SendCtrlToNext("MainCtrl", MainCtrlPos, CabActive); //??? + SendCtrlToNext("MainCtrl", MainCtrlPosForCoupled(), CabActive); //??? SendCtrlToNext("ScndCtrl", ScndCtrlPos, CabActive); } @@ -2662,7 +2662,7 @@ bool TMoverParameters::DecMainCtrl(int CtrlSpeed) if (OK) { - /*OK:=*/SendCtrlToNext("MainCtrl", MainCtrlPos, CabActive); // hmmmm...???!!! + /*OK:=*/SendCtrlToNext("MainCtrl", MainCtrlPosForCoupled(), CabActive); // hmmmm...???!!! /*OK:=*/SendCtrlToNext("ScndCtrl", ScndCtrlPos, CabActive); } } @@ -2745,6 +2745,17 @@ bool TMoverParameters::IsMainCtrlEmergencyPos() const return MainCtrlPos < EIMCtrlEmergencyPositions(); } +int TMoverParameters::MainCtrlPosForCoupled() const +{ + // the emergency brake itself reaches the train through the brake pipe, vented by the vehicle driven from + return std::max(0, MainCtrlPos - EIMCtrlEmergencyPositions()); +} + +int TMoverParameters::MainCtrlPosFromCoupled(int const Position) const +{ + return Position + EIMCtrlEmergencyPositions(); +} + // ************************************************************************************************* // Q: 20160710 // zwiększenie bocznika @@ -2786,7 +2797,7 @@ bool TMoverParameters::IncScndCtrl(int CtrlSpeed) OK = false; if (OK) { - /*OK:=*/SendCtrlToNext("MainCtrl", MainCtrlPos, CabActive); //??? + /*OK:=*/SendCtrlToNext("MainCtrl", MainCtrlPosForCoupled(), CabActive); //??? /*OK:=*/SendCtrlToNext("ScndCtrl", ScndCtrlPos, CabActive); } } @@ -2848,7 +2859,7 @@ bool TMoverParameters::DecScndCtrl(int CtrlSpeed) OK = false; if (OK) { - /*OK:=*/SendCtrlToNext("MainCtrl", MainCtrlPos, CabActive); //??? + /*OK:=*/SendCtrlToNext("MainCtrl", MainCtrlPosForCoupled(), CabActive); //??? /*OK:=*/SendCtrlToNext("ScndCtrl", ScndCtrlPos, CabActive); } } @@ -4586,8 +4597,9 @@ void TMoverParameters::UpdatePipePressure(double dt) // EngDmgFlag 32 (load destroyed) used to trigger this too; dropped, it has nothing to do with - // the emergency brake (a broken coupler sets AlarmChainFlag instead) - if (RadioStopFlag || AlarmChainFlag || (EIMCtrlEmergency && LocalBrakePosA >= 1.0) || IsMainCtrlEmergencyPos() || SecuritySystem.is_braking() || + // the emergency brake (a broken coupler sets AlarmChainFlag instead). the Elf's emergency brake position + // vents the pipe only from the vehicle driven from, whatever the controllers of the others show + if (RadioStopFlag || AlarmChainFlag || (EIMCtrlEmergency && LocalBrakePosA >= 1.0) || (IsMainCtrlEmergencyPos() && IsCabMaster()) || SecuritySystem.is_braking() || (SpringBrakeDriveEmergencyVel >= 0 && Vel > SpringBrakeDriveEmergencyVel && SpringBrake.IsActive) || (0 == CabActive && (InactiveCabFlag & activation::emergencybrake) != 0)) { @@ -10915,8 +10927,10 @@ void TMoverParameters::LoadFIZ_Cntrl(std::string const &line) extract_value(EIMCtrlMainEmergency, "EIMCtrlMainEmergency", line, ""); if (auto const elfpositions{4 + EIMCtrlEmergencyPositions()}; EIMCtrlEmergencyPositions() > 0 && MainCtrlPosNo < elfpositions) { - // without it the controller would have no power position - ErrorLog(std::format("Bad fiz: EIMCtrlMainEmergency needs MCPN={} in {}", elfpositions, TypeName)); + // the old positions in the file: without the fix-up the controller would have no power position, and the + // reverser would stop working at neutral (DirChangeMaxPos read before, in the old positions) + MainCtrlMaxDirChangePos += EIMCtrlEmergencyPositions(); + ErrorLog(std::format("Bad fiz: EIMCtrlMainEmergency needs MCPN={} in {}, DirChangeMaxPos taken as {}", elfpositions, TypeName, MainCtrlMaxDirChangePos)); MainCtrlPosNo = elfpositions; } @@ -12256,9 +12270,10 @@ bool TMoverParameters::RunCommand(std::string const &Command, double CValue1, do if (Command == "MainCtrl") { - if (MainCtrlPosNo >= floor(CValue1)) + // sent as MainCtrlPosForCoupled(), passed on unchanged + if (auto const position{MainCtrlPosFromCoupled(static_cast(floor(CValue1)))}; MainCtrlPosNo >= position) { - MainCtrlPos = static_cast(floor(CValue1)); + MainCtrlPos = position; if (DelayCtrlFlag) { if (LastRelayTime >= InitialCtrlDelay && MainCtrlPos == 1) diff --git a/tests/unit/test_elf_controller.cpp b/tests/unit/test_elf_controller.cpp index 747a57630..212ed51d0 100644 --- a/tests/unit/test_elf_controller.cpp +++ b/tests/unit/test_elf_controller.cpp @@ -5,6 +5,9 @@ #include "McZapkie/hamulce.h" +#include +#include + // the master controller of the Elf (EIMCtrlType 2): its positions, and the emergency brake position below // them which EIMCtrlMainEmergency adds (eu07/maszyna#413) @@ -13,16 +16,32 @@ using test::vehicle; namespace { -// a three-car Elf ready to run, standing with its brakes released and the driver in the front cab of the -// head car, which also drives (the controller's eimic is worked out there) +// the data of an Elf: without the emergency brake position as now, with it in the files updated for it +// (EIMCtrlMainEmergency, MCPN=5, DirChangeMaxPos=4), or with the key alone added to the old files, which the +// loader fixes up +enum class data { plain, emergency, emergency_old_layout }; + +// three-car Elfs coupled into one train, of the given data each, ready to run, standing with their brakes +// released and the driver in the front cab of the head car of the first one, which also drives (the +// controller's eimic is worked out there) struct elf { - explicit elf(bool Emergency) { - for (auto const *car : {"elf_v1/21we-a", "elf_v1/21we-b", "elf_v1/21we-c"}) { - auto cardefinition{definition::fiz(car)}; - if (Emergency) { - cardefinition.set("Cntrl", "EIMCtrlMainEmergency", "Yes").set("Cntrl", "MCPN", 5); + explicit elf(bool Emergency) : elf({Emergency ? data::emergency : data::plain}) {} + explicit elf(std::initializer_list Units) { + for (auto const units : Units) { + for (auto const *car : {"elf_v1/21we-a", "elf_v1/21we-b", "elf_v1/21we-c"}) { + auto cardefinition{definition::fiz(car)}; + if (units != data::plain) { + cardefinition.set("Cntrl", "EIMCtrlMainEmergency", "Yes"); + } + if (units == data::emergency) { + cardefinition.set("Cntrl", "MCPN", 5); + if (std::string{car} != "elf_v1/21we-b") { + // the cars with a cab have it, at neutral: 3 before, one up with the key + cardefinition.set("Cntrl", "DirChangeMaxPos", 4); + } + } + unit.add(cardefinition, unit.size() == 0 ? 1 : 0); } - unit.add(cardefinition, unit.size() == 0 ? 1 : 0); } ready = test::start_up(test::driving(unit), line); // the start-up of the tests leaves the controller at its position 0 (close_line_breaker() in drive.cpp), @@ -48,6 +67,14 @@ struct elf { wait(30.0); } TMoverParameters &cab() { return unit[0].mover(); } + TMoverParameters &car(std::size_t Index) { return unit[Index].mover(); } + // the driver moves the controller notch by notch, which the cab sends on to the coupled vehicles + void set_controller(int Position) { + while (cab().MainCtrlPos < Position && cab().IncMainCtrl(1)) { + } + while (cab().MainCtrlPos > Position && cab().DecMainCtrl(1)) { + } + } void wait(double Seconds) { test::drive(test::driving(unit), line, Seconds); } test::consist unit; test::track line{0.15, 0.0, test::catenary_3kv}; @@ -124,6 +151,99 @@ TEST_CASE("elf controller: EIMCtrlMainEmergency with the old MCPN gets its posit vehicle car{definition::fiz("elf_v1/21we-a").set("Cntrl", "EIMCtrlMainEmergency", "Yes")}; CHECK(car->MainCtrlPosNo == 5); CHECK(car->MainCtrlNoPowerPos() == 4); + // DirChangeMaxPos=3 of the file, the old neutral, moves up with the positions + CHECK(car->MainCtrlMaxDirChangePos == 4); +} + +TEST_CASE("elf controller: EIMCtrlMainEmergency leaves DirChangeMaxPos of the files updated for it alone") { + vehicle car{definition::fiz("elf_v1/21we-a").set("Cntrl", "EIMCtrlMainEmergency", "Yes").set("Cntrl", "MCPN", 5).set("Cntrl", "DirChangeMaxPos", 4)}; + CHECK(car->MainCtrlPosNo == 5); + CHECK(car->MainCtrlMaxDirChangePos == 4); +} + +TEST_CASE("elf controller: the reverser works at the neutral shifted by EIMCtrlMainEmergency") { + // the key added to the old files, DirChangeMaxPos=3 in them + elf unit{{data::emergency_old_layout}}; + REQUIRE(unit.ready); + auto &mover{unit.cab()}; + REQUIRE(mover.MainCtrlPos == mover.MainCtrlNoPowerPos()); + REQUIRE(mover.DirActive == 1); + CHECK(mover.DirectionBackward()); + CHECK(mover.DirActive == 0); + CHECK(mover.DirectionForward()); + CHECK(mover.DirActive == 1); + // not in the power position + unit.set_controller(mover.MainCtrlNoPowerPos() + 1); + REQUIRE(mover.MainCtrlPos == 5); + CHECK_FALSE(mover.DirectionBackward()); + CHECK(mover.DirActive == 1); +} + +TEST_CASE("elf controller: the emergency brake position vents the pipe only from the vehicle driven from") { + elf unit{true}; + REQUIRE(unit.ready); + REQUIRE(unit.charged); + // the rear car, with its own cab, has its controller in the emergency brake position, the driven one not + auto &rear{unit.car(2)}; + rear.MainCtrlPos = 0; + CHECK(rear.IsMainCtrlEmergencyPos()); + CHECK_FALSE(rear.IsCabMaster()); + unit.wait(10.0); + CHECK(unit.cab().PipePress > 4.5); + CHECK(rear.PipePress > 4.5); +} + +TEST_CASE("elf controller: an Elf with the emergency brake position leading one without it") { + elf unit{{data::emergency, data::plain}}; + REQUIRE(unit.ready); + REQUIRE(unit.charged); + auto &lead{unit.cab()}; + auto &other{unit.car(3)}; + REQUIRE_FALSE(other.EIMCtrlMainEmergency); + // neutral of the lead is neutral of the other + CHECK(lead.MainCtrlPos == 4); + CHECK(other.MainCtrlPos == other.MainCtrlNoPowerPos()); + SUBCASE("power") { + unit.set_controller(5); + CHECK(other.MainCtrlPos == 4); + } + SUBCASE("full braking") { + unit.set_controller(1); + CHECK(other.MainCtrlPos == 0); + unit.wait(10.0); + CHECK(lead.PipePress > 4.5); + } + SUBCASE("the emergency brake: the other one at its full braking, the pipe vented by the lead") { + unit.set_controller(0); + REQUIRE(lead.IsMainCtrlEmergencyPos()); + CHECK(other.MainCtrlPos == 0); + unit.wait(10.0); + CHECK(lead.PipePress < 0.5); + CHECK(other.PipePress < 0.5); + } +} + +TEST_CASE("elf controller: an Elf without the emergency brake position leading one with it") { + elf unit{{data::plain, data::emergency}}; + REQUIRE(unit.ready); + REQUIRE(unit.charged); + auto &lead{unit.cab()}; + auto &other{unit.car(3)}; + REQUIRE(other.EIMCtrlMainEmergency); + CHECK(lead.MainCtrlPos == 3); + CHECK(other.MainCtrlPos == other.MainCtrlNoPowerPos()); + SUBCASE("power") { + unit.set_controller(4); + CHECK(other.MainCtrlPos == 5); + } + SUBCASE("the full braking of the lead is the full braking of the other, not its emergency brake") { + unit.set_controller(0); + CHECK(other.MainCtrlPos == 1); + CHECK_FALSE(other.IsMainCtrlEmergencyPos()); + unit.wait(10.0); + CHECK(lead.PipePress > 4.5); + CHECK(other.PipePress > 4.5); + } } TEST_CASE("elf controller: EIMCtrlMainEmergency leaves the other controllers alone") {