diff --git a/CMakeLists.txt b/CMakeLists.txt index e97e41d03..f0590577f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -548,6 +548,7 @@ set(CORE_SOURCES "vehicle/blackbox.cpp" "vehicle/enginestart.cpp" "vehicle/brakesetting.cpp" +"vehicle/fieldshunting.cpp" "vehicle/handover.cpp" "vehicle/horn.cpp" "vehicle/linebreaker.cpp" diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 825137675..57ab2c038 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -16,6 +16,7 @@ http://mozilla.org/MPL/2.0/. #include "utilities/Logs.h" #include "utilities/parser.h" #include "simulation/simulation.h" +#include "vehicle/fieldshunting.h" #include #include @@ -2930,7 +2931,8 @@ bool TMoverParameters::IncScndCtrl(int CtrlSpeed) { // TBD, TODO: refactor this validation as part of relay check routine (currently in tractionforce() // TBD, TODO: diesel electric engine utilize scndctrlactualpos like the other types? - if (EngineType == TEngineType::DieselElectric && (IsMainCtrlNoPowerPos() || AutoRelayFlag || ShuntMode || false == Mains)) + if (EngineType == TEngineType::DieselElectric && + (IsMainCtrlNoPowerPos() || fieldshunting::diesel_electric(AutoRelayType, AutoRelayFlag) != fieldshunting::control::manual || ShuntMode || false == Mains)) { OK = false; } @@ -6431,13 +6433,14 @@ double TMoverParameters::TractionForce(double dt) EngineVoltage = 0; // przekazniki bocznikowania, kazdy inny dla kazdej pozycji - if (false == StLinFlag || ShuntMode) + auto const fieldshuntingcontrol{fieldshunting::diesel_electric(AutoRelayType, AutoRelayFlag)}; + if (false == StLinFlag || ShuntMode || fieldshuntingcontrol == fieldshunting::control::off) { ScndCtrlPos = 0; } else { - if (AutoRelayFlag) + if (fieldshuntingcontrol == fieldshunting::control::automatic) { auto const shuntfieldstate{ScndCtrlPos}; diff --git a/input/drivermouseinput.cpp b/input/drivermouseinput.cpp index 222c58a62..aae0888c5 100644 --- a/input/drivermouseinput.cpp +++ b/input/drivermouseinput.cpp @@ -558,6 +558,9 @@ drivermouse_input::default_bindings() { { "maxcurrent_sw:", { motoroverloadrelaythresholdtoggle, none } }, + { "autorelay_sw:", { + notchingrelaytoggle, + none } }, { "waterpumpbreaker_sw:", { waterpumpbreakertoggle, none } }, diff --git a/tests/unit/drive.cpp b/tests/unit/drive.cpp index b03eeac2d..4510203b1 100644 --- a/tests/unit/drive.cpp +++ b/tests/unit/drive.cpp @@ -137,7 +137,8 @@ void close_line_breaker(driven const &Driven) { Driven.cab.MainSwitch(true); } -// the converter, the compressor and the motor blowers, once the line breaker is closed +// the converter, the compressor and the motor blowers, once the line breaker is closed; and the switch of the +// field shunting of a diesel-electric that has one (AutoRelay=Optional) void switch_auxiliaries_on(TMoverParameters &Cab) { Cab.ConverterSwitch(true); Cab.CompressorSwitch(true); @@ -147,6 +148,9 @@ void switch_auxiliaries_on(TMoverParameters &Cab) { Cab.MotorBlowersSwitch(true, side); } } + if (Cab.EngineType == TEngineType::DieselElectric && Cab.AutoRelayType == 2) { + Cab.AutoRelaySwitch(true); + } } } // namespace diff --git a/tests/unit/test_field_shunting.cpp b/tests/unit/test_field_shunting.cpp new file mode 100644 index 000000000..7248e1cf6 --- /dev/null +++ b/tests/unit/test_field_shunting.cpp @@ -0,0 +1,63 @@ +#include "stdafx.h" +#include "doctest.h" +#include "scenario.h" + +#include "vehicle/fieldshunting.h" + +// the field shunting of the diesel-electric locomotives, set by the driver or by the shunting relays, and the switch +// of the SU45 and the SP45 that lets the relays shunt the field ("załączenie bocznikowania", eu07/maszyna#167) + +using test::definition; +using test::scenario; +using namespace test::channels; + +TEST_CASE("field shunting: who shunts the field of a diesel-electric, by AutoRelay and its switch") { + using enum fieldshunting::control; + struct setting { + int type; // AutoRelay: 0 No, 1 Yes, 2 Optional + bool flag; // the switch, AutoRelayFlag + fieldshunting::control control; + }; + for (auto const &[type, flag, control] : {setting{0, false, manual}, setting{1, true, automatic}, setting{2, true, automatic}, setting{2, false, off}, + // AutoRelaySwitch from a coupled vehicle turns the flag of every one off, as before + setting{1, false, manual}}) { + CAPTURE(type); + CAPTURE(flag); + CHECK(fieldshunting::diesel_electric(type, flag) == control); + } +} + +TEST_CASE("field shunting: the SU45 with its switch, off at full power and switched on and off on the move") { + // the SU45 (RelayType 45) given the switch (AutoRelay=Optional) its cab has, with a coach: off, the field stays + // full and the second controller can't shunt it; on, the relays shunt it as they do with AutoRelay=Yes; off + // again, the shunting drops + scenario scenario{"traction/field shunting switch/su45", motion() + traction()}; + scenario.train().add(definition::fiz("su45_v2/301d").set("Cntrl", "AutoRelay", "Optional"), 1); + scenario.add("bdhpumn_v3/bdhpumn"); + REQUIRE(scenario.start_up()); + auto &su45{scenario.driver().controlling}; + REQUIRE(su45.AutoRelayType == 2); + // the driver switches it on as the AI does, getting the locomotive ready + CHECK(su45.AutoRelayFlag); + scenario.act("field shunting off"); + CHECK(su45.AutoRelaySwitch(false)); + scenario.get_going(); + scenario.full_power(120.0); + CHECK(su45.IsMainCtrlMaxPowerPos()); + CHECK(su45.StLinFlag); + CHECK(su45.ScndCtrlPos == 0); + CHECK_FALSE(su45.IncScndCtrl(1)); + scenario.wait(1.0); + CHECK(su45.ScndCtrlPos == 0); + // over 50 km/h, where the relays of the SU45 let the third stage in + CHECK(su45.Vel > 50.0); + scenario.act("field shunting on"); + CHECK(su45.AutoRelaySwitch(true)); + scenario.wait(30.0); + CHECK(su45.ScndCtrlPos == su45.ScndCtrlPosNo); + scenario.act("field shunting off on the move"); + CHECK(su45.AutoRelaySwitch(false)); + scenario.wait(1.0); + CHECK(su45.ScndCtrlPos == 0); + scenario.check(); +} diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index eb74344bf..6555b5ab7 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -3318,6 +3318,13 @@ bool TController::PrepareEngine() cue_action( driver_hint::rearmotorblowerson ); } } + // the switch of the field shunting of a diesel-electric that has one (AutoRelay=Optional): off, the field + // stays full + if( AIControllFlag + && mvControlling->EngineType == TEngineType::DieselElectric + && mvControlling->AutoRelayType == 2 ) { + mvControlling->AutoRelaySwitch( true ); + } // sync virtual brake state with the 'real' one if( mvOccupied->BrakeHandle != TBrakeHandle::NoHandle ) { std::unordered_map const brakepositions{ diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index 50659934c..ad87dde73 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -1488,6 +1488,8 @@ void TTrain::OnCommand_notchingrelaytoggle(TTrain *Train, command_data const &Co // turn off Train->mvOccupied->AutoRelaySwitch(false); } + // visual feedback + Train->ggAutoRelayButton.UpdateValue(Train->mvOccupied->AutoRelayFlag ? 1.f : 0.f, Train->dsbSwitch); } } @@ -9822,6 +9824,8 @@ bool TTrain::Update(double const Deltatime) ggWiperSw.Update(); ggMaxCurrentCtrl.UpdateValue(true == mvControlled->ShuntModeAllow ? (true == mvControlled->ShuntMode ? 1.f : 0.f) : mvControlled->MotorOverloadRelayHighThreshold ? 1.f : 0.f); ggMaxCurrentCtrl.Update(); + ggAutoRelayButton.UpdateValue(mvOccupied->AutoRelayFlag ? 1.f : 0.f); + ggAutoRelayButton.Update(); // NBMX wrzesien 2003 - drzwi ggDoorLeftPermitButton.Update(lowvoltagepower); ggDoorRightPermitButton.Update(lowvoltagepower); @@ -11466,6 +11470,7 @@ void TTrain::clear_cab_controls() ggBrakeOperationModeCtrl.Clear(); ggWiperSw.Clear(); ggMaxCurrentCtrl.Clear(); + ggAutoRelayButton.Clear(); ggMainOffButton.Clear(); ggMainOnButton.Clear(); for (auto &remotelinebreaker : m_remotelinebreakers) @@ -11838,6 +11843,8 @@ void TTrain::set_cab_controls(int const Cab) ggCompressorListButton.PutValue(static_cast(mvOccupied->CompressorListPos - 1)); // motor overload relay threshold / shunt mode ggMaxCurrentCtrl.PutValue(true == mvControlled->ShuntModeAllow ? (true == mvControlled->ShuntMode ? 1.f : 0.f) : mvControlled->MotorOverloadRelayHighThreshold ? 1.f : 0.f); + // automatic relays (AutoRelay) + ggAutoRelayButton.PutValue(mvOccupied->AutoRelayFlag ? 1.f : 0.f); // lights ggLightsButton.PutValue(static_cast(mvOccupied->LightsPos - 1)); @@ -12242,6 +12249,7 @@ bool TTrain::initialize_gauge(cParser &Parser, std::string const &Label, int con {"brakeprofiler_sw:", ggBrakeProfileR}, {"brakeopmode_sw:", ggBrakeOperationModeCtrl}, {"maxcurrent_sw:", ggMaxCurrentCtrl}, + {"autorelay_sw:", ggAutoRelayButton}, {"main_off_bt:", ggMainOffButton}, {"main_on_bt:", ggMainOnButton}, {"mainb_sw:", m_remotelinebreakers[0].main_switch}, diff --git a/vehicle/Train.h b/vehicle/Train.h index a547eef72..8bc27ac62 100644 --- a/vehicle/Train.h +++ b/vehicle/Train.h @@ -592,6 +592,7 @@ public: // reszta może by?publiczna TGauge ggWiperSw; // przelacznik wycieraczek TGauge ggMaxCurrentCtrl; + TGauge ggAutoRelayButton; // przełącznik AutoRelay: rozruch automatyczny, załączenie bocznikowania spalinowozu TGauge ggMainOffButton; TGauge ggMainOnButton; diff --git a/vehicle/fieldshunting.cpp b/vehicle/fieldshunting.cpp new file mode 100644 index 000000000..0a4135151 --- /dev/null +++ b/vehicle/fieldshunting.cpp @@ -0,0 +1,22 @@ +/* +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/fieldshunting.h" + +namespace fieldshunting { + +control diesel_electric(int const Autorelaytype, bool const Autorelayflag) { + if (Autorelayflag) { + return control::automatic; + } + return Autorelaytype == 2 ? control::off : control::manual; +} + +} // namespace fieldshunting diff --git a/vehicle/fieldshunting.h b/vehicle/fieldshunting.h new file mode 100644 index 000000000..747af7430 --- /dev/null +++ b/vehicle/fieldshunting.h @@ -0,0 +1,28 @@ +/* +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 + +// the field shunting (ScndCtrlPos) of the diesel-electric locomotives +namespace fieldshunting { + +// who sets the field shunting +enum class control : int { + manual, // the driver, with the second controller + automatic, // the shunting relays (RelayType) + off // nobody: the shunting is switched off, the field stays full +}; + +// who sets the field shunting of a diesel-electric locomotive, by its AutoRelay (Autorelaytype: 0 No, 1 Yes, +// 2 Optional) and its AutoRelayFlag (Autorelayflag). with the flag set, the relays. AutoRelay=Optional is a switch +// that lets the relays shunt the field, as the SU45's and SP45's "załączenie bocznikowania" (eu07/maszyna#167): +// switched off, nobody. otherwise the driver +control diesel_electric(int Autorelaytype, bool Autorelayflag); + +} // namespace fieldshunting