From 2d16657c2e313e2aad0e69a5fe0f521161f266db Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 06:16:59 +0100 Subject: [PATCH] fix(ai): keep the locomotive released while it pushes the buffers in to uncouple (#482) * test(scenarios): the L053 poranek cases now fail on the station's SM42 #409 fixed what both l053_poranek_tme222158_debica cases were marked xfail for: the EP07 on Tm4 stops at the checkpoint, and the ET21 no longer stands off the wire at Debica Towarowa. Run on staging f15ea405, neither passes yet: TME222158 gets to Debica and reports there, but the station's SM42-1096, ordered to uncouple at step 10 of deb_sm42_stat, pushes its cut past debica_k_sem_info at danger and never gets the coupler off, so the station never gives TME222158 step 1 and both runs end as a standstill (4347 s and 4576 s of simulation time). The xfail marks stay, with that reason. * fix(ai): keep the locomotive released while it pushes the buffers in to uncouple Stage 3 of uncoupling (TController::UpdateDisconnect) ends only when the locomotive has pushed the buffers together: a screw coupler is let go with the buffers under 0.01 m apart (or over 0.2 m). Nothing else ends the stage. The consist brakes applied in stage 2 hold the locomotive as well, and only its brake releaser lets it go. The AI worked the releaser in that stage only while it wanted to speed up (AccDesired above -0.05), together with the start-off rules of control_releaser. When the cut stands across a signal at stop for the direction the locomotive pushes in, the driver counts the signal as passed at its first move after the direction change, VelSignalLast becomes 0 and AccDesired stays at -0.05 or -0.85. The releaser then went off, the brake cylinder filled again from the brake pipe, the pressure switch cut the power, and the locomotive stood for good with the buffers 0.018 m apart. The station's SM42-1096 at Debica on L053 poranek did that at step 10 of deb_sm42_stat and logged "actuating and compressing buffers..." for the rest of the run (a temporary log line showed the brake cylinder going from 1.25 to 3.69 bar with the releaser off, and the gap staying at 0.0184 m). In stage 3 the releaser now stays on while the locomotive's brake cylinder holds more than 0.1 bar, whatever AccDesired is. The push asks for 2 km/h at most and the cut stays braked, so this changes nothing else. Everything else, including the rest of the uncoupling (the direction changes before and after it) and coupling, keeps the old rule. The overcharge guard (pipe above 5.2 bar) still turns the releaser off. The decision moves into vehicle/brakereleaser.{h,cpp} so it is unit tested; control_releaser does the same cues in the same order as before. On L053 poranek the SM42 now uncouples at step 10 in 0.2 s (gap 0.021 -> 0.0096 m) and the mission goes on. * test(scenarios): a shunter uncouples with its wagons standing across a signal at stop sm42_td_uncouple_past_signal (fragment td_uncouple_past_signal.scn) rebuilds the uncoupling of the SM42 at Debica on L053 poranek on td.scn. An SM42 pulls three loaded wagons back along tor1k, stops in front of a closed track with the far end of the last wagon 2 m past the exit signal stacja1_j at stop, and gets Shunt 0 0 at once. The pull leaves the screw coupler 0.019 m apart at the buffers. Before the fix of the releaser the locomotive stayed braked and the case ran into its timeout with no "uncoupled" in the log; now it uncouples within a second. * test(scenarios): the L053 poranek cases pass again With the station's SM42-1096 uncoupling at step 10 of deb_sm42_stat again (the releaser fix before this commit), both l053_poranek_tme222158_debica cases pass: TME222158 gets its exit signal at Debica after 4086.2 s of simulation, and with the ET21 after 4131.6 s. The xfail marks go, so that the runner doesn't fail on XPASS, and the README rows say so. --- CMakeLists.txt | 1 + tests/scenarios/README.md | 19 ++- .../cases/l053_poranek_tme222158_debica.json | 1 - .../l053_poranek_tme222158_debica_et21.json | 1 - .../cases/sm42_td_uncouple_past_signal.json | 25 ++++ .../cases/td_uncouple_past_signal.scn | 31 +++++ tests/unit/test_brake_releaser.cpp | 114 ++++++++++++++++++ vehicle/Driver.cpp | 50 +++----- vehicle/brakereleaser.cpp | 60 +++++++++ vehicle/brakereleaser.h | 39 ++++++ 10 files changed, 306 insertions(+), 35 deletions(-) create mode 100644 tests/scenarios/cases/sm42_td_uncouple_past_signal.json create mode 100644 tests/scenarios/cases/td_uncouple_past_signal.scn create mode 100644 tests/unit/test_brake_releaser.cpp create mode 100644 vehicle/brakereleaser.cpp create mode 100644 vehicle/brakereleaser.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3627ef518..34be53811 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -576,6 +576,7 @@ set(CORE_SOURCES "vehicle/drivingaid.cpp" "vehicle/brakingcurve.cpp" "vehicle/signalpassing.cpp" +"vehicle/brakereleaser.cpp" "vehicle/handover.cpp" "vehicle/crew.cpp" "vehicle/horn.cpp" diff --git a/tests/scenarios/README.md b/tests/scenarios/README.md index e021bb398..6d6317bd7 100644 --- a/tests/scenarios/README.md +++ b/tests/scenarios/README.md @@ -326,6 +326,21 @@ Przystanek whatever the buckle. With 600 mm over a main lobe of 8 m the locomoti the buckle at 46 km/h, 1036 m from the start (`Bad driving: ... derailed on buckled track`); with 30 mm it keeps on the rails and stops at Przystanek after 1400 m. +`sm42_td_uncouple_past_signal` (fragment `td_uncouple_past_signal.scn`) is the uncoupling of the SM42 at Debica on +L053 poranek (step 10 of `deb_sm42_stat`) on td.scn. An SM42 with no timetable stands turned at the far end of `tor1k`, +three wagons loaded with gravel (51 m of train) behind it towards the exit signal `stacja1_j`, which stays at stop (no +route). `tdo_n1734`, the track behind `tor1k`, is closed (`trackvel 0`) from the start. `event0` of `tor1k` gives the +driver `Shunt -1 0`: it pulls the wagons back for 47 m and stops in front of the closed track, with the far end of the +last wagon 2 m past the signal's memory cell (the `distance` check keeps it 0-4 m past). The pull leaves the screw +coupler stretched, 0.019 m apart at the buffers, and a screw coupler is let go only with the buffers pressed together +(under 0.01 m). At the first stand `event0` gives `Shunt 0 0`: brake the wagons, change direction, push the buffers in, +uncouple. After the direction change the driver counts `stacja1_j` as passed at its first move, so its speed is capped +at 0. The driver used to work the brake releaser only while it wanted to speed up, so the locomotive stayed braked by +the wagons' brake application and never closed the gap: no `uncoupled` in the log, and the case ran into its timeout. +Now the locomotive is released, eases into the wagons and uncouples within a second. The wagons are loaded so that the +stop leaves the gap above 0.01 m: with a coach and an empty wagon the buffers came to rest 0.009 m apart and the +coupler let go at once. + The `*_td_crew_*` cases (eu07/maszyna#510, fragment `td_crew.scn`) are about the crew command of a `putvalues` event, `Crew: `: cab 1 or -1 puts an AI driver in cab A or B of the vehicle named, 0 takes its AI driver off. The vehicle is named in the text, so the events are @@ -485,8 +500,8 @@ staging f15ea405 of 2026-11-23): | `wrzosy_pxe336080_couples` | #524 | passes: ordered to, the locomotive couples to the rake (`couples`, 262 s) and takes it out of the depot (696 s). The scenery itself gives no such order | | `baltyk_skm1_roj55324_shunting_signal` | #525 | passes, with four seeds: the unit on the siding is let into the platforms 4 minutes after the start, once the shunter beside it has done its first moves, and leaves at 10:42 | | `baltyk_skm1_roj55321_departure` | #525 | passes, with three seeds: the unit in the platform leaves at 10:34 | -| `l053_poranek_tme222158_debica` | #421 | `xfail`: on master of 2026-11-11 the station jammed 4 minutes after the start, the AI of EP07-338'16 passed the shunting signal Tm4 at stop at 29 km/h. Since #409 (staging f15ea405, 2026-11-23) the EP07 stops at the checkpoint and TME222158 gets to Debica, but the station's SM42-1096 jams it: ordered to uncouple at step 10 of `deb_sm42_stat` it pushes its cut past `debica_k_sem_info` at danger and never gets the coupler off, so the station never sends TME222158 on | -| `l053_poranek_tme222158_debica_et21` | #421 | `xfail`: on master of 2026-11-11, with an ET21 as in the report, the locomotive stopped for good at Debica Towarowa, on the headshunt 20 m past the end of the overhead wire, and its driver never got out of `Prepare_engine`. Since #409 (staging f15ea405) the ET21 gets through Debica Towarowa (steps 1-5 of `dt_tme222158_stat`) to Debica, then fails on the SM42 as `l053_poranek_tme222158_debica` does | +| `l053_poranek_tme222158_debica` | #421 | passes: TME222158 gets the exit signal to Sandomierz (step 6 of `deb_tme222158_stat`) after 4086.2 s. On master of 2026-11-11 the station jammed 4 minutes after the start, the AI of EP07-338'16 passed the shunting signal Tm4 at stop at 29 km/h; #409 fixed that. On staging f15ea405 (2026-11-23) the station's SM42-1096 jammed it next: ordered to uncouple at step 10 of `deb_sm42_stat`, with its cut standing across `debica_k_sem_info` at stop, it stayed braked and never got the coupler off (standstill after 4347 s), until the AI kept the locomotive released while it pushes the buffers in to uncouple (`sm42_td_uncouple_past_signal`) | +| `l053_poranek_tme222158_debica_et21` | #421 | passes after 4131.6 s. On master of 2026-11-11, with an ET21 as in the report, the locomotive stopped for good at Debica Towarowa, on the headshunt 20 m past the end of the overhead wire, and its driver never got out of `Prepare_engine`. Since #409 the ET21 gets through Debica Towarowa (steps 1-5 of `dt_tme222158_stat`) to Debica; there it waited for the SM42 as `l053_poranek_tme222158_debica` did, until the same fix | | `l053_poludnie_roj32134_debica` | #506 | passes: both trains run and the unit ends at Debica after 6134 s; no train in its way | In the L053 sceneries the test mode logs a signal passed at danger for several shunting diff --git a/tests/scenarios/cases/l053_poranek_tme222158_debica.json b/tests/scenarios/cases/l053_poranek_tme222158_debica.json index cba4a9830..dde90e86a 100644 --- a/tests/scenarios/cases/l053_poranek_tme222158_debica.json +++ b/tests/scenarios/cases/l053_poranek_tme222158_debica.json @@ -10,7 +10,6 @@ "reason": "tme222158_got_the_exit_signal_at_debica" }, "slow": true, - "xfail": "eu07/maszyna#421 is not reached, the station's SM42 jams Debica: since #409 EP07-338'16 stops at the checkpoint before Tm4 (tor1834:event0) and TME222158 is let in and reports at Debica (deb_tme222158_stat c 0), but SM42-1096, ordered to uncouple at step 10 of deb_sm42_stat, pushes its cut past debica_k_sem_info at danger and never gets the coupler off (\"Uncoupling [sm42-1096]: actuating and compressing buffers... from front\" for the rest of the run), so it never does step 11 and the station never gives TME222158 step 1: standstill after 4347 s", "physicslog": false, "ini": [ "file.binary.terrain no" diff --git a/tests/scenarios/cases/l053_poranek_tme222158_debica_et21.json b/tests/scenarios/cases/l053_poranek_tme222158_debica_et21.json index 62785a518..7ad5a1a78 100644 --- a/tests/scenarios/cases/l053_poranek_tme222158_debica_et21.json +++ b/tests/scenarios/cases/l053_poranek_tme222158_debica_et21.json @@ -16,7 +16,6 @@ "reason": "tme222158_got_the_exit_signal_at_debica" }, "slow": true, - "xfail": "eu07/maszyna#421 is not reached, the station's SM42 jams Debica, as in l053_poranek_tme222158_debica: since #409 the ET21 no longer stands off the wire at Debica Towarowa, it gets through steps 1-5 of dt_tme222158_stat, takes the wagons to Debica and reports there (deb_tme222158_stat c 0), but SM42-1096, ordered to uncouple at step 10 of deb_sm42_stat, pushes its cut past debica_k_sem_info at danger and never gets the coupler off (\"Uncoupling [sm42-1096]: actuating and compressing buffers... from front\" for the rest of the run), so it never does step 11 and the station never gives TME222158 step 1: standstill after 4576 s", "physicslog": false, "ini": [ "file.binary.terrain no" diff --git a/tests/scenarios/cases/sm42_td_uncouple_past_signal.json b/tests/scenarios/cases/sm42_td_uncouple_past_signal.json new file mode 100644 index 000000000..f1ae7b835 --- /dev/null +++ b/tests/scenarios/cases/sm42_td_uncouple_past_signal.json @@ -0,0 +1,25 @@ +{ + "description": "SM42 shunter on td.scn pulls three loaded wagons back along tor1k and stops with the far end of the last one a few metres past the exit signal stacja1_j at stop, then gets Shunt 0 0 (uncouple): after the direction change the signal lies at stop over that wagon, behind the new head, and the AI has to push the buffers in all the same and let the coupler go.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_uncouple_past_signal.scn", + "vars": { + "wagons": [ + "node -1 0 {{vehicle}}_w3 dynamic pkp\\401z_v2 82515940087-8 401zp_2 0 nobody 3 60 gravel enddynamic", + "node -1 0 {{vehicle}}_w2 dynamic pkp\\401z_v2 82515942691-5 401zp_1 0 nobody 3 60 gravel enddynamic", + "node -1 0 {{vehicle}}_w1 dynamic pkp\\401z_v2 82515993043-7 401zl_2 0 nobody 3 60 gravel enddynamic" + ] + }, + "track_events": { + "tor1k": "event0 autotest_wake" + }, + "test_config": [ + "test.fail_if_stop_overran no" + ], + "duration": 180, + "timeout": 600, + "checks": [ + { "type": "log_contains", "pattern": "Uncoupling \\[autotest_sm42_td_uncouple_past_signal\\]: uncoupled" }, + { "type": "distance", "min": 45, "max": 49 } + ] +} diff --git a/tests/scenarios/cases/td_uncouple_past_signal.scn b/tests/scenarios/cases/td_uncouple_past_signal.scn new file mode 100644 index 000000000..98ab9033e --- /dev/null +++ b/tests/scenarios/cases/td_uncouple_past_signal.scn @@ -0,0 +1,31 @@ +// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed. +// a shunter with no timetable stands at the far end of tor1k (point 2), turned (offset -1) to face back towards +// track 1 of Stacja1, with its wagons (vars.wagons) behind it, towards the exit signal stacja1_j (at stop, no route; +// its memory cell is 51 m into tor1k). the trainset's velocity is negative, so its driver takes the direction of the +// locomotive's cab and pulls. tdo_n1734, the track behind tor1k, is closed (speed 0) from the start, so the shunter +// pulls the wagons back along tor1k and stops in front of it, with the far end of the last wagon a few metres past +// the signal: the signal stands at stop over that wagon for the direction the shunter pushes in when it uncouples. +// the pull leaves the screw coupler stretched, as at a real stop. +trainset none tor1k 100.0 -0.1 +{{wagons}} +node -1 0 {{vehicle}} dynamic pkp\sm42_v1 6DA-1096 6da -1 headdriver 0 0 enddynamic +endtrainset + +node -1 0 autotest_closed eventlauncher 0 0 0 -1 none 1034 autotest_close end +event autotest_close trackvel 0 tdo_n1734 0 endevent + +// a standing shunter waits for the scenery's orders. event0 of tor1k (the case's track_events) runs while it stands +// there. the first time it gives the order to go (Shunt -1 0). 25 s later the shunter is on its way, and the first +// time it stands again, in front of tdo_n1734, it gets the order a scenery gives to leave the wagons: Shunt 0 0, +// uncouple everything behind the locomotive and stay. it brakes the wagons, changes direction, pushes the buffers in +// and lets the coupler go. the order comes at once: standing for long, the wagons' brakes release and the coupler +// draws the buffers together, which leaves nothing to push +node -1 0 autotest_ordered memcell 0 0 0 ordered 0 0 none endmemcell +event autotest_wake multiple 0 none autotest_go autotest_uncouple endevent +event autotest_go multiple 0 autotest_ordered autotest_go_order autotest_go_given autotest_go_done condition memcompare * 0 * endevent +event autotest_go_order PutValues 0 none 0 0 0 Shunt -1 0 endevent +event autotest_go_given UpdateValues 0 autotest_ordered * 1 * endevent +event autotest_go_done UpdateValues 25 autotest_ordered * 2 * endevent +event autotest_uncouple multiple 0 autotest_ordered autotest_uncouple_order autotest_uncouple_given condition memcompare * 2 * endevent +event autotest_uncouple_order PutValues 0 none 0 0 0 Shunt 0 0 endevent +event autotest_uncouple_given UpdateValues 0 autotest_ordered * 3 * endevent diff --git a/tests/unit/test_brake_releaser.cpp b/tests/unit/test_brake_releaser.cpp new file mode 100644 index 000000000..0e32552b3 --- /dev/null +++ b/tests/unit/test_brake_releaser.cpp @@ -0,0 +1,114 @@ +#include "stdafx.h" +#include "doctest.h" + +#include "vehicle/brakereleaser.h" + +// when the AI works the brake releaser of its locomotive (TController::control_releaser). in stage 3 of uncoupling +// the locomotive pushes towards the cut it leaves, until the screw coupler slackens enough to be let go +// (TController::UpdateDisconnect). the consist brakes applied in stage 2 hold the locomotive too, and only the +// releaser lets it go. the releaser was worked only while the driver wanted to speed up (AccDesired above +// -0.05), so a signal at stop the cut stood across after the direction change, which caps the speed at 0, left the +// locomotive braked and the uncoupling went on for good (SM42 at Debica on L053). + +namespace { + +// a locomotive standing in stage 3 of uncoupling, braked by the consist's brake application of stage 2 +brake_releaser::conditions compressing_buffers(double const Acceleration) { + brake_releaser::conditions state; + state.acceleration_desired = Acceleration; + state.pipe_pressure = 3.8; + state.cylinder_pressure = 1.5; + state.control_pressure = 5.0; + state.velocity = 0.0; + state.pressing = true; + state.compressing_buffers = true; + return state; +} + +// a locomotive standing braked at the head of a train with a charged brake pipe, about to start off +brake_releaser::conditions standing_braked(double const Acceleration) { + brake_releaser::conditions state; + state.acceleration_desired = Acceleration; + state.pipe_pressure = 5.0; + state.cylinder_pressure = 1.0; + state.control_pressure = 5.0; + state.velocity = 0.0; + return state; +} + +} // namespace + +TEST_CASE("brake releaser: stage 3 of uncoupling releases the locomotive whatever the driver's acceleration") { + for (auto const acceleration : {0.3, 0.0, -0.05, -0.2, -0.9}) { + CAPTURE(acceleration); + auto const wanted{brake_releaser::decide(compressing_buffers(acceleration))}; + CHECK(wanted.actuate); + CHECK_FALSE(wanted.fill_pipe); + } +} + +TEST_CASE("brake releaser: stage 3 of uncoupling leaves a released locomotive alone") { + for (auto const acceleration : {0.3, -0.9}) { + CAPTURE(acceleration); + auto state{compressing_buffers(acceleration)}; + state.cylinder_pressure = 0.05; + CHECK_FALSE(brake_releaser::decide(state).actuate); + } +} + +TEST_CASE("brake releaser: pressing outside stage 3 still needs the driver to want to speed up") { + // the direction changes of stages 2 and 4, and coupling, are as before: the releaser goes on only with + // AccDesired above -0.05 + auto state{compressing_buffers(0.3)}; + state.compressing_buffers = false; + CHECK(brake_releaser::decide(state).actuate); + state.acceleration_desired = -0.05; + CHECK_FALSE(brake_releaser::decide(state).actuate); + state.acceleration_desired = -0.9; + CHECK_FALSE(brake_releaser::decide(state).actuate); +} + +TEST_CASE("brake releaser: starting off releases a braked locomotive below 1 km/h") { + CHECK(brake_releaser::decide(standing_braked(0.3)).actuate); + CHECK_FALSE(brake_releaser::decide(standing_braked(-0.05)).actuate); + + auto moving{standing_braked(0.3)}; + moving.velocity = 1.0; + CHECK_FALSE(brake_releaser::decide(moving).actuate); + + auto lightly{standing_braked(0.3)}; + lightly.cylinder_pressure = 0.4; + CHECK_FALSE(brake_releaser::decide(lightly).actuate); + + // the control reservoir not charged: releasing would vent it + auto uncharged{standing_braked(0.3)}; + uncharged.control_pressure = 4.9; + CHECK_FALSE(brake_releaser::decide(uncharged).actuate); + // unless the train brake is held on purpose to start uphill + uncharged.uphill_start = true; + CHECK(brake_releaser::decide(uncharged).actuate); +} + +TEST_CASE("brake releaser: an empty brake pipe is filled up when the driver wants to speed up") { + auto state{standing_braked(0.3)}; + state.pipe_pressure = 2.9; + state.cylinder_pressure = 0.0; + auto const wanted{brake_releaser::decide(state)}; + CHECK(wanted.actuate); + CHECK(wanted.fill_pipe); + + state.acceleration_desired = -0.2; + auto const braking{brake_releaser::decide(state)}; + CHECK_FALSE(braking.actuate); + CHECK_FALSE(braking.fill_pipe); +} + +TEST_CASE("brake releaser: an overcharged brake pipe turns the releaser off, in stage 3 of uncoupling too") { + auto starting{standing_braked(0.3)}; + starting.pipe_pressure = 5.3; + CHECK_FALSE(brake_releaser::decide(starting).actuate); + + auto uncoupling{compressing_buffers(-0.9)}; + uncoupling.pipe_pressure = 5.3; + CHECK_FALSE(brake_releaser::decide(uncoupling).actuate); +} diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index cba35b68a..675c1ef8e 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -20,6 +20,7 @@ http://mozilla.org/MPL/2.0/. #include "utilities/Logs.h" #include "utilities/physicslog.h" #include "vehicle/Train.h" +#include "vehicle/brakereleaser.h" #include "vehicle/brakesetting.h" #include "vehicle/brakingcurve.h" #include "vehicle/handover.h" @@ -9117,39 +9118,26 @@ void TController::control_releaser() { if( false == hasreleaser ) { return; } - auto actuate { false }; + brake_releaser::conditions state; + state.acceleration_desired = AccDesired; + state.pipe_pressure = mvOccupied->PipePress; + state.cylinder_pressure = mvOccupied->BrakePress; + state.control_pressure = mvOccupied->Hamulec->GetCRP(); + state.velocity = mvOccupied->Vel; + state.uphill_start = bUphillStart; + state.pressing = TestFlag( iDrivigFlags, movePress ); + // stage 3 of uncoupling (UpdateDisconnect), from the direction change until the coupler lets go + state.compressing_buffers = + state.pressing && ( OrderCurrentGet() & Disconnect ) != 0 && iVehicleCount >= 0 && iDirection == iDirectionOrder; + auto const wanted { brake_releaser::decide( state ) }; + auto const actuate { wanted.actuate }; auto isbrakehandleinrightposition { true }; - if( AccDesired > EU07_AI_NOACCELERATION ) { - // fill up brake pipe if needed - if( mvOccupied->PipePress < 3.0 ) { - actuate = true; - // some vehicles require brake handle to be moved to specific position - if( mvOccupied->HandleUnlock != -3 ) { - cue_action( driver_hint::trainbrakesetpipeunlock ); - isbrakehandleinrightposition &= BrakeCtrlPosition == mvOccupied->HandleUnlock; - } - } - // wyluzuj lokomotywę, to szybciej ruszymy - // this rule is for starting off, so only below 1 km/h: at speed, just after an application, it would vent - // the control reservoir of a locomotive that may have to brake again before the pipe has refilled it - if( mvOccupied->BrakePress > 0.4 - && ( mvOccupied->Hamulec->GetCRP() > 4.9 - // starting uphill the train brake stays applied on purpose, and the locomotive's own share of it has to go - // for the power to come on (asynchronous drives and the pressure switch cut the power while it is applied) - || bUphillStart ) - && mvOccupied->Vel < 1.0 ) { - actuate = true; - } - // keep engine brakes released during coupling/uncoupling - if( true == TestFlag(iDrivigFlags, movePress) - && mvOccupied->BrakePress > 0.1 ) { - actuate = true; - } - } - // don't overcharge train brake pipe - if( mvOccupied->PipePress > 5.2 ) { - actuate = false; + // some vehicles require brake handle to be moved to specific position to fill up the brake pipe + if( wanted.fill_pipe + && mvOccupied->HandleUnlock != -3 ) { + cue_action( driver_hint::trainbrakesetpipeunlock ); + isbrakehandleinrightposition = ( BrakeCtrlPosition == mvOccupied->HandleUnlock ); } if( actuate ) { diff --git a/vehicle/brakereleaser.cpp b/vehicle/brakereleaser.cpp new file mode 100644 index 000000000..0a51c9a62 --- /dev/null +++ b/vehicle/brakereleaser.cpp @@ -0,0 +1,60 @@ +/* +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/brakereleaser.h" + +namespace brake_releaser { + +namespace { + +// the rules for a driver that wants to speed up +bool wanted_to_start(conditions const &State) { + // fill up the brake pipe if needed + if (State.pipe_pressure < 3.0) { + return true; + } + // wyluzuj lokomotywę, to szybciej ruszymy + // this rule is for starting off, so only below 1 km/h: at speed, just after an application, it would vent + // the control reservoir of a locomotive that may have to brake again before the pipe has refilled it + if (State.cylinder_pressure > 0.4 + && (State.control_pressure > 4.9 + // starting uphill the train brake stays applied on purpose, and the locomotive's own share of it has to go + // for the power to come on (asynchronous drives and the pressure switch cut the power while it is applied) + || State.uphill_start) + && State.velocity < 1.0) { + return true; + } + // keep engine brakes released during coupling/uncoupling + return State.pressing && State.cylinder_pressure > 0.1; +} + +} // namespace + +decision decide(conditions const &State) { + decision result; + if (State.acceleration_desired > no_acceleration) { + result.fill_pipe = State.pipe_pressure < 3.0; + result.actuate = wanted_to_start(State); + } + // uncoupling, stage 3: the locomotive has to push the slack of the coupler out whatever its speed table says. + // the consist stays held by its own brakes, applied in stage 2, and the push asks for 2 km/h at most. a signal + // at stop that the consist stands across after the direction change caps the speed at 0 and so AccDesired + // below no_acceleration, and a locomotive left braked by the consist's brake application never closes the gap + if (State.compressing_buffers && State.cylinder_pressure > 0.1) { + result.actuate = true; + } + // don't overcharge train brake pipe + if (State.pipe_pressure > 5.2) { + result.actuate = false; + } + return result; +} + +} // namespace brake_releaser diff --git a/vehicle/brakereleaser.h b/vehicle/brakereleaser.h new file mode 100644 index 000000000..62bc2e7c1 --- /dev/null +++ b/vehicle/brakereleaser.h @@ -0,0 +1,39 @@ +/* +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 + +// when the AI driver works the brake releaser of its locomotive (TController::control_releaser): it vents the +// locomotive's own train brake cylinders, to start off sooner, to fill up an empty brake pipe, and to let the +// locomotive press the buffers while it (un)couples +namespace brake_releaser { + +// the state of the locomotive and of its driver the decision depends on +struct conditions { + double acceleration_desired{0.0}; // AccDesired of the driver [m/s2]; above no_acceleration it wants to speed up + double pipe_pressure{0.0}; // brake pipe [bar] + double cylinder_pressure{0.0}; // the locomotive's brake cylinders [bar] + double control_pressure{0.0}; // the control reservoir of the locomotive's distributor [bar] + double velocity{0.0}; // [km/h] + bool uphill_start{false}; // starting uphill with the train brake held on purpose + bool pressing{false}; // (un)coupling: the driver presses the buffers (movePress) + bool compressing_buffers{false}; // uncoupling, stage 3: pushing towards the cut to slacken the coupler +}; + +struct decision { + bool actuate{false}; // the releaser goes on (else off) + bool fill_pipe{false}; // the brake pipe is to be filled up: the brake handle goes to its unlock position +}; + +// AccDesired at or below this asks for no speeding up (EU07_AI_NOACCELERATION of Driver.h) +inline constexpr double no_acceleration{-0.05}; + +decision decide(conditions const &State); + +} // namespace brake_releaser