diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 199c65a0c..d96e0d10c 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -2205,6 +2205,7 @@ class TMoverParameters int SpeedCtrlAutoTurnOffFlag = 0; /*czy tempomat sam się wyłącza*/ bool EIMCtrlAdditionalZeros = false; /*czy ma dodatkowe zero jazdy i zero hamowania */ bool EIMCtrlEmergency = false; /*czy ma dodatkowe zero jazdy i zero hamowania */ + bool EIMCtrlMainEmergency = false; /*czy zadajnik typu 2 (Elf) ma pozycje hamowania naglego ponizej swojej pozycji 0*/ double eimv_pr = 0; /*realizowany procent dostepnej sily rozruchu/hamowania*/ double eimv[21]; static std::vector const eimv_labels; @@ -2368,6 +2369,10 @@ class TMoverParameters int MainCtrlNoPowerPos() const; // highest setting of master controller which won't cause engine to generate extra power int MainCtrlActualPowerPos() const; // current actual setting of master controller, relative to the highest setting not generating extra power int MainCtrlPowerPos() const; // current setting of master controller, relative to the highest setting not generating extra power + // positions the master controller of the EIMCtrlType 2 (Elf) has below its own position 0, the emergency brake (0 or 1) + int EIMCtrlEmergencyPositions() const; + // whether the master controller is in its emergency brake position (EIMCtrlType 2 with EIMCtrlMainEmergency) + bool IsMainCtrlEmergencyPos() const; /*! pomocniczy nastawnik:*/ bool IncScndCtrl(int CtrlSpeed); bool DecScndCtrl(int CtrlSpeed); diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 330e8eb8f..3499e16b3 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -2710,7 +2710,7 @@ int TMoverParameters::MainCtrlNoPowerPos() const } case 2: { - return 3; + return 3 + EIMCtrlEmergencyPositions(); } case 3: { @@ -2735,6 +2735,16 @@ int TMoverParameters::MainCtrlPowerPos() const return MainCtrlPos - MainCtrlNoPowerPos(); } +int TMoverParameters::EIMCtrlEmergencyPositions() const +{ + return (EIMCtrlType == 2 && EIMCtrlMainEmergency) ? 1 : 0; +} + +bool TMoverParameters::IsMainCtrlEmergencyPos() const +{ + return MainCtrlPos < EIMCtrlEmergencyPositions(); +} + // ************************************************************************************************* // Q: 20160710 // zwiększenie bocznika @@ -4577,7 +4587,7 @@ 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) || SecuritySystem.is_braking() || + if (RadioStopFlag || AlarmChainFlag || (EIMCtrlEmergency && LocalBrakePosA >= 1.0) || IsMainCtrlEmergencyPos() || SecuritySystem.is_braking() || (SpringBrakeDriveEmergencyVel >= 0 && Vel > SpringBrakeDriveEmergencyVel && SpringBrake.IsActive) || (0 == CabActive && (InactiveCabFlag & activation::emergencybrake) != 0)) { @@ -7357,10 +7367,16 @@ void TMoverParameters::CheckEIMIC(double dt) eimic = 0; break; case 2: - if (MainCtrlActualPos != MainCtrlPos || LastRelayTime > InitialCtrlDelay) + if (IsMainCtrlEmergencyPos()) + { + // hamowanie nagle: pelne hamowanie od razu, przewod glowny oproznia UpdatePipePressure() + eimic = -1.0; + } + else if (MainCtrlActualPos != MainCtrlPos || LastRelayTime > InitialCtrlDelay) { double delta = MainCtrlActualPos == MainCtrlPos ? dt * CtrlDelay : 0.01; - switch (MainCtrlPos) + // the positions below are those of the controller without the emergency brake position + switch (MainCtrlPos - EIMCtrlEmergencyPositions()) { case 0: case 1: @@ -10895,6 +10911,14 @@ void TMoverParameters::LoadFIZ_Cntrl(std::string const &line) extract_value(LocHandleTimeTraxx, "LocalBrakeTraxx", line, ""); extract_value(EIMCtrlAdditionalZeros, "EIMCtrlAddZeros", line, ""); extract_value(EIMCtrlEmergency, "EIMCtrlEmergency", line, ""); + // Elf (EIMCtrlType 2): an emergency brake position below the controller's position 0, which shifts the other positions up by one + 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)); + MainCtrlPosNo = elfpositions; + } extract_value(ScndS, "ScndS", line, ""); // brak pozycji rownoleglej przy niskiej nastawie PSR diff --git a/tests/unit/test_elf_controller.cpp b/tests/unit/test_elf_controller.cpp new file mode 100644 index 000000000..747a57630 --- /dev/null +++ b/tests/unit/test_elf_controller.cpp @@ -0,0 +1,136 @@ +#include "stdafx.h" +#include "doctest.h" +#include "consist.h" +#include "drive.h" + +#include "McZapkie/hamulce.h" + +// the master controller of the Elf (EIMCtrlType 2): its positions, and the emergency brake position below +// them which EIMCtrlMainEmergency adds (eu07/maszyna#413) + +using test::definition; +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) +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); + } + 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), + // the emergency brake one with EIMCtrlMainEmergency; the driver sets it to neutral, as the AI does. a unit + // moves its controller only with a direction set + for (int i = 0; i < 3 && cab().DirActive <= 0; ++i) { + cab().DirectionForward(); + } + while (cab().MainCtrlPos < cab().MainCtrlNoPowerPos() && cab().IncMainCtrl(1)) { + // up to neutral + } + test::release_brakes(cab()); + recharge(); + charged = cab().PipePress > 4.5; + } + // the pipe charged again after an emergency stop: the Elf locks its emptied pipe off the brake handle (LPOn, + // LPOff) until the unlock button (UBB1, the first universal brake button) is held, the handle at running + void recharge() { + cab().BrakeLevelSet(cab().Handle->GetPos(bh_RP)); + cab().UniversalBrakeButton(0, 1); + wait(30.0); + cab().UniversalBrakeButton(0, 0); + wait(30.0); + } + TMoverParameters &cab() { return unit[0].mover(); } + void wait(double Seconds) { test::drive(test::driving(unit), line, Seconds); } + test::consist unit; + test::track line{0.15, 0.0, test::catenary_3kv}; + bool ready{false}; + bool charged{false}; +}; + +} // namespace + +TEST_CASE("elf controller: without EIMCtrlMainEmergency the positions stay as they were") { + elf unit{false}; + REQUIRE(unit.ready); + REQUIRE(unit.charged); + auto &mover{unit.cab()}; + CHECK_FALSE(mover.EIMCtrlMainEmergency); + CHECK(mover.EIMCtrlEmergencyPositions() == 0); + CHECK(mover.MainCtrlPosNo == 4); + CHECK(mover.MainCtrlNoPowerPos() == 3); + CHECK(mover.MainCtrlPos == 3); + // the lowest position brakes fully, without emptying the pipe + mover.MainCtrlPos = 0; + CHECK_FALSE(mover.IsMainCtrlEmergencyPos()); + unit.wait(10.0); + CHECK(mover.eimic == doctest::Approx(-1.0)); + CHECK(mover.PipePress > 4.5); +} + +TEST_CASE("elf controller: EIMCtrlMainEmergency shifts the positions up by the emergency brake one") { + elf unit{true}; + REQUIRE(unit.ready); + REQUIRE(unit.charged); + auto &mover{unit.cab()}; + CHECK(mover.EIMCtrlMainEmergency); + CHECK(mover.EIMCtrlEmergencyPositions() == 1); + CHECK(mover.MainCtrlPosNo == 5); + CHECK(mover.MainCtrlNoPowerPos() == 4); + CHECK(mover.MainCtrlPos == 4); + CHECK_FALSE(mover.IsMainCtrlEmergencyPos()); + SUBCASE("the neutral position neither drives nor brakes") { + unit.wait(5.0); + CHECK(mover.eimic == doctest::Approx(0.0)); + } + SUBCASE("the full braking position, formerly 0, brakes fully without emptying the pipe") { + mover.MainCtrlPos = 1; + unit.wait(10.0); + CHECK(mover.eimic == doctest::Approx(-1.0)); + CHECK(mover.PipePress > 4.5); + } + SUBCASE("the braking position, formerly 1, ramps the braking up") { + mover.MainCtrlPos = 2; + unit.wait(1.0); + CHECK(mover.eimic < 0.0); + CHECK(mover.eimic > -1.0); + CHECK(mover.PipePress > 4.5); + } + SUBCASE("the emergency brake position brakes fully at once and empties the pipe") { + mover.MainCtrlPos = 0; + CHECK(mover.IsMainCtrlEmergencyPos()); + // a single step of the physics + unit.unit.step(unit.line); + CHECK(mover.eimic == doctest::Approx(-1.0)); + unit.wait(10.0); + CHECK(mover.PipePress < 0.5); + CHECK(mover.BrakePress > 1.0); + // out of it the pipe charges again + mover.MainCtrlPos = mover.MainCtrlNoPowerPos(); + CHECK_FALSE(mover.IsMainCtrlEmergencyPos()); + unit.recharge(); + CHECK(mover.PipePress > 4.5); + } +} + +TEST_CASE("elf controller: EIMCtrlMainEmergency with the old MCPN gets its positions all the same") { + vehicle car{definition::fiz("elf_v1/21we-a").set("Cntrl", "EIMCtrlMainEmergency", "Yes")}; + CHECK(car->MainCtrlPosNo == 5); + CHECK(car->MainCtrlNoPowerPos() == 4); +} + +TEST_CASE("elf controller: EIMCtrlMainEmergency leaves the other controllers alone") { + // the Impuls (EIMCtrlType 0) has its emergency brake in the brake range of its controller (EIMCtrlEmergency) + vehicle impuls{definition::fiz("impuls_v1/31we-a_pr").set("Cntrl", "EIMCtrlMainEmergency", "Yes"), 60.0, "impuls", 1}; + CHECK(impuls->EIMCtrlEmergencyPositions() == 0); + CHECK(impuls->MainCtrlPosNo == 10); + impuls->MainCtrlPos = 0; + CHECK_FALSE(impuls->IsMainCtrlEmergencyPos()); +} diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 08f0c0d24..461c8d1af 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -3144,9 +3144,11 @@ bool TController::IncBrakeEIM() break; } case 2: { - OK = mvOccupied->MainCtrlPos > 1; + // the braking position, above the emergency brake one where the controller has it + auto const brakepos{1 + mvOccupied->EIMCtrlEmergencyPositions()}; + OK = mvOccupied->MainCtrlPos > brakepos; if( OK ) - mvOccupied->MainCtrlPos = 1; + mvOccupied->MainCtrlPos = brakepos; break; } case 3: { @@ -3300,9 +3302,10 @@ bool TController::DecBrakeEIM() break; } case 2: { - OK = mvOccupied->MainCtrlPos < 3; + auto const neutralpos{mvOccupied->MainCtrlNoPowerPos()}; + OK = mvOccupied->MainCtrlPos < neutralpos; if( OK ) - mvOccupied->MainCtrlPos = 3; + mvOccupied->MainCtrlPos = neutralpos; break; } case 3: { @@ -3663,12 +3666,14 @@ bool TController::IncSpeedEIM() { } */ break; - case 2: - OK = mvControlling->MainCtrlPos < 4; + case 2: { + auto const powerpos{4 + mvControlling->EIMCtrlEmergencyPositions()}; + OK = mvControlling->MainCtrlPos < powerpos; if( OK ) { - mvControlling->MainCtrlPos = 4; + mvControlling->MainCtrlPos = powerpos; } break; + } } return OK; } @@ -3696,9 +3701,10 @@ bool TController::DecSpeedEIM( int const Amount ) mvControlling->SpeedCtrlPowerDec(); } else { - OK = mvControlling->MainCtrlPos > 2; + auto const holdpos{2 + mvControlling->EIMCtrlEmergencyPositions()}; + OK = mvControlling->MainCtrlPos > holdpos; if( OK ) { - mvControlling->MainCtrlPos = 2; + mvControlling->MainCtrlPos = holdpos; } } break; @@ -4170,8 +4176,9 @@ void TController::CheckTimeControllers() } else if (mvOccupied->EIMCtrlType == 2) //elf { - if (mvOccupied->eimic > 0) mvOccupied->MainCtrlPos = 3; - if (mvOccupied->eimic < 0) mvOccupied->MainCtrlPos = 2; + auto const emergencypositions{mvOccupied->EIMCtrlEmergencyPositions()}; + if (mvOccupied->eimic > 0) mvOccupied->MainCtrlPos = 3 + emergencypositions; + if (mvOccupied->eimic < 0) mvOccupied->MainCtrlPos = 2 + emergencypositions; } } //4. Check Speed Control System diff --git a/vehicle/DynObj.cpp b/vehicle/DynObj.cpp index d5f60e332..46aba815f 100644 --- a/vehicle/DynObj.cpp +++ b/vehicle/DynObj.cpp @@ -3238,7 +3238,8 @@ bool TDynamicObject::Update(double dt, double dt1) auto eimic = std::min(MoverParameters->eimic, MoverParameters->eimicSpeedCtrl); MoverParameters->eimic_real = eimic; - if (MoverParameters->EIMCtrlType == 2 && MoverParameters->MainCtrlPos == 0) + // Elf: full braking at once in the lowest position, and in the emergency brake position below it + if (MoverParameters->EIMCtrlType == 2 && MoverParameters->MainCtrlPos <= MoverParameters->EIMCtrlEmergencyPositions()) eimic = -1.0; MoverParameters->SendCtrlToNext("EIMIC", std::max(0., eimic), MoverParameters->CabActive); auto LBR = std::max(-eimic, 0.);