From 314e7df29434bda29dd3a9da92a141163fd74df2 Mon Sep 17 00:00:00 2001 From: maj00r Date: Thu, 1 Oct 2026 21:57:18 +0200 Subject: [PATCH] braking diagnostics --- vehicle/Driver.cpp | 107 +++++++++++++++++++++++++++++++++++++++++++++ vehicle/Driver.h | 7 +++ 2 files changed, 114 insertions(+) diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 9f1b2586..6cf01f30 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -34,6 +34,7 @@ http://mozilla.org/MPL/2.0/. #define LOGSTOPS 1 #define LOGBACKSCAN 0 #define LOGPRESS 0 +#define LOGBRAKECHARGE 1 // finds point of specified track nearest to specified event. returns: distance to that point from the specified end of the track // TODO: move this to file with all generic routines, too easy to forget it's here and it may come useful @@ -5885,6 +5886,10 @@ TController::determine_consist_state() { Ready = true; // wstępnie gotowy fReady = 0.0; // założenie, że odhamowany + fConsistMaxCRP = 0.0; + fConsistMinCRP = 99.0; + fConsistBrakedCount = 0; + fConsistReleaserCount = 0; IsConsistBraked = mvOccupied->BrakeSystem == TBrakeSystem::ElectroPneumatic && false == ForcePNBrake ? mvOccupied->BrakePress > 2.0 : mvOccupied->PipePress < std::max(3.9, mvOccupied->BrakePressureActual.PipePressureVal) + 0.1; fAccGravity = 0.0; // przyspieszenie wynikające z pochylenia @@ -5914,6 +5919,9 @@ TController::determine_consist_state() { // za dużo w zbiorniku // indywidualne luzowanko vehicle->BrakeReleaser(1); +#if LOGBRAKECHARGE + ++fConsistReleaserCount; +#endif } if (bp < 0.1 && (AIControllFlag || Global.AITrainman) && false == TestFlag(vehicle->Hamulec->GetBrakeStatus(), b_dmg) // brake isn't broken && vehicle->Hamulec->GetCRP() < vehicle->PipePress - 0.1) { @@ -5923,6 +5931,9 @@ TController::determine_consist_state() { } } fReady = std::max( bp, fReady ); // szukanie najbardziej zahamowanego + fConsistMaxCRP = std::max( fConsistMaxCRP, vehicle->Hamulec->GetCRP() ); + fConsistMinCRP = std::min( fConsistMinCRP, vehicle->Hamulec->GetCRP() ); + if( bp > 0.4 ) { ++fConsistBrakedCount; } if( ( dy = p->VectorFront().y ) != 0.0 ) { // istotne tylko dla pojazdów na pochyleniu // ciężar razy składowa styczna grawitacji @@ -8028,8 +8039,104 @@ void TController::control_main_pipe() { BrakeLevelSet(gbh_FS); // don't charge the brakes too often, or we risk overcharging BrakeChargingCooldown = -1 * std::clamp(iVehicles * 3, 30, 90); +#if LOGBRAKECHARGE + fBrakeChargeFSStart = ElapsedTime; + WriteLog( "BRAKECHARGE-FIRE " + OwnerName() + + " t=" + to_string( ElapsedTime, 1 ) + + " Vel=" + to_string( mvOccupied->Vel, 1 ) + + " VelDes=" + to_string( VelDesired, 1 ) + + " VelNext=" + to_string( VelNext, 1 ) + + " AccDes=" + to_string( AccDesired, 3 ) + + " AbsAccS=" + to_string( AbsAccS, 3 ) + + " AccGrav=" + to_string( fAccGravity, 3 ) + + " fReady=" + to_string( fReady, 2 ) + + " PipeP=" + to_string( mvOccupied->PipePress, 2 ) + + " EqPipeP=" + to_string( mvOccupied->EqvtPipePress, 2 ) + + " minCRP=" + to_string( fConsistMinCRP, 2 ) + + " maxCRP=" + to_string( fConsistMaxCRP, 2 ) + + " braked=" + std::to_string( fConsistBrakedCount ) + "/" + std::to_string( iVehicles ) + + " releaser=" + std::to_string( fConsistReleaserCount ) + + " ProxDist=" + to_string( ActualProximityDist, 1 ) + + " nVeh=" + std::to_string( iVehicles ) + + " heavyCargo=" + std::to_string( IsHeavyCargoTrain ) ); +#endif } +#if LOGBRAKECHARGE + if( fBrakeChargeFSStart >= 0.0 + && BrakeCtrlPosition > gbh_FS + 0.5 ) { + WriteLog( "BRAKECHARGE-FSEND " + OwnerName() + + " t=" + to_string( ElapsedTime, 1 ) + + " durationS=" + to_string( ElapsedTime - fBrakeChargeFSStart, 2 ) + + " Vel=" + to_string( mvOccupied->Vel, 1 ) + + " AccGrav=" + to_string( fAccGravity, 3 ) + + " PipeP=" + to_string( mvOccupied->PipePress, 2 ) + + " EqPipeP=" + to_string( mvOccupied->EqvtPipePress, 2 ) + + " maxCRP=" + to_string( fConsistMaxCRP, 2 ) ); + fBrakeChargeFSStart = -1.0; + } + + { + auto const wantsdepart { mvOccupied->Vel < EU07_AI_NOMOVEMENT && VelDesired > 0.0 }; + auto const blocked { wantsdepart && ( false == Ready || fReady > 0.4 ) }; + if( blocked ) { + if( fDepartBlockStart < 0.0 ) { fDepartBlockStart = ElapsedTime; } + if( ElapsedTime - fBrakeChargeLogTimer >= 2.0 ) { + fBrakeChargeLogTimer = ElapsedTime; + WriteLog( "BRAKECHARGE-DEPART " + OwnerName() + + " t=" + to_string( ElapsedTime, 1 ) + + " blockedS=" + to_string( ElapsedTime - fDepartBlockStart, 1 ) + + " Ready=" + std::to_string( Ready ) + + " fReady=" + to_string( fReady, 2 ) + + " braked=" + std::to_string( fConsistBrakedCount ) + "/" + std::to_string( iVehicles ) + + " releaser=" + std::to_string( fConsistReleaserCount ) + + " minCRP=" + to_string( fConsistMinCRP, 2 ) + + " maxCRP=" + to_string( fConsistMaxCRP, 2 ) + + " PipeP=" + to_string( mvOccupied->PipePress, 2 ) + + " EqPipeP=" + to_string( mvOccupied->EqvtPipePress, 2 ) + + " Compr=" + to_string( mvOccupied->Compressor, 2 ) + + " BCP=" + to_string( BrakeCtrlPosition, 2 ) ); + } + } + else if( fDepartBlockStart >= 0.0 ) { + WriteLog( "BRAKECHARGE-DEPARTOK " + OwnerName() + + " t=" + to_string( ElapsedTime, 1 ) + + " blockedTotalS=" + to_string( ElapsedTime - fDepartBlockStart, 1 ) + + " fReady=" + to_string( fReady, 2 ) + + " maxCRP=" + to_string( fConsistMaxCRP, 2 ) + + " PipeP=" + to_string( mvOccupied->PipePress, 2 ) ); + fDepartBlockStart = -1.0; + } + } +#endif + +#if LOGBRAKECHARGE + if( ( std::abs( fAccGravity ) > 0.01 + || ( mvOccupied->Vel < 1.0 && fReady > 0.3 ) ) + && ElapsedTime - fBrakeChargeLogTimer >= 2.0 ) { + fBrakeChargeLogTimer = ElapsedTime; + WriteLog( "BRAKECHARGE-STATE " + OwnerName() + + " t=" + to_string( ElapsedTime, 1 ) + + " Vel=" + to_string( mvOccupied->Vel, 1 ) + + " VelDes=" + to_string( VelDesired, 1 ) + + " VelNext=" + to_string( VelNext, 1 ) + + " AccDes=" + to_string( AccDesired, 3 ) + + " AbsAccS=" + to_string( AbsAccS, 3 ) + + " AccGrav=" + to_string( fAccGravity, 3 ) + + " fReady=" + to_string( fReady, 2 ) + + " braked=" + std::to_string( fConsistBrakedCount ) + "/" + std::to_string( iVehicles ) + + " releaser=" + std::to_string( fConsistReleaserCount ) + + " minCRP=" + to_string( fConsistMinCRP, 2 ) + + " maxCRP=" + to_string( fConsistMaxCRP, 2 ) + + " BCP=" + to_string( BrakeCtrlPosition, 2 ) + + " PipeP=" + to_string( mvOccupied->PipePress, 2 ) + + " EqPipeP=" + to_string( mvOccupied->EqvtPipePress, 2 ) + + " Compr=" + to_string( mvOccupied->Compressor, 2 ) + + " Cooldown=" + to_string( BrakeChargingCooldown, 1 ) + + " ProxDist=" + to_string( ActualProximityDist, 1 ) ); + } +#endif + if( mvOccupied->Compressor < 5.0 || ( BrakeCtrlPosition < gbh_RP && mvOccupied->EqvtPipePress > (fReady < 0.25 ? 5.1 : 5.2) ) ) { diff --git a/vehicle/Driver.h b/vehicle/Driver.h index b76dbf08..c87a7994 100644 --- a/vehicle/Driver.h +++ b/vehicle/Driver.h @@ -450,6 +450,13 @@ private: double ReactionTime = 0.0; // czas reakcji Ra: czego i na co? świadomości AI double fBrakeTime = 0.0; // wpisana wartość jest zmniejszana do 0, gdy ujemna należy zmienić nastawę hamulca double BrakeChargingCooldown{}; // prevents the ai from trying to charge the train brake too frequently + double fBrakeChargeLogTimer = 0.0; + double fBrakeChargeFSStart = -1.0; + double fConsistMaxCRP = 0.0; + double fConsistMinCRP = 0.0; + int fConsistBrakedCount = 0; + int fConsistReleaserCount = 0; + double fDepartBlockStart = -1.0; TBrakeSystem BrakeSystem = TBrakeSystem::Individual; //type of main brake bool ForcePNBrake = false; //is it necessary to use PN brake instead of EP brake int DynamicBrakeTest = 0; //is it necessary to make brake test while driving