From d3e6736f788918e0cfc0f4124aa6a2bf0c0df11d Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Wed, 25 Nov 2026 05:15:02 +0100 Subject: [PATCH] fix(ai): the braking margin ends once the independent brake is on (#479) * fix(ai): the braking margin ends once the independent brake is on The braking curve outside the final approach keeps the room the brake takes to fill only while the brake is still to be applied. It took the train brake handle past running as the only sign that the brake was on. A vehicle that runs alone, a light locomotive or a railcar such as the SN61, brakes with its independent brake and leaves the handle in running, so the margin never ended for it: on every look it planned to stop short by the distance the brake takes to fill, slowed down too early, released, braked again, and crawled the last tens of metres to a W4 or a signal at stop. This followed #264 and #297. The independent brake now counts as well (braking_curve::brake_acting, LocalBrakePosA above 0). On td.scn the light EU07 reaches the W4 of Przystanek 6.6 s sooner and covers the last 100 m in 20.3 s instead of 26.3 s; on a 20 per mille downgrade it reaches a signal at stop 11.7 s sooner (last 100 m in 20.6 s instead of 31.7 s), with 3 applications of the independent brake in the last 300 m instead of 5. A train braking with the train brake runs as before (its physicslog is the same byte for byte). * test(scenarios): light locomotive, railcar and train stopping down a 20 per mille gradient The *_td_downgrade_w4_signal cases run on a line the fragment adds beside td.scn: 300 m level, then 3000 m down a gradient of 20 per mille under a wire fed by a substation of its own. The train stops at the W4 of Dol 1500 m down the gradient and then before a signal at stop 1100 m further down. They run with a light EU07 and an SN61 alone, which brake with the independent brake, and with an EU07 and three coaches, which brakes with the train brake. eu07_coaches_td_timetable is that train on the td/rozklad timetable to Przystanek. They show the approach to a stop: before the previous commit the light EU07 needed 31.7 s for the last 100 m to the signal, now 20.6 s; the train with coaches runs the same in both. * fix(ai): the braking margin counts the independent brake only on a vehicle that has one * test(scenarios): the light EU07 and the SN61 stop at the signal down the gradient in time --- tests/scenarios/README.md | 18 +- .../eu07_coaches_td_downgrade_w4_signal.json | 42 ++ .../cases/eu07_coaches_td_timetable.json | 40 ++ .../cases/eu07_td_downgrade_w4_signal.json | 47 ++ .../cases/sn61_td_downgrade_w4_signal.json | 47 ++ tests/scenarios/cases/td_downgrade.txt | 20 + .../cases/td_downgrade_w4_signal.scn | 518 ++++++++++++++++++ tests/scenarios/run.py | 21 +- tests/unit/test_braking_curve.cpp | 35 ++ vehicle/Driver.cpp | 10 +- vehicle/brakingcurve.cpp | 4 + vehicle/brakingcurve.h | 8 +- 12 files changed, 803 insertions(+), 7 deletions(-) create mode 100644 tests/scenarios/cases/eu07_coaches_td_downgrade_w4_signal.json create mode 100644 tests/scenarios/cases/eu07_coaches_td_timetable.json create mode 100644 tests/scenarios/cases/eu07_td_downgrade_w4_signal.json create mode 100644 tests/scenarios/cases/sn61_td_downgrade_w4_signal.json create mode 100644 tests/scenarios/cases/td_downgrade.txt create mode 100644 tests/scenarios/cases/td_downgrade_w4_signal.scn diff --git a/tests/scenarios/README.md b/tests/scenarios/README.md index 2638272c7..bf5467018 100644 --- a/tests/scenarios/README.md +++ b/tests/scenarios/README.md @@ -254,6 +254,16 @@ the td/rozklad train, an EU07 with three coaches, with its head 80 m past the W4 under the consist, behind the head, and the driver still counts Stacja1 and leaves at 10:35, since the scan of the route begins at the last vehicle and keeps a W4 behind the head. +`eu07_coaches_td_timetable` is the timetable case with the EU07 and three coaches, a train that brakes with the train +brake, beside the light EU07 and the SN61 alone, which brake with the independent brake. The `*_td_downgrade_w4_signal` +cases (fragment `td_downgrade_w4_signal.scn`, timetable `td_downgrade.txt`) run on a line the fragment adds beside the +tracks of td.scn, at x = -3000: 300 m level, then 3000 m down a gradient of 20 per mille, under an overhead wire fed +by a substation of its own (`gr_pwr`; the wire on the section `pwr01` of td.scn gave the EU07 no voltage). The train +starts on the level at the W4 of Gora, stops at the W4 of Dol 1500 m down the gradient, leaves at 10:38 and stops before +`gr_sem`, a signal at stop 1100 m further down (a memory cell with `SetVelocity 0 0` and the event that reads it, no +model), about 1590 m and 2690 m from the start. The three trains are the light EU07, the SN61 alone and the EU07 with +three coaches. + The `test_mode_*` cases show the ends of the test mode: `test_mode_pass` (exit 0, the pass event), `test_mode_signal_passed_at_danger` (exit 11), `test_mode_timeout` (exit 12, from `test.timeout`), `test_mode_standstill` (exit 13, from `test.standstill`) and @@ -428,9 +438,11 @@ the row instead, logged by builds from this branch on. - `max_speed` `limit`, `tolerance`: never goes faster than `limit + tolerance`. - `brakes` `min_pressure`: after moving off, brake cylinder pressure reaches `min_pressure` bar (physicslog pressures are in bar whatever its header says; the brake pipe runs at 5.0). -- `stops` `moving_speed`, `stop_speed`, `hold`, optional `min_distance`, `max_distance`: after - reaching `moving_speed`, stays at or below `stop_speed` for `hold` seconds; with the distances, - that stop has to be between them (metres travelled, as in `distance`). +- `stops` `moving_speed`, `stop_speed`, `hold`, optional `min_distance`, `max_distance`, `max_time`, + `nth`: after reaching `moving_speed`, stays at or below `stop_speed` for `hold` seconds; with the + distances, that stop has to be between them (metres travelled, as in `distance`), with `max_time` + it has to begin by then (seconds of the physicslog). `nth` (default 1) takes a later stop: each + stop after the first counts once the train has reached `moving_speed` again. - `stays_stopped` `moving_speed`, `stop_speed`: after moving off and stopping, never goes above `stop_speed` again. - `distance` `min`, `max`: total distance travelled. The physicslog has no position, so the diff --git a/tests/scenarios/cases/eu07_coaches_td_downgrade_w4_signal.json b/tests/scenarios/cases/eu07_coaches_td_downgrade_w4_signal.json new file mode 100644 index 000000000..1faae73ff --- /dev/null +++ b/tests/scenarios/cases/eu07_coaches_td_downgrade_w4_signal.json @@ -0,0 +1,42 @@ +{ + "description": "An EU07 with three coaches on the line of eu07_td_downgrade_w4_signal, down a gradient of 20 per mille: stops at the W4 of Dol, then before the signal at stop. A train braking with the train brake, the control of the light EU07 and SN61 cases.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_downgrade_w4_signal.scn", + "timetable": "td_downgrade.txt", + "vars": { + "consist": [ + "node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 3 0 enddynamic", + "node -1 0 {{vehicle}}_c1 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c2 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c3 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 0 0 enddynamic" + ] + }, + "duration": 540, + "timeout": 900, + "checks": [ + { + "type": "starts", + "min_speed": 20, + "within": 150 + }, + { + "type": "max_speed", + "limit": 80, + "tolerance": 3 + }, + { + "type": "stops", + "moving_speed": 20, + "stop_speed": 1.0, + "hold": 20, + "min_distance": 1500, + "max_distance": 1700 + }, + { + "type": "distance", + "min": 2550, + "max": 2750 + } + ] +} diff --git a/tests/scenarios/cases/eu07_coaches_td_timetable.json b/tests/scenarios/cases/eu07_coaches_td_timetable.json new file mode 100644 index 000000000..c8621c3b0 --- /dev/null +++ b/tests/scenarios/cases/eu07_coaches_td_timetable.json @@ -0,0 +1,40 @@ +{ + "description": "EU07 with three coaches on td.scn, AI driver on the td/rozklad timetable: starts from Stacja1, keeps to the speed limit, brakes to a stop at Przystanek with the train brake.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_timetable.scn", + "vars": { + "consist": [ + "node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 3 0 enddynamic", + "node -1 0 {{vehicle}}_c1 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c2 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 3 0 enddynamic", + "node -1 0 {{vehicle}}_c3 dynamic pkp\\bdhpumn_v3 bdhpumn_50512608068-6 BDHPUMN_TAPICERKA_1 0 nobody 0 0 enddynamic" + ] + }, + "duration": 360, + "timeout": 600, + "checks": [ + { + "type": "starts", + "min_speed": 20, + "within": 150 + }, + { + "type": "max_speed", + "limit": 90, + "tolerance": 3 + }, + { + "type": "brakes", + "min_pressure": 0.5 + }, + { + "type": "stops", + "moving_speed": 20, + "stop_speed": 1.0, + "hold": 0, + "min_distance": 1380, + "max_distance": 1420 + } + ] +} diff --git a/tests/scenarios/cases/eu07_td_downgrade_w4_signal.json b/tests/scenarios/cases/eu07_td_downgrade_w4_signal.json new file mode 100644 index 000000000..e26f6180d --- /dev/null +++ b/tests/scenarios/cases/eu07_td_downgrade_w4_signal.json @@ -0,0 +1,47 @@ +{ + "description": "A light EU07 on a line of its own beside td.scn, down a gradient of 20 per mille on a timetable: stops at the W4 of Dol 1500 m down the gradient, leaves at 10:38 and stops before the signal gr_sem at stop 1100 m further down. The EU07 alone brakes with its independent brake.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_downgrade_w4_signal.scn", + "timetable": "td_downgrade.txt", + "vars": { + "consist": "node -1 0 {{vehicle}} dynamic pkp\\4e_v1 4e-004 4e 0 headdriver 0 0 enddynamic" + }, + "duration": 540, + "timeout": 900, + "checks": [ + { + "type": "starts", + "min_speed": 20, + "within": 150 + }, + { + "type": "max_speed", + "limit": 80, + "tolerance": 3 + }, + { + "type": "stops", + "moving_speed": 20, + "stop_speed": 1.0, + "hold": 20, + "min_distance": 1500, + "max_distance": 1700 + }, + { + "type": "stops", + "moving_speed": 20, + "stop_speed": 1.0, + "hold": 20, + "min_distance": 2550, + "max_distance": 2750, + "max_time": 355, + "nth": 2 + }, + { + "type": "distance", + "min": 2550, + "max": 2750 + } + ] +} diff --git a/tests/scenarios/cases/sn61_td_downgrade_w4_signal.json b/tests/scenarios/cases/sn61_td_downgrade_w4_signal.json new file mode 100644 index 000000000..033313dc0 --- /dev/null +++ b/tests/scenarios/cases/sn61_td_downgrade_w4_signal.json @@ -0,0 +1,47 @@ +{ + "description": "An SN61 railcar alone on the line of eu07_td_downgrade_w4_signal, down a gradient of 20 per mille: stops at the W4 of Dol, then before the signal at stop. The SN61 alone brakes with its independent brake.", + "base_scenery": "td.scn", + "time": "10:34", + "fragment": "td_downgrade_w4_signal.scn", + "timetable": "td_downgrade.txt", + "vars": { + "consist": "node -1 0 {{vehicle}} dynamic pkp\\sn61_v2 SN61-13 SN61_v1 0 headdriver 0 0 enddynamic" + }, + "duration": 540, + "timeout": 900, + "checks": [ + { + "type": "starts", + "min_speed": 20, + "within": 150 + }, + { + "type": "max_speed", + "limit": 80, + "tolerance": 3 + }, + { + "type": "stops", + "moving_speed": 20, + "stop_speed": 1.0, + "hold": 20, + "min_distance": 1500, + "max_distance": 1700 + }, + { + "type": "stops", + "moving_speed": 20, + "stop_speed": 1.0, + "hold": 20, + "min_distance": 2550, + "max_distance": 2750, + "max_time": 366, + "nth": 2 + }, + { + "type": "distance", + "min": 2550, + "max": 2750 + } + ] +} diff --git a/tests/scenarios/cases/td_downgrade.txt b/tests/scenarios/cases/td_downgrade.txt new file mode 100644 index 000000000..ddc50d031 --- /dev/null +++ b/tests/scenarios/cases/td_downgrade.txt @@ -0,0 +1,20 @@ +________________________________________________________________ +[ Rodzaj i numer pociagu | TEST26 ] +[ Kategoria | RO ] +[________________________________________________|______________] +[ | Gora ] +[ Relacja pociagu | Koniec ] +[________________________________________________|______________] +[ Wymagany % ciezaru hamujacego | 88% ] +[________________________________________________|______________] +[ Seria i obciazenie lokomotywy | EU07 210 ] +[________________________________________________|______________] +[ | | Gora 2 | | ] +[ | 80 | R1,L,H,RT,PP 2 10.35 | ] +[ | |----------------------------------1----------|---] +[ | | Dol 1 10.37 | 4 ] +[ |_____| R1,+,L,H,PP 1 10.38 | ] +[ | 80 |----------------------------------1----------|---] +[ | | Koniec 1 10.45 | 7 ] +[ | | R1 1 10.46 | ] +[_______|_____|__________________________________1__________|___] diff --git a/tests/scenarios/cases/td_downgrade_w4_signal.scn b/tests/scenarios/cases/td_downgrade_w4_signal.scn new file mode 100644 index 000000000..ffa43ecc3 --- /dev/null +++ b/tests/scenarios/cases/td_downgrade_w4_signal.scn @@ -0,0 +1,518 @@ +// added by tests/scenarios/run.py to td.scn, whose own trainsets were removed. +// a line of its own, away from the tracks of td.scn: 300 m level, then 3000 m down a gradient of 20 per mille, +// under an overhead wire. +// the train starts on the level, with the W4 of Gora about 40 m ahead, and runs on the timetable {{timetable}}: +// Gora 10:35 -> Dol, a W4 1500 m down the gradient (stop, leaves at 10:38) -> the signal gr_sem, 1100 m further +// down, which stays at stop. the line goes on 400 m past the signal +node -1 0 gr_00 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -200.0 0.0 +0 +endtrack +node -1 0 gr_01 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 -100.0 0.0 +0 +endtrack +node -1 0 gr_02 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 -100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 60.00 0.0 0.0 +0 +event2 gora#1_stopinfo +endtrack +node -1 0 gr_03 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 60.00 0.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 58.00 100.0 0.0 +0 +endtrack +node -1 0 gr_04 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 58.00 100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 56.00 200.0 0.0 +0 +endtrack +node -1 0 gr_05 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 56.00 200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 54.00 300.0 0.0 +0 +endtrack +node -1 0 gr_06 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 54.00 300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 52.00 400.0 0.0 +0 +endtrack +node -1 0 gr_07 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 52.00 400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 50.00 500.0 0.0 +0 +endtrack +node -1 0 gr_08 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 50.00 500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 48.00 600.0 0.0 +0 +endtrack +node -1 0 gr_09 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 48.00 600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 46.00 700.0 0.0 +0 +endtrack +node -1 0 gr_10 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 46.00 700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 44.00 800.0 0.0 +0 +endtrack +node -1 0 gr_11 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 44.00 800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 42.00 900.0 0.0 +0 +endtrack +node -1 0 gr_12 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 42.00 900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 40.00 1000.0 0.0 +0 +endtrack +node -1 0 gr_13 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 40.00 1000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 38.00 1100.0 0.0 +0 +endtrack +node -1 0 gr_14 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 38.00 1100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 36.00 1200.0 0.0 +0 +endtrack +node -1 0 gr_15 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 36.00 1200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 34.00 1300.0 0.0 +0 +endtrack +node -1 0 gr_16 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 34.00 1300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 32.00 1400.0 0.0 +0 +endtrack +node -1 0 gr_17 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 32.00 1400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 30.00 1500.0 0.0 +0 +event2 dol#1_stopinfo +endtrack +node -1 0 gr_18 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 30.00 1500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 28.00 1600.0 0.0 +0 +endtrack +node -1 0 gr_19 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 28.00 1600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 26.00 1700.0 0.0 +0 +endtrack +node -1 0 gr_20 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 26.00 1700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 24.00 1800.0 0.0 +0 +endtrack +node -1 0 gr_21 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 24.00 1800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 22.00 1900.0 0.0 +0 +endtrack +node -1 0 gr_22 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 22.00 1900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 20.00 2000.0 0.0 +0 +endtrack +node -1 0 gr_23 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 20.00 2000.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 18.00 2100.0 0.0 +0 +endtrack +node -1 0 gr_24 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 18.00 2100.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 16.00 2200.0 0.0 +0 +endtrack +node -1 0 gr_25 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 16.00 2200.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 14.00 2300.0 0.0 +0 +endtrack +node -1 0 gr_26 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 14.00 2300.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 12.00 2400.0 0.0 +0 +endtrack +node -1 0 gr_27 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 12.00 2400.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 10.00 2500.0 0.0 +0 +endtrack +node -1 0 gr_28 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 10.00 2500.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 8.00 2600.0 0.0 +0 +event2 gr_sem_info +endtrack +node -1 0 gr_29 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 8.00 2600.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 6.00 2700.0 0.0 +0 +endtrack +node -1 0 gr_30 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 6.00 2700.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 4.00 2800.0 0.0 +0 +endtrack +node -1 0 gr_31 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 4.00 2800.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 2.00 2900.0 0.0 +0 +endtrack +node -1 0 gr_32 track normal 100.0 1.435 0.15 25.0 20 0 flat vis + rail_screw_used1 6 1435mm/tpbps-new2 0.2 0.5 1.1 +-3000.0 2.00 2900.0 0.0 +0.0 0.0 0.0 +0.0 0.0 0.0 +-3000.0 0.00 3000.0 0.0 +0 +endtrack +// the overhead wire along the whole line, as td.scn has it: 5.6 m above the rail, the carrier 1.7 m higher, fed by +// a substation of its own +node -1 0 gr_pwr tractionpowersource -3000.0 60.00 0.0 3400 0 0.01 2000 1.0 3 60.0 end +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -300.0 +-3000.0 65.60 -200.0 +-3000.0 67.30 -300.0 +-3000.0 67.30 -200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -200.0 +-3000.0 65.60 -100.0 +-3000.0 67.30 -200.0 +-3000.0 67.30 -100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 -100.0 +-3000.0 65.60 0.0 +-3000.0 67.30 -100.0 +-3000.0 67.30 0.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 65.60 0.0 +-3000.0 63.60 100.0 +-3000.0 67.30 0.0 +-3000.0 65.30 100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 63.60 100.0 +-3000.0 61.60 200.0 +-3000.0 65.30 100.0 +-3000.0 63.30 200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 61.60 200.0 +-3000.0 59.60 300.0 +-3000.0 63.30 200.0 +-3000.0 61.30 300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 59.60 300.0 +-3000.0 57.60 400.0 +-3000.0 61.30 300.0 +-3000.0 59.30 400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 57.60 400.0 +-3000.0 55.60 500.0 +-3000.0 59.30 400.0 +-3000.0 57.30 500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 55.60 500.0 +-3000.0 53.60 600.0 +-3000.0 57.30 500.0 +-3000.0 55.30 600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 53.60 600.0 +-3000.0 51.60 700.0 +-3000.0 55.30 600.0 +-3000.0 53.30 700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 51.60 700.0 +-3000.0 49.60 800.0 +-3000.0 53.30 700.0 +-3000.0 51.30 800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 49.60 800.0 +-3000.0 47.60 900.0 +-3000.0 51.30 800.0 +-3000.0 49.30 900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 47.60 900.0 +-3000.0 45.60 1000.0 +-3000.0 49.30 900.0 +-3000.0 47.30 1000.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 45.60 1000.0 +-3000.0 43.60 1100.0 +-3000.0 47.30 1000.0 +-3000.0 45.30 1100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 43.60 1100.0 +-3000.0 41.60 1200.0 +-3000.0 45.30 1100.0 +-3000.0 43.30 1200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 41.60 1200.0 +-3000.0 39.60 1300.0 +-3000.0 43.30 1200.0 +-3000.0 41.30 1300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 39.60 1300.0 +-3000.0 37.60 1400.0 +-3000.0 41.30 1300.0 +-3000.0 39.30 1400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 37.60 1400.0 +-3000.0 35.60 1500.0 +-3000.0 39.30 1400.0 +-3000.0 37.30 1500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 35.60 1500.0 +-3000.0 33.60 1600.0 +-3000.0 37.30 1500.0 +-3000.0 35.30 1600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 33.60 1600.0 +-3000.0 31.60 1700.0 +-3000.0 35.30 1600.0 +-3000.0 33.30 1700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 31.60 1700.0 +-3000.0 29.60 1800.0 +-3000.0 33.30 1700.0 +-3000.0 31.30 1800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 29.60 1800.0 +-3000.0 27.60 1900.0 +-3000.0 31.30 1800.0 +-3000.0 29.30 1900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 27.60 1900.0 +-3000.0 25.60 2000.0 +-3000.0 29.30 1900.0 +-3000.0 27.30 2000.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 25.60 2000.0 +-3000.0 23.60 2100.0 +-3000.0 27.30 2000.0 +-3000.0 25.30 2100.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 23.60 2100.0 +-3000.0 21.60 2200.0 +-3000.0 25.30 2100.0 +-3000.0 23.30 2200.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 21.60 2200.0 +-3000.0 19.60 2300.0 +-3000.0 23.30 2200.0 +-3000.0 21.30 2300.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 19.60 2300.0 +-3000.0 17.60 2400.0 +-3000.0 21.30 2300.0 +-3000.0 19.30 2400.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 17.60 2400.0 +-3000.0 15.60 2500.0 +-3000.0 19.30 2400.0 +-3000.0 17.30 2500.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 15.60 2500.0 +-3000.0 13.60 2600.0 +-3000.0 17.30 2500.0 +-3000.0 15.30 2600.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 13.60 2600.0 +-3000.0 11.60 2700.0 +-3000.0 15.30 2600.0 +-3000.0 13.30 2700.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 11.60 2700.0 +-3000.0 9.60 2800.0 +-3000.0 13.30 2700.0 +-3000.0 11.30 2800.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 9.60 2800.0 +-3000.0 7.60 2900.0 +-3000.0 11.30 2800.0 +-3000.0 9.30 2900.0 +0.4 4.0 3 0.04 vis +endtraction +node -1 0 none traction gr_pwr 3500 4500 0.01 cu 3.0 1 +-3000.0 7.60 2900.0 +-3000.0 5.60 3000.0 +-3000.0 9.30 2900.0 +-3000.0 7.30 3000.0 +0.4 4.0 3 0.04 vis +endtraction + +// the W4 of the two stations of the timetable; the middle of the consist 2 m before it, leaves on time +include ip/pkp/w4n.inc gora#1 -2997.3 60.00 -60.0 180 0 0 2 202 end +include ip/pkp/w4n.inc dol#1 -2997.3 30.00 1500.0 180 0 0 2 202 end +// a signal at stop: what the AI reads of one, a memory cell with SetVelocity 0 0 and the event that reads it +node -1 0 gr_sem_mem memcell -2997.3 8.00 2600.0 SetVelocity 0.0 0.0 none endmemcell +event gr_sem_info getvalues 5.0 gr_sem_mem endevent + +trainset {{timetable}} gr_02 0.0 0.1 +{{consist}} +endtrainset diff --git a/tests/scenarios/run.py b/tests/scenarios/run.py index 35e923bee..2dcec6f0d 100644 --- a/tests/scenarios/run.py +++ b/tests/scenarios/run.py @@ -482,25 +482,42 @@ def check_brakes(rows, min_pressure, moving_speed=20): return False, f"brake cylinder pressure never reached {min_pressure} bar after moving off" -def check_stops(rows, moving_speed, stop_speed, hold, min_distance=None, max_distance=None): +def check_stops(rows, moving_speed, stop_speed, hold, min_distance=None, max_distance=None, max_time=None, nth=1): + """The nth stop of `hold` seconds after moving off at `moving_speed` (each stop after the first counts once the + train is moving at `moving_speed` again).""" start = _first_moving(rows, moving_speed) if start is None: return False, f"never reached {moving_speed} km/h" dist = _distances(rows) stopped_at = None + held = 0 + moving = True for i in range(start, len(rows)): r = rows[i] + if not moving: + moving = r[COL_VELOCITY] >= moving_speed + continue if r[COL_VELOCITY] <= stop_speed: if stopped_at is None: stopped_at = i if r[COL_TIME] - rows[stopped_at][COL_TIME] >= hold: + held += 1 + if held < nth: + stopped_at = None + moving = False + continue where = dist[stopped_at] - detail = f"came to a stop at t={rows[stopped_at][COL_TIME]:.1f}s after {where:.0f} m" + when = rows[stopped_at][COL_TIME] + detail = f"came to a stop at t={when:.1f}s after {where:.0f} m" if (min_distance is not None and where < min_distance) or (max_distance is not None and where > max_distance): return False, f"{detail}, wanted between {min_distance} and {max_distance} m" + if max_time is not None and when > max_time: + return False, f"{detail}, wanted by t={max_time}s" return True, detail else: stopped_at = None + if held: + return False, f"stopped {held} times for {hold}s after moving off, wanted stop {nth}" return False, f"did not stay below {stop_speed} km/h for {hold}s after moving off" diff --git a/tests/unit/test_braking_curve.cpp b/tests/unit/test_braking_curve.cpp index 7102d06e0..6bcf92fc7 100644 --- a/tests/unit/test_braking_curve.cpp +++ b/tests/unit/test_braking_curve.cpp @@ -154,6 +154,41 @@ TEST_CASE("braking curve: a train with a worked out brake table plans along the } } +TEST_CASE("braking curve: the train brake handle or the independent brake counts as braking") { + CHECK_FALSE(braking_curve::brake_acting(0.0, 0.0)); + // the handle in its release or filling positions is below running + CHECK_FALSE(braking_curve::brake_acting(-1.0, 0.0)); + CHECK(braking_curve::brake_acting(1.0, 0.0)); + CHECK(braking_curve::brake_acting(0.5, 0.0)); + // a light locomotive or a railcar alone brakes with the independent brake, the handle stays in running + CHECK(braking_curve::brake_acting(0.0, 0.25)); + CHECK(braking_curve::brake_acting(-1.0, 1.0)); + CHECK(braking_curve::brake_acting(2.0, 0.5)); +} + +TEST_CASE("braking curve: a vehicle braking with its independent brake uses the whole distance, as with the train brake") { + // before, only the train brake handle counted: a light locomotive that had put its independent brake on still + // planned, on every look, to stop short by the distance the brake takes to fill, so it slowed down too early + // and crawled the last tens of metres to the stop + flat_table const light; + auto const table{light.table()}; + auto approach{stop_at(60.0, 300.0)}; + approach.offset = 20.0; + approach.fill_horizon = 8.0; + approach.brake_applied = braking_curve::brake_acting(0.0, 0.3); + + auto const demand{braking_curve::demand(approach, &table)}; + + CHECK(demand == doctest::Approx(braking_curve::shaped_demand(60.0, 0.0, 280.0 + 0.1 / 25.92, 0.0, table))); + auto trainbrake{approach}; + trainbrake.brake_applied = braking_curve::brake_acting(1.0, 0.0); + CHECK(demand == doctest::Approx(braking_curve::demand(trainbrake, &table))); + auto released{approach}; + released.brake_applied = braking_curve::brake_acting(0.0, 0.0); + // with no brake on, the room to fill is kept, and more is asked for + CHECK(braking_curve::demand(released, &table) < demand); +} + TEST_CASE("braking curve: a train gets the demand it got before the curve moved out of the AI") { // a table that grips harder as the train slows, on a gradient; the demands were worked out with the // code of TController::adjust_desired_speed_for_braking_curve before the move (origin/master 80fd5aad) diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index a25ed392c..5630cdea1 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -8256,8 +8256,16 @@ TController::adjust_desired_speed_for_braking_curve( double const Vel ) { // 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 fillbrakea0 { bStopTargetIsPassengerStop ? 1.0 : fBrake_a0[ 0 ] }; + // once the brake is on, the room it takes to fill is behind; a vehicle running alone brakes with its + // independent brake and leaves the train brake handle in running, so that brake counts as well braking_curve::approach const approach { - Vel, VelNext, ActualProximityDist, brakingpointoffset, fAccGravity, AbsAccS, BrakeCtrlPosition > 0.0, + Vel, VelNext, ActualProximityDist, brakingpointoffset, fAccGravity, AbsAccS, + braking_curve::brake_acting( + BrakeCtrlPosition, + // IncLocalBrakeLevel() moves the independent brake handle on a vehicle without one too + ( mvOccupied->LocalBrake == TLocalBrake::PneumaticBrake || mvOccupied->LocalBrake == TLocalBrake::HydraulicBrake ) ? + mvOccupied->LocalBrakePosA : + 0.0 ), brake_response_horizon( mvOccupied, BrakeSystem, AbsAccS, fBrake_a0[ 0 ] ), brake_response_horizon( mvOccupied, BrakeSystem, 1.0, fillbrakea0 ) }; auto const deceleration { braking_curve::demand( approach, BrakeSystem == TBrakeSystem::Pneumatic ? &braketable : nullptr ) }; diff --git a/vehicle/brakingcurve.cpp b/vehicle/brakingcurve.cpp index d39ee2868..1cd1397aa 100644 --- a/vehicle/brakingcurve.cpp +++ b/vehicle/brakingcurve.cpp @@ -25,6 +25,10 @@ bool brake_table::known() const { return a0[size] > 0.0; } +bool brake_acting(double const Trainbrakeposition, double const Localbrakeposition) { + return (Trainbrakeposition > 0.0) || (Localbrakeposition > 0.0); +} + double shaped_demand(double const Velocity, double const Target, double const Distance, double const Gravity, brake_table const &Table) { auto const travel = [Velocity, Target, Gravity, &Table](double const Ratio) { diff --git a/vehicle/brakingcurve.h b/vehicle/brakingcurve.h index 6ed40d9bb..3b49597e5 100644 --- a/vehicle/brakingcurve.h +++ b/vehicle/brakingcurve.h @@ -40,11 +40,17 @@ struct approach { double offset; // the braking point that far short of it [m] double gravity; // tangential acceleration of the gradient [m/s2], negative uphill double acceleration; // present acceleration of the train [m/s2] - bool brake_applied; // the train brake handle is past running + bool brake_applied; // the brake the train slows down with is applied (brake_acting) double speedup_horizon; // how long the present acceleration lasts while speeding up [s] double fill_horizon; // how long the brake takes to fill once applied [s] }; +// whether the train is braking already, for approach::brake_applied: the train brake handle is past running +// (Trainbrakeposition above 0), or the independent brake is applied (Localbrakeposition above 0). a vehicle that +// runs alone, a light locomotive or a railcar, brakes with the independent brake and leaves the train brake +// handle in running +bool brake_acting(double Trainbrakeposition, double Localbrakeposition); + // acceleration [m/s2] to ask for now, negative to brake. with the worked out table of a pneumatic brake // (Pneumatictable) the demand follows the brake: planned from the state the train is in once the brake has // responded, along the shape of its force over speed. without one (nullptr for another brake, or a table left at