From 6b82f1471aaf38b7417f28c018aa3e1e958416fc Mon Sep 17 00:00:00 2001
From: pwarszawski
Date: Mon, 2 Nov 2026 12:36:11 +0100
Subject: [PATCH] AI braking: take power off when holding the speed uphill near
a stop
Within fMaxProximityDist of a stop, going uphill, the AI holds its speed
with AccDesired = min(0, AccPreferred). control_tractive_force only cut
the power uphill when AccDesired < 0, so an AccDesired of exactly 0 kept
the controller where it was. A consist that came into that range under
power kept full power and crept up to the signal.
Holding the speed uphill on the way to a stop now asks for no speeding
up: power comes off once the train is faster than AccDesired allows.
With the current brake valves this rarely shows: on a 10 per mille climb,
four real-time runs of 32 consists each, the E186 with 25 empty 408W drew
power in 0-14 samples of the last 50 m before and 0-8 after, no overruns
either way. It surfaced once the AI predicted the ESt3 brake closer to
what the valve delivers, where the same train crept to 12 km/h from 40 m
out and overran the signal; with this change it stopped short in all runs.
---
vehicle/Driver.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp
index 2c59ddcda..436cdb7f6 100644
--- a/vehicle/Driver.cpp
+++ b/vehicle/Driver.cpp
@@ -8099,7 +8099,9 @@ void TController::control_tractive_force() {
}
else if( velocity > VelDesired + SpeedCtrlMargin
|| ( fAccGravity < -0.01 ?
- AccDesired < 0.0 :
+ AccDesired < 0.0
+ // holding the speed uphill on the way to a stop asks for no speeding up
+ || ( VelNext == 0.0 && ActualProximityDist <= fMaxProximityDist && AbsAccS > AccDesired + 0.05 ) :
AbsAccS > AccDesired + 10.05 )
|| IsAnyCouplerStretched ) {
// jak za bardzo przyspiesza albo prędkość przekroczona