diff --git a/CMakeLists.txt b/CMakeLists.txt index e97e41d03..a88a88424 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -548,6 +548,7 @@ set(CORE_SOURCES "vehicle/blackbox.cpp" "vehicle/enginestart.cpp" "vehicle/brakesetting.cpp" +"vehicle/drivingaid.cpp" "vehicle/handover.cpp" "vehicle/horn.cpp" "vehicle/linebreaker.cpp" diff --git a/application/driveruipanels.cpp b/application/driveruipanels.cpp index ba8e7556d..c598842d7 100644 --- a/application/driveruipanels.cpp +++ b/application/driveruipanels.cpp @@ -23,6 +23,7 @@ http://mozilla.org/MPL/2.0/. #include "world/mtable.h" #include "vehicle/Train.h" #include "vehicle/Driver.h" +#include "vehicle/drivingaid.h" #include "model/AnimModel.h" #include "vehicle/DynObj.h" #include "model/Model3d.h" @@ -76,6 +77,13 @@ drivingaid_panel::update() { auto const *mover = controlled->MoverParameters; auto const *vehicledriver = controlled->Mechanik; auto const *owner = controlled->ctOwner != nullptr ? controlled->ctOwner : controlled->Mechanik; + // the numbers of the throttle and brakes lines, with the controls of the cab the driver is in + auto const readout { drivingaid::compute( drivingaid::from_movers( + *mover, + *vehicledriver->Controlling(), + drivingaid::cab_controls { + train->ggLocalBrake.SubModel != nullptr, + train->ggJointCtrl.SubModel != nullptr } ) ) }; { // throttle, velocity, speed limits and grade std::string expandedtext; @@ -116,8 +124,8 @@ drivingaid_panel::update() { std::snprintf( m_buffer.data(), m_buffer.size(), STR_C("Throttle: %3d+%d %c%s"), - mover->EIMCtrlType > 0 ? std::max(0, static_cast(100.4 * mover->eimic_real)) : vehicledriver->Controlling()->MainCtrlPos, - mover->EIMCtrlType > 0 ? vehicledriver->Controlling()->MainCtrlPos : vehicledriver->Controlling()->ScndCtrlPos, + readout.throttle_first, + readout.throttle_second, mover->SpeedCtrlUnit.IsActive ? 'T' : mover->DirActive > 0 ? 'D' : mover->DirActive < 0 ? 'R' : @@ -137,16 +145,32 @@ drivingaid_panel::update() { mover->PipePress * 100 ); expandedtext = m_buffer.data(); } - auto const basicbraking { mover->fBrakeCtrlPos }; - auto const eimicbraking { std::max( 0.0, -100.0 * mover->eimic_real ) }; - std::snprintf( - m_buffer.data(), m_buffer.size(), - STR_C("Brakes: %5.1f+%-2.0f%c%s"), -// ( mover->EIMCtrlType == 0 ? basicbraking : mover->EIMCtrlType == 3 ? ( mover->UniCtrlIntegratedBrakeCtrl ? eimicbraking : basicbraking ) : eimicbraking ), - mover->UniCtrlIntegratedBrakeCtrl ? eimicbraking : basicbraking, - mover->LocalBrakePosA * LocalBrakePosNo, - mover->SlippingWheels ? '!' : ' ', - expandedtext.c_str() ); + if( readout.ed_percent ) { + // the ED braking demand, ahead of the expanded data (eu07/maszyna#558) + std::snprintf( + m_buffer.data(), m_buffer.size(), + STR_C(" ED brake: %d%%%%"), + *readout.ed_percent ); + expandedtext.insert( 0, m_buffer.data() ); + } + if( readout.show_local_brake ) { + std::snprintf( + m_buffer.data(), m_buffer.size(), + STR_C("Brakes: %5.1f+%-2.0f%c%s"), + readout.brake_first, + readout.local_brake, + mover->SlippingWheels ? '!' : ' ', + expandedtext.c_str() ); + } + else { + // the cab has no local brake control: its setting is left out (eu07/maszyna#555) + std::snprintf( + m_buffer.data(), m_buffer.size(), + STR_C("Brakes: %5.1f%c%s"), + readout.brake_first, + mover->SlippingWheels ? '!' : ' ', + expandedtext.c_str() ); + } text_lines.emplace_back( m_buffer.data(), Global.UITextColor ); } diff --git a/tests/unit/data/fiz/README.md b/tests/unit/data/fiz/README.md index 514fb6287..eb5650edb 100644 --- a/tests/unit/data/fiz/README.md +++ b/tests/unit/data/fiz/README.md @@ -59,8 +59,9 @@ Every `.json` here is a vehicle picked up by `test_fiz.cpp`: record the paramete | `su45_v2/301d.fiz` | SU45 | DumbDE | LSt | FV4a | PneumaticBrake | Screw | | `su46_v2/303d.fiz` | SU46 | DumbDE | LSt | FV4a | PneumaticBrake | Screw | | `tem2_v2/tem2a.fiz` | TEM2 | DieselElectric | LSt | M394 | PneumaticBrake | Screw | +| `vectron_v1/wariant_7w.fiz` | VECTRON | ElectricInductionMotor | EStED | MHZ_K8P | PneumaticBrake | Screw | | `wm15_v1/wm15.fiz` | WM15 | Dumb | LSt | FV4a | PneumaticBrake | Screw | | `wmb10_v1/wmb10.fiz` | WMB10 | DieselEngine | LSt | FV4a | PneumaticBrake | Screw | | `z1_v2/152a.fiz` | Z1 | - | KE | - | ManualBrake | Screw | -The paths are those of the game's `.fiz` files. `elf_v1/inverter.fiz` is a part the Elf units include, not a vehicle. The 218M (V2NList), the SA134 (HTCList) and the 22WEc (ffBrakeList) are there for lists the others lack, the EP05 for its camshaft. The 214MA stands for the 214M railbus, whose own file repeats a section (TurboPos and MotorParamTable twice), which the definitions here can't hold. +The paths are those of the game's `.fiz` files. `elf_v1/inverter.fiz` is a part the Elf units include, not a vehicle. The 218M (V2NList), the SA134 (HTCList) and the 22WEc (ffBrakeList) are there for lists the others lack, the EP05 for its camshaft, the Vectron for its ED brake lever of its own (SplitEDPneumaticBrake). The 214MA stands for the 214M railbus, whose own file repeats a section (TurboPos and MotorParamTable twice), which the definitions here can't hold. diff --git a/tests/unit/data/fiz/vectron_v1/wariant_7w.json b/tests/unit/data/fiz/vectron_v1/wariant_7w.json new file mode 100644 index 000000000..777f4a78b --- /dev/null +++ b/tests/unit/data/fiz/vectron_v1/wariant_7w.json @@ -0,0 +1,72 @@ +{ + "_source": "pkp/vectron_v1/wariant_7w.fiz", + "_comment": "converted by test_fiz.cpp from the game's definition with the files it includes, keeping what the game's loader reads", + "Param": {"Category": "train", "M": "90000", "Mred": "12000", "Vmax": "200", "PWR": "6400", "SandCap": "700"}, + "Load": {"MaxLoad": "7", "LoadQ": "pieces", "LoadAccepted": "pantstate", "LoadSpeed": "1", "UnLoadSpeed": "0.1"}, + "Dimensions": {"L": "18.925", "H": "3.95", "W": "2.95", "Cx": "0.1"}, + "Wheels": {"D": "1.250", "AIM": "4000", "Tw": "1.435", "Axle": "Bo'Bo'", "Ad": "3", "Bd": "9.5", "Rmin": "80"}, + "Brake": {"BrakeValve": "EStED", "NBpA": "4", "MBF": "50", "MaxBP": "3.7", "MaxLBP": "3.7", "BCN": "8", "RM": "0.81", "BCR": "0.127", "BCD": "0.04", "BCM": "2.7", "BCS": "0.8", "BSA": "0", "BM": "Disk2", "BVV": "125", "Vv": "0.8", "CompressorSpeed": "0.06", "CompressorPower": "Main", "MinCP": "8.5", "MaxCP": "9.9", "UBB1": "8", "UBB2": "2", "LPOn": "3.0", "LPOff": "4.5", "HandlePipeUnlockPos": "-1", "EmergencyCutsOffHandle": "Yes"}, + "SpringBrake": {"Volume": "10", "MBF": "8", "MaxSP": "5.5", "ResetP": "4.0", "MinFP": "3.5", "PressOff": "4.5", "PressOn": "3.5", "ValveOnArea": "0.0002", "ValveOffArea": "0.0002", "ValvePNBArea": "0.002", "MTC": "4"}, + "BuffCoupl": {"CType": "Screw", "kB": "9200", "DmaxB": "0.15", "FmaxB": "740", "kC": "4800", "DmaxC": "0.15", "FmaxC": "780", "beta": "0.58", "AllowedFlag": "103"}, + "Cntrl": {"BrakeSystem": "Pneumatic", "BrakeOpModes": "PN", "BCPN": "4", "BDelay1": "15", "BDelay2": "4", "BDelay3": "35", "BDelay4": "25", "ASB": "Automatic", "LocalBrake": "PneumaticBrake", "MCPN": "15", "SCPN": "40", "SpeedCtrlDelay": "0.5", "AutoRelay": "No", "MainInitTime": "10", "MainStart": "Manual", "IniCDelay": "0.5", "SCDelay": "0.1", "BrakeDelays": "GPR", "BrakeHandle": "MHZ_K8P", "LocBrakeHandle": "FD1", "ScndS": "Yes", "SBD": "0", "ConverterStart": "Automatic", "ConverterStartDelay": "10", "PantCompressorStart": "Automatic", "PantAutoValve": "Yes", "EIMCtrlType": "0", "HAO": "No", "HMO": "No", "HGDP1": "0.1", "OMP": "0.4", "DirChangeMaxPos": "0", "LocalBrakeTraxx": "No", "PantEPValveStart": "Manual", "PantEPValveSpring": "No", "HideDirStatusWhenMoving": "Yes", "HideDirStatusSpeed": "5", "AutomaticCabActivation": "No", "InactiveCabFlag": "161", "DCMB": "Yes", "DCDPP": "1.0", "IBTB": "Yes", "SBBBH": "Yes", "BBHT": "2.0", "MotorBlowersStart": "Converter", "SplitEDPneumaticBrake": "Yes", "DBPN": "15", "rows": [ + ["-1","0.8","-1","20","Pneumatic"], + ["0","0.5","-1","2","Pneumatic"], + ["1","0.46","-1","2","Pneumatic"], + ["2","0.42","-1","2","Pneumatic"], + ["3","0.38","-1","2","Pneumatic"], + ["4","0.34","-1","2","Pneumatic"], + ["5","0.29","-1","2","Pneumatic"], + ["6","0","-1","40","Pneumatic"], + ["LampRed=255","LampGreen=255","LampBlue=228"] + ]}, + "Security": {"AwareSystem": "Active,CabSignal,SeparateAcknowledge", "AwareDelay": "30", "SoundSignalDelay": "0", "MaxHoldTime": "1.0", "EmergencyBrakeDelay": "5", "RadioStop": "Yes"}, + "Light": {"Light": "Generator", "LGeneratorEngine": "ElectricSeriesMotor", "LMaxVoltage": "24", "LMaxCurrent": "155"}, + "Clima": {"Heating": "Main"}, + "Power": {"EnginePower": "CurrentCollector", "CollectorsNo": "2", "MaxVoltage": "4200", "MaxCurrent": "2000", "MinH": "0.38", "MinV": "1900", "MaxH": "2.4", "CSW": "1.4", "PhysicalLayout": "3", "PantType": "WBL85"}, + "Engine": {"EngineType": "ElectricInductionMotor", "Trans": "10:47", "dfic": "931", "dfmax": "1.67", "p": "2", "cfu": "29", "cim": "8.86", "icif": "0.642", "Uzmax": "2216", "Uzh": "2216", "DU": "20", "I0": "20", "fcfu": "30", "F0": "340", "a1": "0.35", "Pmax": "6400", "Fh": "150", "Ph": "5200", "Vh0": "5", "Vh1": "10", "Imax": "2500", "Flat": "Yes", "abed": "1", "edep": "1.5", "Imaxrpc": "500", "BRVto": "15", "MotorBlowersSustainTime": "30", "MotorBlowersStartVelocity": "0.1", "MotorBlowersSpeed": "-10"}, + "SpeedControl": {"SpeedCtrl": "Yes", "OverrideManual": "No", "InitPwr": "1.0", "MaxPwrVel": "-1", "StartVel": "-1", "VelStep": "5", "PwrStep": "0.01", "MinPwr": "0.0", "MaxPwr": "1.0", "MinVel": "0", "MaxVel": "200", "Offset": "0", "kPpos": "0.1", "kPneg": "0.2", "kIpos": "0.03", "kIneg": "0.03", "BrakeIntervention": "No", "SpeedCtrlType": "Time", "SpeedCtrlDelay": "0.5"}, + "Doors": {"OpenCtrl": "Mixed", "CloseCtrl": "Mixed", "DoorOpenWithPermit": "1", "DoorMaxShiftL": "2", "DoorsPermitLightBlinking": "0"}, + "Switches": {"Pantograph": "Impulse", "PantographPresets": "2|1|3|2", "PantographPresetDefault": "1", "ModernDimmer": "Yes"}, + "DimmerList": {"Size": "5", "Cycle": "no", "DefaultPos": "3", "rows": [ + ["yes","no","no"], + ["yes","yes","no"], + ["no","no","yes"], + ["no","no","no"], + ["no","yes","no"] + ]}, + "ffList": {"Size": "8", "rows": [ + ["0","0.2"], + ["1","0.2"], + ["9.2","0.6"], + ["24.6","0.8"], + ["30.0","0.8"], + ["30.0","1.74"], + ["35.2","2.07"], + ["35.2","2.44"], + ["49.8","3.388"] + ]}, + "LightsList": {"Size": "16", "Wrap": "Yes", "Default": "1", "rows": [ + ["0","0"], + ["17","0"], + ["4","0"], + ["16","1"], + ["1","16"], + ["21","34"], + ["34","0"], + ["21","0"], + ["37","0"], + ["33","0"], + ["22","34"], + ["36","0"], + ["21","0"], + ["21","0"], + ["38","34"], + ["38","0"] + ]}, + "WiperList": {"Size": "4", "Angle": "58", "rows": [ + ["0","0.7","0.0","0.5"], + ["3","0.7","7.0","0.5"], + ["3","0.7","0.7","0.0"], + ["3","0.5","0.5","0.0"] + ]} +} diff --git a/tests/unit/test_drivingaid.cpp b/tests/unit/test_drivingaid.cpp new file mode 100644 index 000000000..b6ae1cc9d --- /dev/null +++ b/tests/unit/test_drivingaid.cpp @@ -0,0 +1,176 @@ +#include "stdafx.h" +#include "doctest.h" +#include "vehicle.h" +#include "real_vehicles.h" + +#include "vehicle/drivingaid.h" +#include "McZapkie/hamulce.h" + +#include +#include +#include + +// the numbers of the driving aid panel's throttle and brakes lines: the ED braking shows (eu07/maszyna#558) and +// the local brake is left out where the cab has no control of it (eu07/maszyna#555) + +using test::definition; +using test::vehicle; + +namespace { + +// the cab controls of the vehicles here, as their cab definitions (.mmd) have them: the Vectron has a local brake +// lever and a joint controller whose braking range is its ED lever, the Traxx and the EU07 a local brake lever, +// the SM42 a joint controller whose braking range is the local brake, none of the 45 Elf cabs either of them +constexpr drivingaid::cab_controls vectron_cab{true, true}; +constexpr drivingaid::cab_controls lever_cab{true, false}; +constexpr drivingaid::cab_controls jointctrl_cab{false, true}; +constexpr drivingaid::cab_controls elf_cab{false, false}; + +drivingaid::readout read(vehicle &Vehicle, drivingaid::cab_controls const &Cab) { + return drivingaid::compute(drivingaid::from_movers(Vehicle.mover(), Vehicle.mover(), Cab)); +} + +// what the panel showed before: the throttle and brakes numbers, and the local brake always +drivingaid::readout before(TMoverParameters const &Mover) { + drivingaid::readout result; + result.throttle_first = Mover.EIMCtrlType > 0 ? std::max(0, static_cast(100.4 * Mover.eimic_real)) : Mover.MainCtrlPos; + result.throttle_second = Mover.EIMCtrlType > 0 ? Mover.MainCtrlPos : Mover.ScndCtrlPos; + result.brake_first = Mover.UniCtrlIntegratedBrakeCtrl ? std::max(0.0, -100.0 * Mover.eimic_real) : Mover.fBrakeCtrlPos; + result.local_brake = Mover.LocalBrakePosA * LocalBrakePosNo; + return result; +} + +test::track const line{0.15, 0.0, test::catenary_3kv}; + +} // namespace + +TEST_CASE("driving aid: the Vectron's ED lever shows as a negative throttle step, and its ED braking") { + vehicle vectron{definition::fiz("vectron_v1/wariant_7w"), 80.0 /* km/h */, "vectron", 1}; + REQUIRE(vectron->SplitEDPneumaticBrake); + REQUIRE(vectron->DynamicBrakeCtrlPosNo == 15); + REQUIRE(vectron->EIMCtrlType == 0); + + // lever at zero: the master controller, as before, and no ED braking + auto const idle{read(vectron, vectron_cab)}; + CHECK(idle.throttle_first == vectron->MainCtrlPos); + CHECK_FALSE(idle.ed_percent.has_value()); + CHECK(idle.show_local_brake); + + // six steps of the ED lever, as the cab's joint controller shows them + for (int step = 0; step < 6; ++step) { + REQUIRE(vectron->IncDynamicBrakeLevel(1.f)); + } + vectron.run(1.0, line); + REQUIRE(vectron->Vel > 15.0); // above Vh1, where the ED brake has its full demand + auto const braking{read(vectron, vectron_cab)}; + CHECK(braking.throttle_first == -6); + REQUIRE(vectron->eimic_real == doctest::Approx(-0.4)); + REQUIRE(braking.ed_percent.has_value()); + CHECK(*braking.ed_percent == 40); + // the train brake handle and the local brake, as before + CHECK(braking.brake_first == doctest::Approx(vectron->fBrakeCtrlPos)); + CHECK(braking.show_local_brake); + CHECK(braking.local_brake == doctest::Approx(0.0)); + + // the joint controller's braking range is the ED lever, so it isn't a local brake control + CHECK_FALSE(read(vectron, jointctrl_cab).show_local_brake); +} + +TEST_CASE("driving aid: the Traxx's ED braking from its master controller") { + vehicle traxx{definition::fiz("e186_v2/eu47"), 80.0 /* km/h */, "traxx", 1}; + REQUIRE(traxx->EIMCtrlType == 1); + REQUIRE_FALSE(traxx->SplitEDPneumaticBrake); + + CHECK_FALSE(read(traxx, lever_cab).ed_percent.has_value()); + // B+: the braking demand ramps towards full + traxx->MainCtrlPos = 0; + traxx.run(3.0, line); + REQUIRE(traxx->eimic_real < -0.2); + auto const braking{read(traxx, lever_cab)}; + REQUIRE(braking.ed_percent.has_value()); + CHECK(*braking.ed_percent == std::lround(-100.0 * traxx->eimic_real)); + // the drive demand stays at zero while braking, with the controller position next to it, as before + CHECK(braking.throttle_first == 0); + CHECK(braking.throttle_second == 0); + CHECK(braking.show_local_brake); +} + +TEST_CASE("driving aid: the Elf leaves out the local brake it has no control of, and shows its ED braking") { + vehicle elf{definition::fiz("elf_v1/21we-a"), 60.0 /* km/h */, "elf", 1}; + REQUIRE(elf->EIMCtrlType == 2); + // the definition has a local brake (LocalBrake=PneumaticBrake, LocBrakeHandle=FD1), the cab no control of it + REQUIRE(elf->LocalBrake == TLocalBrake::PneumaticBrake); + + auto const idle{read(elf, elf_cab)}; + CHECK_FALSE(idle.show_local_brake); + CHECK_FALSE(idle.ed_percent.has_value()); + + // the controller at its lowest braking position: the demand ramps towards full braking + elf->MainCtrlPos = 0; + elf.run(2.0, line); + REQUIRE(elf->eimic_real < -0.1); + auto const braking{read(elf, elf_cab)}; + REQUIRE(braking.ed_percent.has_value()); + CHECK(*braking.ed_percent == std::lround(-100.0 * elf->eimic_real)); + CHECK(braking.throttle_first == 0); + CHECK(braking.throttle_second == 0); + CHECK_FALSE(braking.show_local_brake); + + // applied after all (the AI, or the keys), it shows + elf->LocalBrakePosA = 0.3; + auto const applied{read(elf, elf_cab)}; + CHECK(applied.show_local_brake); + CHECK(applied.local_brake == doctest::Approx(3.0)); +} + +TEST_CASE("driving aid: a vehicle without an EIM controller shows what it did") { + vehicle eu07{definition::fiz("4e_v1/4e"), 60.0 /* km/h */, "eu07", 1}; + eu07->MainCtrlPos = 5; + eu07->LocalBrakePosA = 0.2; + auto const readout{read(eu07, lever_cab)}; + CHECK(readout.throttle_first == 5); + CHECK(readout.throttle_second == eu07->ScndCtrlPos); + CHECK(readout.local_brake == doctest::Approx(2.0)); + CHECK(readout.show_local_brake); + CHECK_FALSE(readout.ed_percent.has_value()); + + // the SM42's local brake is the braking range of its joint controller + vehicle sm42{definition::fiz("sm42_v1/6d1"), 0.0, "sm42", 1}; + CHECK(read(sm42, jointctrl_cab).show_local_brake); + CHECK_FALSE(read(sm42, elf_cab).show_local_brake); +} + +TEST_CASE("driving aid: the integrated universal controller shows the ED demand as its brake number, once") { + drivingaid::input input; + input.eim = true; + input.eimctrltype = 3; + input.integratedbrake = true; + input.eimic_real = -0.35; + input.brakectrlpos = 2.0; + auto const readout{drivingaid::compute(input)}; + CHECK(readout.brake_first == doctest::Approx(35.0)); + CHECK_FALSE(readout.ed_percent.has_value()); + CHECK(readout.throttle_first == 0); +} + +TEST_CASE("driving aid: every real vehicle with a local brake control shows the numbers it showed before") { + // with the ED lever of a split ED brake at zero, the change only adds the ED part and leaves out the local brake + // of a cab without a control of it + for (auto const &path : test::real_vehicles()) { + CAPTURE(path); + test::reseed_random(); + vehicle real{definition::fiz(path), 40.0 /* km/h */, "real", 1}; + for (auto const &[mainctrl, localbrake, eimic] : {std::tuple{0, 0.0, 0.0}, std::tuple{1, 0.4, -0.25}, std::tuple{1, 0.0, 0.6}}) { + real->MainCtrlPos = std::min(mainctrl, real->MainCtrlPosNo); + real->LocalBrakePosA = localbrake; + real->eimic_real = eimic; + auto const now{read(real, lever_cab)}; + auto const was{before(real.mover())}; + CHECK(now.throttle_first == was.throttle_first); + CHECK(now.throttle_second == was.throttle_second); + CHECK(now.brake_first == doctest::Approx(was.brake_first)); + CHECK(now.local_brake == doctest::Approx(was.local_brake)); + CHECK(now.show_local_brake); + } + } +} diff --git a/vehicle/drivingaid.cpp b/vehicle/drivingaid.cpp new file mode 100644 index 000000000..df8fc37a7 --- /dev/null +++ b/vehicle/drivingaid.cpp @@ -0,0 +1,79 @@ +/* +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/drivingaid.h" + +#include "McZapkie/MOVER.h" +#include "McZapkie/hamulce.h" + +#include +#include + +namespace drivingaid { + +namespace { + +// the first throttle number: the drive demand in percent with an EIM controller, else the master controller. +// a separate ED lever off its zero shows as the negative step the cab's joint controller is at +int throttle_first(input const &Input) { + if (Input.splited && Input.dynamicbrakepos > 0.0) { + return -static_cast(std::lround(Input.dynamicbrakepos * Input.dynamicbrakeposno)); + } + if (Input.eimctrltype > 0) { + return std::max(0, static_cast(100.4 * Input.eimic_real)); + } + return Input.mainctrlpos; +} + +// the cab has a control of the local brake: its own lever, or the braking range of the joint controller +// unless that range is the separate ED lever +bool has_local_brake_control(input const &Input) { + return Input.cab.localbrake || (Input.cab.jointctrl && false == Input.splited); +} + +} // namespace + +readout compute(input const &Input) { + readout result; + result.throttle_first = throttle_first(Input); + result.throttle_second = Input.eimctrltype > 0 ? Input.mainctrlpos : Input.scndctrlpos; + + auto const edbraking{std::max(0.0, -100.0 * Input.eimic_real)}; + result.brake_first = Input.integratedbrake ? edbraking : Input.brakectrlpos; + result.local_brake = Input.localbrakepos * LocalBrakePosNo; + // without a control in the cab the local brake is left out, unless it is applied after all (the AI or a key) + result.show_local_brake = has_local_brake_control(Input) || Input.localbrakepos > 0.0; + // the integrated universal controller shows the ED demand as its brake number already + if (Input.eim && false == Input.integratedbrake) { + if (auto const percent{static_cast(std::lround(edbraking))}; percent > 0) { + result.ed_percent = percent; + } + } + return result; +} + +input from_movers(TMoverParameters const &Vehicle, TMoverParameters const &Controlling, cab_controls const &Cab) { + input result; + result.eim = Vehicle.EngineType == TEngineType::ElectricInductionMotor || Vehicle.EIMCtrlType > 0; + result.eimctrltype = Vehicle.EIMCtrlType; + result.splited = Controlling.SplitEDPneumaticBrake; + result.integratedbrake = Vehicle.UniCtrlIntegratedBrakeCtrl; + result.eimic_real = Vehicle.eimic_real; + result.dynamicbrakepos = Controlling.DynamicBrakeCtrlPos; + result.dynamicbrakeposno = Controlling.DynamicBrakeCtrlPosNo; + result.mainctrlpos = Controlling.MainCtrlPos; + result.scndctrlpos = Controlling.ScndCtrlPos; + result.brakectrlpos = Vehicle.fBrakeCtrlPos; + result.localbrakepos = Vehicle.LocalBrakePosA; + result.cab = Cab; + return result; +} + +} // namespace drivingaid diff --git a/vehicle/drivingaid.h b/vehicle/drivingaid.h new file mode 100644 index 000000000..8cec257da --- /dev/null +++ b/vehicle/drivingaid.h @@ -0,0 +1,68 @@ +/* +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 + +class TMoverParameters; + +// what the driving aid panel shows of the controls and of the braking: the numbers of its throttle and +// brakes lines, worked out from the vehicle state (eu07/maszyna#558, eu07/maszyna#555) +namespace drivingaid { + +// the cab controls the panel needs to know of, which the cab definition (.mmd) has or lacks +struct cab_controls { + // a lever of the local (auxiliary) brake: localbrake: + bool localbrake{true}; + // a joint controller, jointctrl:, whose braking range is the local brake, or the ED lever with + // SplitEDPneumaticBrake + bool jointctrl{false}; +}; + +struct input { + // the vehicle works out the integrated drive and brake demand (eimic): an induction motor vehicle, + // or a diesel one with an EIM controller + bool eim{false}; + int eimctrltype{0}; + // the ED brake has a lever of its own (SplitEDPneumaticBrake), with dynamicbrakeposno steps + bool splited{false}; + // the universal controller brakes with the ED brake, so the brake handle number is the ED demand already + bool integratedbrake{false}; + // the demand in use, -1..1, negative braking + double eimic_real{0.0}; + double dynamicbrakepos{0.0}; // 0..1 + int dynamicbrakeposno{10}; + int mainctrlpos{0}; + int scndctrlpos{0}; + double brakectrlpos{0.0}; // the train brake handle + double localbrakepos{0.0}; // 0..1 + cab_controls cab; +}; + +struct readout { + // "Throttle: first+second" + int throttle_first{0}; + int throttle_second{0}; + // "Brakes: first+local" + double brake_first{0.0}; + double local_brake{0.0}; + bool show_local_brake{true}; + // the ED braking demand in percent, while there is some + std::optional ed_percent; +}; + +// the panel's numbers from the vehicle state +readout compute(input const &Input); + +// the state the panel reads: Vehicle is the one the driver sits in, Controlling the one whose controllers +// the driver moves (TController::Controlling()) +input from_movers(TMoverParameters const &Vehicle, TMoverParameters const &Controlling, cab_controls const &Cab); + +} // namespace drivingaid