From 5f46aca43a41bb26d7822eb39756f5c3169b98a6 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 8 Nov 2026 14:48:04 +0100 Subject: [PATCH 1/3] fix: a latching line breaker lever goes off with the breaker knocked out (#277) The EP05's single two-state line breaker lever stayed on once the converter overload relay knocked the breaker out: every press of the toggle tried to close the open breaker, which the tripped relay refused. A press now puts a lever left on over an open breaker off first. (eu07/maszyna#394) --- CMakeLists.txt | 1 + tests/unit/test_linebreaker.cpp | 114 ++++++++++++++++++++++++++++++++ vehicle/Train.cpp | 17 +++-- vehicle/linebreaker.cpp | 26 ++++++++ vehicle/linebreaker.h | 28 ++++++++ 5 files changed, 181 insertions(+), 5 deletions(-) create mode 100644 tests/unit/test_linebreaker.cpp create mode 100644 vehicle/linebreaker.cpp create mode 100644 vehicle/linebreaker.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f34ad61f..a5e467d93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -464,6 +464,7 @@ set(CORE_SOURCES "scripting/ladderlogic.cpp" "vehicle/handover.cpp" "vehicle/horn.cpp" +"vehicle/linebreaker.cpp" "vehicle/smoke.cpp" ) add_library(eu07_core STATIC ${CORE_SOURCES}) diff --git a/tests/unit/test_linebreaker.cpp b/tests/unit/test_linebreaker.cpp new file mode 100644 index 000000000..126e3307c --- /dev/null +++ b/tests/unit/test_linebreaker.cpp @@ -0,0 +1,114 @@ +#include "stdafx.h" +#include "doctest.h" +#include "consist.h" +#include "drive.h" + +#include "vehicle/linebreaker.h" + +// the line breaker (WS) controls of the cab (eu07/maszyna#394) + +using test::consist; +using test::definition; + +namespace { + +// the line breaker lever of the EP05 (main_sw), a single two-state lever, the way TTrain works it: the state +// the cab keeps of the line breaker follows the vehicle, the breaker closes while the lever is on and can close +struct lever { + TMoverParameters &mover; + int breaker{0}; // as TTrain::m_linebreakerstate: 0 open, 1 closed + bool on{false}; + + void press() { + switch (linebreaker::pressed(breaker, true, on)) { + case linebreaker::toggle::close: + on = true; + break; + case linebreaker::toggle::open: + on = false; + if (breaker == 1 && mover.MainSwitch(false)) { + breaker = 0; + } + break; + default: + break; + } + } + // TTrain::Update() + void update() { + if (breaker == 0 && mover.Mains) { + breaker = 1; + } + if (breaker == 1 && false == mover.Mains) { + breaker = 0; + } + if (on && breaker == 0 && mover.MainSwitchCheck()) { + breaker = mover.MainSwitch(true) ? 1 : 0; + } + } +}; + +} // namespace + +TEST_CASE("line breaker: a press of the toggle closes an open breaker and opens a closed one") { + using enum linebreaker::toggle; + for (auto const latching : {false, true}) { + CHECK(linebreaker::pressed(0, latching, false) == close); + CHECK(linebreaker::pressed(1, latching, true) == open); + CHECK(linebreaker::pressed(1, latching, false) == open); + // freshly closed, the cab finishes closing it first + CHECK(linebreaker::pressed(2, latching, true) == none); + } + // a lever left on over an open breaker goes off; push buttons have no position to keep + CHECK(linebreaker::pressed(0, true, true) == open); + CHECK(linebreaker::pressed(0, false, true) == close); +} + +TEST_CASE("line breaker: the EP05's lever goes off with the converter overload relay tripped (eu07/maszyna#394)") { + consist train; + auto &ep05{train.add(definition::fiz("ep05_v2/ep05"), 1).mover()}; + test::track const line{0.15, 0.0, test::catenary_3kv}; + auto const driver{test::driving(train)}; + REQUIRE(test::start_up(driver, line)); + REQUIRE(ep05.Mains); + REQUIRE(ep05.ConverterFlag); + lever ws{ep05, 1, true}; + + // the converter overload relay knocks the line breaker out, as the cab does it when the converter is + // switched on together with the compressor; the lever stays on + ep05.ConvOvldFlag = true; + ep05.MainSwitch(false, range_t::local); + ws.update(); + REQUIRE_FALSE(ep05.Mains); + REQUIRE(ws.breaker == 0); + CHECK(ws.on); + // with the relay tripped the breaker doesn't close + test::drive(driver, line, 5.0); + CHECK_FALSE(ep05.MainSwitchCheck()); + + // nothing holds the lever: it goes off, and on again, though the breaker stays open + ws.press(); + CHECK_FALSE(ws.on); + ws.press(); + CHECK(ws.on); + ws.update(); + CHECK_FALSE(ep05.Mains); + ws.press(); + CHECK_FALSE(ws.on); + + // the relay reset, with the converter switched off, the lever put on closes the breaker again + ep05.ConverterSwitch(false, range_t::local); + test::drive(driver, line, 1.0); + CHECK(ep05.RelayReset(relay_t::primaryconverteroverload, range_t::local)); + CHECK_FALSE(ep05.ConvOvldFlag); + ws.update(); + CHECK_FALSE(ep05.Mains); // the lever is off + ws.press(); + ws.update(); + CHECK(ep05.Mains); + CHECK(ws.breaker == 1); + // and the next press opens it + ws.press(); + CHECK_FALSE(ws.on); + CHECK_FALSE(ep05.Mains); +} diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index e30635f4f..9fdb97bf9 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/. #include "stdafx.h" #include "vehicle/Train.h" #include "vehicle/horn.h" +#include "vehicle/linebreaker.h" #include "utilities/Globals.h" #include "simulation/simulation.h" @@ -3652,16 +3653,22 @@ void TTrain::OnCommand_linebreakertoggle(TTrain *Train, command_data const &Comm if (Command.action == GLFW_PRESS) { // press or hold... - if (Train->m_linebreakerstate == 0) + // a single two-state lever stays where it was put, also when the line breaker gets knocked out + auto const latchinglever{Train->ggMainOnButton.SubModel == nullptr && Train->ggMainOffButton.SubModel == nullptr && Train->ggMainButton.SubModel != nullptr && + Train->ggMainButton.type() == TGaugeType::toggle}; + switch (linebreaker::pressed(Train->m_linebreakerstate, latchinglever, Train->ggMainButton.GetDesiredValue() > 0.5)) { + case linebreaker::toggle::close: // ...to close the circuit // NOTE: bit of a dirty shortcut here OnCommand_linebreakerclose(Train, Command); - } - else if (Train->m_linebreakerstate == 1) - { - // ...to open the circuit + break; + case linebreaker::toggle::open: + // ...to open the circuit, or to put the lever off if the circuit was already opened OnCommand_linebreakeropen(Train, Command); + break; + default: + break; } } else if (Command.action == GLFW_RELEASE) diff --git a/vehicle/linebreaker.cpp b/vehicle/linebreaker.cpp new file mode 100644 index 000000000..97eae0325 --- /dev/null +++ b/vehicle/linebreaker.cpp @@ -0,0 +1,26 @@ +/* +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/linebreaker.h" + +namespace linebreaker { + +toggle pressed(int const Breakerstate, bool const Latchinglever, bool const Leveron) { + if (Breakerstate == 1) { + return toggle::open; + } + if (Breakerstate != 0) { + return toggle::none; + } + // the line breaker is open; a lever left on goes off first + return Latchinglever && Leveron ? toggle::open : toggle::close; +} + +} // namespace linebreaker diff --git a/vehicle/linebreaker.h b/vehicle/linebreaker.h new file mode 100644 index 000000000..370e992cc --- /dev/null +++ b/vehicle/linebreaker.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 line breaker (main switch, WS) controls of the cab +namespace linebreaker { + +enum class toggle : int { + none, // the press does nothing + close, // the control goes to its on position, and the line breaker closes if it can + open // the control goes to its off position, and the line breaker opens +}; + +// what a press of the line breaker toggle does. Breakerstate is the state the cab keeps of the line +// breaker (0: open, 1: closed, 2: freshly closed). Latchinglever is a single two-state switch which +// stays where it was put, Leveron that it stands in its on position. such a lever doesn't follow the +// line breaker: knocked out (by the converter overload relay, say) the breaker opens with the lever +// left on, and the lever has to go off before it can be put on again (eu07/maszyna#394) +toggle pressed(int Breakerstate, bool Latchinglever, bool Leveron); + +} // namespace linebreaker From 22c588d8f99099947b6d3e89e50c4051f5c1ef62 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 8 Nov 2026 14:48:42 +0100 Subject: [PATCH 2/3] feat(cab): 401Da oil pump lamp and slotted speedometer lever (eu07/maszyna#546) (#261) * feat: 401da oil pump lamp and slotted lever animation (eu07/maszyna#546) i-oilpump lights while the pre-lubrication oil pump works, so it goes off once the engine runs. animslottedlever: in the .mmd turns a lever by a pin on the coupling rod sliding in the lever's slot, which the speedometer drive of 401Da needs. The compressor start delay of #546 came with CompressorStartDelay (Brake section) of master. * fix: force GLM AVX2 only when the compiler targets AVX2 ENABLE_AVX2=OFF left GLM_FORCE_AVX2 defined, so MSVC still emitted AVX2 intrinsics and the exe crashed on CPUs without AVX2. * test: cover the compressor start delay and the oil pump lamp The delay of an engine stopped before it passed starts over, a compressor switched on by hand waits too, and the key is read from the Brake section. In the converter-fed set-up of 401Da the compressor waits for ConverterStartDelay and then its own delay. The oil pump (i-oilpump lamp) works before the engine start and stops once the engine runs. --- stdafx.h | 2 +- tests/unit/test_compressor.cpp | 90 ++++++++++++++++++++++++++++++++++ tests/unit/test_oil_pump.cpp | 55 +++++++++++++++++++++ vehicle/DynObj.cpp | 57 +++++++++++++++++++++ vehicle/DynObj.h | 10 ++++ vehicle/Train.cpp | 4 ++ vehicle/Train.h | 1 + 7 files changed, 218 insertions(+), 1 deletion(-) create mode 100644 tests/unit/test_oil_pump.cpp diff --git a/stdafx.h b/stdafx.h index f2b377196..164edc240 100644 --- a/stdafx.h +++ b/stdafx.h @@ -91,7 +91,7 @@ #if defined(__aarch64__) || defined(__arm64__) #define GLM_FORCE_NEON -#else +#elif defined(__AVX2__) // set by /arch:AVX2 or -mavx2 (ENABLE_AVX2); without it GLM falls back to SSE2 #define GLM_FORCE_AVX2 #endif #define GLM_FORCE_SWIZZLE diff --git a/tests/unit/test_compressor.cpp b/tests/unit/test_compressor.cpp index c5aa2fff7..4f55ce0b8 100644 --- a/tests/unit/test_compressor.cpp +++ b/tests/unit/test_compressor.cpp @@ -113,3 +113,93 @@ TEST_CASE("compressor: without a pressure switch the air over the cut-out pressu REQUIRE(vehicle->CompressorFlag); // nothing stops it CHECK(vehicle->CompressedVolume < 8.5 * 0.81); // a fifth of the air let out } + +TEST_CASE("compressor: an engine stopped before the delay passed counts the whole delay again") { + auto vehicle{compressor_vehicle(30.0)}; + vehicle->Mains = true; // engine started + run_compressor(vehicle, 20.0); + REQUIRE_FALSE(vehicle->CompressorFlag); + + vehicle->Mains = false; // engine stopped, 10 s short of the delay + run_compressor(vehicle, 1.0); + vehicle->Mains = true; + run_compressor(vehicle, 15.0); // 36 s since the first start, but only 15 s since this one + CHECK_FALSE(vehicle->CompressorFlag); + + run_compressor(vehicle, 15.1); + CHECK(vehicle->CompressorFlag); +} + +TEST_CASE("compressor: the start delay holds back a compressor switched on by hand too") { + auto vehicle{compressor_vehicle(30.0)}; + vehicle->CompressorStart = start_t::manual; + vehicle->CompressorAllow = true; // switch in the cabinet on before the engine start + vehicle->Mains = true; + + run_compressor(vehicle, 29.9); + CHECK_FALSE(vehicle->CompressorFlag); + run_compressor(vehicle, 0.2); + CHECK(vehicle->CompressorFlag); +} + +TEST_CASE("compressor: the start delay is read from the brake section") { + auto const delay{[](std::string const &Section) { + return vehicle{definition::load("wagon").set(Section, "CompressorStartDelay", 30)}->CompressorStartDelay; + }}; + CHECK(delay("Brake") == doctest::Approx(30.0)); + CHECK(delay("Cntrl") == doctest::Approx(0.0)); // the key isn't taken from the control section +} + +namespace { + +// 401Da: the compressor runs from the 110 V of the auxiliary generator driven by the engine, here the converter +// started with the main circuit, which gets up to voltage the converter start delay after the engine start +definition generator_vehicle(double const ConverterDelay, double const CompressorDelay) { + return definition::load("cab_vehicle") + .set("Param", "PWR", 370) + .set("Light", "Light", "Generator") + .set("Light", "LMaxVoltage", 110) + .set("Brake", "Vv", 0.6) + .set("Brake", "MinCP", 6.5) + .set("Brake", "MaxCP", 8.0) + .set("Brake", "CompressorSpeed", 0.003) + .set("Brake", "CompressorPower", "Converter") + .set("Brake", "CompressorStartDelay", CompressorDelay) + .set("Cntrl", "CompressorStart", "Automatic") + .set("Cntrl", "ConverterStart", "Automatic") + .set("Cntrl", "ConverterStartDelay", ConverterDelay); +} + +} // namespace + +TEST_CASE("compressor: fed from the converter it waits for the converter start delay") { + vehicle loco{generator_vehicle(30.0, 0.0)}; + REQUIRE(loco->CompressorPower == 2); + REQUIRE(loco->ConverterStartDelay == doctest::Approx(30.0)); + + loco.run(1.0); // engine off + CHECK_FALSE(loco->Power110vIsAvailable); + + loco->Mains = true; // engine started + loco.run(25.0); + CHECK_FALSE(loco->Power110vIsAvailable); + CHECK_FALSE(loco->CompressorFlag); + + loco.run(10.0); + CHECK(loco->Power110vIsAvailable); + CHECK(loco->CompressorFlag); +} + +TEST_CASE("compressor: fed from the converter the start delay counts from the converter voltage") { + vehicle loco{generator_vehicle(20.0, 10.0)}; + REQUIRE(loco->CompressorStartDelay == doctest::Approx(10.0)); + + loco.run(1.0); // engine off + loco->Mains = true; // engine started + loco.run(25.0); + REQUIRE(loco->Power110vIsAvailable); // the converter is up + CHECK_FALSE(loco->CompressorFlag); // but the compressor waits for its own delay as well + + loco.run(10.0); + CHECK(loco->CompressorFlag); +} diff --git a/tests/unit/test_oil_pump.cpp b/tests/unit/test_oil_pump.cpp new file mode 100644 index 000000000..a5f623233 --- /dev/null +++ b/tests/unit/test_oil_pump.cpp @@ -0,0 +1,55 @@ +#include "stdafx.h" +#include "doctest.h" +#include "vehicle.h" + +using test::definition; +using test::vehicle; + +// the oil pump lamp of the cab (i-oilpump) shows OilPump.is_active: the pre-lubrication pump of 401Da, which works +// before the engine start and stops once the engine runs and makes the oil pressure itself (eu07/maszyna#546) +// NOTE: the test vehicle has no diesel engine, so the pump check is called the way dizel_Update() calls it + +TEST_CASE("oil pump: the pre-lubrication pump works before the engine start and stops once the engine runs") { + vehicle loco{definition::load("cab_vehicle").set("Cntrl", "OilStart", "Manual")}; + REQUIRE(loco->OilPump.start_type == start_t::manual); + loco->Power24vIsAvailable = true; // battery on + + loco->OilPumpCheck(0.01); + CHECK_FALSE(loco->OilPump.is_active); // not switched on yet + + loco->OilPump.is_enabled = true; // pump switch on: pre-lubrication + loco->OilPumpCheck(0.01); + CHECK(loco->OilPump.is_active); + + loco->Mains = true; // engine started + loco->OilPumpCheck(0.01); + CHECK_FALSE(loco->OilPump.is_active); +} + +TEST_CASE("oil pump: the pump started with the engine start procedure stops once the engine runs") { + vehicle loco{definition::load("cab_vehicle").set("Cntrl", "OilStart", "Automatic")}; + REQUIRE(loco->OilPump.start_type == start_t::automatic); + loco->Power24vIsAvailable = true; + + loco->dizel_startup = true; // starter button pressed + loco->OilPumpCheck(0.01); + CHECK(loco->OilPump.is_active); + + loco->dizel_startup = false; // start procedure done, the pump keeps working until the engine runs + loco->OilPumpCheck(0.01); + CHECK(loco->OilPump.is_active); + + loco->Mains = true; + loco->OilPumpCheck(0.01); + CHECK_FALSE(loco->OilPump.is_active); +} + +TEST_CASE("oil pump: without power the pump and its lamp stay off") { + vehicle loco{definition::load("cab_vehicle")}; + loco->Power24vIsAvailable = false; + loco->Power110vIsAvailable = false; + + loco->OilPump.is_enabled = true; + loco->OilPumpCheck(0.01); + CHECK_FALSE(loco->OilPump.is_active); +} diff --git a/vehicle/DynObj.cpp b/vehicle/DynObj.cpp index d5f60e332..2da371e86 100644 --- a/vehicle/DynObj.cpp +++ b/vehicle/DynObj.cpp @@ -557,6 +557,33 @@ void TDynamicObject::UpdateAxle(TAnim *pAnim) pAnim->smAnimated->future_transform = glm::rotate((float)glm::radians(m_future_wheels_angle[wheel_id]), glm::vec3(1.0f, 0.0f, 0.0f)); }; +// angle of a slotted lever for given angle of the wheel, which drives the coupling rod with the pin +// all points of the coupling rod move along circles of crank radius, the lever follows the pin sliding in its slot +double TDynamicObject::slottedlever_angle( slottedlever_data const &Lever, double const Wheelangle ) { + // crank turned around X axis, the same way as the wheel + auto const wheelangle { glm::radians( Wheelangle ) }; + auto const crank { glm::dvec2( + Lever.crank.x * std::cos( wheelangle ) - Lever.crank.y * std::sin( wheelangle ), + Lever.crank.x * std::sin( wheelangle ) + Lever.crank.y * std::cos( wheelangle ) ) }; + auto const pin { Lever.pin - Lever.crank + crank }; + // angle relative to the pose of the lever in the model, which matches wheel angle 0 + return glm::degrees( std::atan2( pin.y, pin.x ) - std::atan2( Lever.pin.y, Lever.pin.x ) ); +} + +void TDynamicObject::update_slottedlevers() { + + for( auto const &lever : m_slottedlevers ) { + auto const wheelid { ( + ( lever.axle < iAnimType[ ANIM_WHEELS ] ) && ( lever.axle < static_cast( pAnimations.size() ) ) ? + pAnimations[ lever.axle ].dWheelAngle : + 1 ) }; // driving wheels and coupling rods by default + auto const angle { slottedlever_angle( lever, dWheelAngle[ wheelid ] ) }; + auto const futureangle { slottedlever_angle( lever, dWheelAngle[ wheelid ] + m_future_wheels_angle[ wheelid ] ) }; + lever.submodel->SetRotate( float3( 1, 0, 0 ), angle ); + lever.submodel->future_transform = glm::rotate( (float)glm::radians( std::remainder( futureangle - angle, 360.0 ) ), glm::vec3( 1.0f, 0.0f, 0.0f ) ); + } +} + // animacja drzwi - przesuw void TDynamicObject::UpdateDoorTranslate(TAnim *pAnim) { if( pAnim->smAnimated == nullptr ) { return; } @@ -841,6 +868,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) animation.yUpdate( &animation ); } } + update_slottedlevers(); if( mdModel != nullptr && ObjSqrDist < 50 * 50 ) { @@ -5739,6 +5767,35 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co } } + else if( token == "animslottedlever:" ) { + // lever with a slot, turned by a pin on the coupling rod (e.g. speedometer drive) + // parameters: submodel name, number of axle (from animwheelprefix) driving the coupling rod, crank radius [m], + // pin position relative to the lever axis [m] and crank angle [deg] for wheel angle 0, in local (Y, Z) plane of the lever + // angle is measured from Y axis towards Z axis, i.e. in the direction of rotation around X axis + slottedlever_data lever; + int axle { 1 }; + double crankradius { 0.0 }; + double crankangle { 0.0 }; + parser.getTokens( 6, false ); + parser + >> asAnimName + >> axle + >> crankradius + >> lever.pin.x + >> lever.pin.y + >> crankangle; + lever.submodel = GetSubmodelFromName( mdModel, asAnimName ); + if( lever.submodel != nullptr ) { + lever.submodel->WillBeAnimated(); + lever.axle = std::max( 0, axle - 1 ); + lever.crank = crankradius * glm::dvec2( std::cos( glm::radians( crankangle ) ), std::sin( glm::radians( crankangle ) ) ); + m_slottedlevers.emplace_back( lever ); + } + else { + ErrorLog( "Bad model: " + asFileName + " - missed submodel " + asAnimName, logtype::model ); + } + } + else if( token == "animdoorprefix:" ) { // nazwa animowanych drzwi int i, j; diff --git a/vehicle/DynObj.h b/vehicle/DynObj.h index 577f0f020..9df2d93b6 100644 --- a/vehicle/DynObj.h +++ b/vehicle/DynObj.h @@ -316,6 +316,16 @@ private: TSubModel *sm_summer_variant {}; // submodel letniego wariantu TSubModel *sm_autumn_variant {}; // submodel jesiennego wariantu double fWahaczeAmp; + // levers with a slot, turned by a pin on the coupling rod sliding in the slot (e.g. speedometer drive of 401Da) + struct slottedlever_data { + TSubModel *submodel { nullptr }; // lever, turned around its local X axis like the wheels + int axle { 0 }; // index of the axle animation, whose crank drives the coupling rod + glm::dvec2 pin { 0.0 }; // pin position relative to the lever axis for wheel angle 0, in local (Y, Z) plane [m] + glm::dvec2 crank { 0.0 }; // crank vector for wheel angle 0, in local (Y, Z) plane [m] + }; + std::vector m_slottedlevers; + static double slottedlever_angle( slottedlever_data const &Lever, double const Wheelangle ); + void update_slottedlevers(); // Winger 160204 - pantografy double pantspeedfactor; // animacje typu przesuw diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index 9fdb97bf9..5f27f2720 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -9044,6 +9044,7 @@ bool TTrain::Update(double const Deltatime) btLampkaSprezarka.Turn(mvControlled->CompressorFlag); // mutopsitka dziala btLampkaSprezarkaOff.Turn(!mvControlled->CompressorFlag); btLampkaFuelPumpOff.Turn(!mvControlled->FuelPump.is_active); + btLampkaOilPump.Turn(mvControlled->OilPump.is_active); // pre-lubrication pump, goes off once the engine is started // boczniki // Ra: w SU45 boczniki wchodzą na ScndCtrlPos, a nie na ScndCtrlActualPos @@ -9203,6 +9204,7 @@ bool TTrain::Update(double const Deltatime) btLampkaSprezarka.Turn(false); btLampkaSprezarkaOff.Turn(false); btLampkaFuelPumpOff.Turn(false); + btLampkaOilPump.Turn(false); btLampkaBezoporowa.Turn(false); btLampkaHamowanie1zes.Turn(false); btLampkaHamienie.Turn(false); @@ -11236,6 +11238,7 @@ void TTrain::clear_cab_controls() btLampkaSprezarkaOff.Clear(); btLampkaSprezarkaBOff.Clear(); btLampkaFuelPumpOff.Clear(); + btLampkaOilPump.Clear(); btLampkaNapNastHam.Clear(); btLampkaOporyB.Clear(); btLampkaStycznB.Clear(); @@ -11658,6 +11661,7 @@ bool TTrain::initialize_button(cParser &Parser, std::string const &Label, int co {"i-compressoroff:", btLampkaSprezarkaOff}, {"i-compressorboff:", btLampkaSprezarkaBOff}, {"i-fuelpumpoff:", btLampkaFuelPumpOff}, + {"i-oilpump:", btLampkaOilPump}, {"i-voltbrake:", btLampkaNapNastHam}, {"i-resistorsb:", btLampkaOporyB}, {"i-contactorsb:", btLampkaStycznB}, diff --git a/vehicle/Train.h b/vehicle/Train.h index 009b349b4..e664c231a 100644 --- a/vehicle/Train.h +++ b/vehicle/Train.h @@ -760,6 +760,7 @@ public: // reszta może by?publiczna TButton btLampkaSprezarkaOff; TButton btLampkaSprezarkaBOff; TButton btLampkaFuelPumpOff; + TButton btLampkaOilPump; TButton btLampkaBocznik1; TButton btLampkaBocznik2; TButton btLampkaBocznik3; From 8cc8158d2a18aed45fd9a9a98be2f7e8df638fcb Mon Sep 17 00:00:00 2001 From: pwarszawski Date: Sun, 8 Nov 2026 16:12:51 +0100 Subject: [PATCH 3/3] AI: making for a passenger stop, leave room only for the brake's own fill time Since #187 the braking curve towards a stop or a lower speed leaves room for the time the brake takes to respond, as long as the train brake handle is still in the running position. The horizon it takes has the AI's old look-ahead, (1 - a0) * 30/3.6 s, about 7-8 s, as its floor; at 60 km/h that is over 100 m, up to half of the braking distance. Stops at signals were tuned with it. A vehicle that brakes with its independent brake (an SN61, a light engine) leaves the train brake handle where it is, so it kept that room the whole way in: it braked early and gently, came down to 10 km/h some 50 m out and crawled the rest, applying power and the brake in turn. Making for a passenger stop (the point the train is to stop at, found by the scan of the route, is a W4), the room now covers only the time the brake takes to fill (half its application time), without the look-ahead floor. Stops at signals and anything else keep the room as it was. When a vehicle ahead is closer than the stop the scan found, the train makes for that vehicle, so the room is the full one again. --- vehicle/Driver.cpp | 14 +++++++++++++- vehicle/Driver.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 21aed82ab..bf0e18318 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -882,6 +882,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN auto speedlimitiscontinuous { true }; // stays true if potential active speed limit is unbroken to the last (relevant) point in scan table eSignNext = nullptr; IsAtPassengerStop = false; + bStopTargetIsPassengerStop = false; IsScheduledPassengerStopVisible = false; mvOccupied->SecuritySystem.set_cabsignal_lock(false); // te flagi są ustawiane tutaj, w razie potrzeby @@ -1001,6 +1002,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN fAcc = a; // zalecane przyspieszenie (nie musi być uwzględniane przez AI) fNext = v; // istotna jest prędkość na końcu tego odcinka fDist = d; // dlugość odcinka + bStopTargetIsPassengerStop = ( v == 0.0 ) && ( ( point.iFlags & spPassengerStopPoint ) != 0 ); } /* else if ((fAcc > 0) && (v >= 0) && (v > fNext)) { @@ -1015,6 +1017,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN fAcc = a; fNext = v; fDist = d; + bStopTargetIsPassengerStop = ( v == 0.0 ) && ( ( point.iFlags & spPassengerStopPoint ) != 0 ); } // potentially update our current speed limit if( v < VelLimitLastDist.first @@ -7377,6 +7380,10 @@ TController::adjust_desired_speed_for_obstacles() { if( k - vel < 5 ) { // porównanie modułów prędkości [km/h] // zatroszczyć się trzeba, jeśli tamten nie jedzie znacząco szybciej + if( Obstacle.distance < ActualProximityDist ) { + // the vehicle ahead, not the stop found by the scan, is what the train is now to stop short of + bStopTargetIsPassengerStop = false; + } ActualProximityDist = std::min( ActualProximityDist, Obstacle.distance ); @@ -7720,9 +7727,14 @@ TController::adjust_desired_speed_for_target_speed( double const Range ) { auto room { brakingroom }; if( ( AbsAccS <= 0.0 ) && ( BrakeCtrlPosition <= 0.0 ) ) { // only while the brake is still to be applied: once it acts, the room it needs to respond is behind + // making for a passenger stop only the time the brake takes to fill: the look-ahead the horizon + // keeps as its floor was set for the stops at a signal, and a vehicle that brakes with its + // independent brake, which leaves the train brake handle where it is, kept braking earlier + // and earlier the whole way in, to crawl the last tens of metres to the stop point + auto const brakea0 { bStopTargetIsPassengerStop ? 1.0 : fBrake_a0[ 0 ] }; room = std::max( 0.5 * brakingroom, - brakingroom - vel / 3.6 * brake_response_horizon( mvOccupied, BrakeSystem, 1.0, fBrake_a0[ 0 ] ) ); + brakingroom - vel / 3.6 * brake_response_horizon( mvOccupied, BrakeSystem, 1.0, brakea0 ) ); } deceleration = shaped_braking_demand( velocity, VelNext, room + 0.1 / 25.92, fAccGravity, diff --git a/vehicle/Driver.h b/vehicle/Driver.h index 68964711c..dd5403789 100644 --- a/vehicle/Driver.h +++ b/vehicle/Driver.h @@ -404,6 +404,7 @@ private: double VelDesired = 0.0; // predkość, z jaką ma jechać, wynikająca z analizy tableki; <=VelSignal double fAccDesiredAv = 0.0; // uśrednione przyspieszenie z kolejnych przebłysków świadomości, żeby ograniczyć migotanie double fBrakeHeldTime = 0.0; // czas od ostatniego przestawienia kranu hamulca zasadniczego + bool bStopTargetIsPassengerStop = false; // the point the train is to stop at, found by the last scan of the route, is a passenger stop double fShortfall = 0.0; // how far the train fell short of the braking demand at the last check [m/s2] double fShortfallTime = 0.0; // when that was checked int iShortfallGrowth = 0; // how many checks in a row the shortfall has grown