From 1f3cf4fe56ee33fe38accd7903eaee401cd2d2a7 Mon Sep 17 00:00:00 2001 From: pwarszawski Date: Mon, 2 Nov 2026 16:02:06 +0100 Subject: [PATCH] AI braking: don't let the running brake test override a stop ahead adjust_desired_speed_for_braking_test runs after the target speed was worked out and overwrites AccDesired. In its third phase it holds the deceleration near fAccThreshold until the speed has dropped by 8 km/h. On a 20 per mille descent that application barely holds the speed, so the phase can last minutes, and a stop signal coming up meanwhile is ignored. In one real-time run an E186 with 19 container wagons started the test 1290 m before a stop signal, lost 7 km/h by the signal and overran it by 274 m after the emergency application. While the test runs the AI now uses whichever of the two asks for the harder braking: the test may brake harder than the route needs, never softer. Measured in real time, four runs of 32 consists each on a 20 per mille descent, on the flat and on the descent with half the rail adhesion: the test no longer runs within 600 m of a stop signal (before: down to 414 m on this branch, and 14 m with the overrun above in a build with other brake changes), no overruns, stops 8-15 m short of the signal 86, 117 and 83 of 128 (before 90, 117 and 78). --- vehicle/Driver.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 436cdb7f6..6d6c1532e 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -7927,6 +7927,10 @@ TController::adjust_desired_speed_for_braking_test() { if( false == AIControllFlag ) { return; } // TBD: add notification about braking test and enable it for human driver as well? auto const vel { DirectionalVel() }; + // what the route ahead asks for; the test may brake harder than that, never softer + auto const routeaccdesired { AccDesired }; + auto const routeaccdesiredgravity { fAccDesiredGravity }; + auto const routeveldesired { VelDesired }; switch( DynamicBrakeTest ) { case 0: { @@ -7993,6 +7997,14 @@ TController::adjust_desired_speed_for_braking_test() { break; } } + // a stop or a restriction coming up while the test runs takes precedence + if( ( DynamicBrakeTest >= 1 ) + && ( DynamicBrakeTest <= 3 ) + && ( routeaccdesired < AccDesired ) ) { + AccDesired = routeaccdesired; + fAccDesiredGravity = routeaccdesiredgravity; + VelDesired = std::min( VelDesired, routeveldesired ); + } } void