From 44df817426584eca9ec089545a5b87b0834cfa08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=B3lik=20Uszasty?= Date: Sun, 25 Oct 2020 00:47:59 +0200 Subject: [PATCH] AI can make braking test --- Driver.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ Driver.h | 6 ++++++ Globals.cpp | 6 ++++++ Globals.h | 1 + 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/Driver.cpp b/Driver.cpp index 02b10a93..b76f8976 100644 --- a/Driver.cpp +++ b/Driver.cpp @@ -2409,7 +2409,10 @@ bool TController::CheckVehicles(TOrders user) if( mvOccupied->LightsPosNo > 0 ) { pVehicle->SetLights(); } - + if (OrderCurrentGet() & (Shunt | Loose_shunt | Disconnect | Connect | Change_direction)) { + // kasowanie pamieci hamowania kontrolnego + DynamicBrakeTest = 0; + } if (AIControllFlag) { // jeśli prowadzi komputer if( true == TestFlag( OrderCurrentGet(), Obey_train ) ) { @@ -2992,7 +2995,7 @@ bool TController::ReleaseEngine() { bool TController::IncBrake() { // zwiększenie hamowania bool OK = false; - TBrakeSystem bs = BrakeSystem == TBrakeSystem::ElectroPneumatic && ForcePNBrake ? + TBrakeSystem bs = ((BrakeSystem == TBrakeSystem::ElectroPneumatic) && (ForcePNBrake)) ? TBrakeSystem::Pneumatic : BrakeSystem; switch( bs ) { case TBrakeSystem::Individual: { @@ -3969,7 +3972,7 @@ void TController::SpeedCntrl(double DesiredSpeed) void TController::SetTimeControllers() { //1. Check the type of Main Brake Handle - if (BrakeSystem == TBrakeSystem::Pneumatic) + if (BrakeSystem == TBrakeSystem::Pneumatic || ForcePNBrake) { if (mvOccupied->Handle->Time) { @@ -4171,11 +4174,11 @@ void TController::SetTimeControllers() void TController::CheckTimeControllers() { //1. Check the type of Main Brake Handle - if (BrakeSystem == TBrakeSystem::ElectroPneumatic && mvOccupied->Handle->TimeEP) + if (BrakeSystem == TBrakeSystem::ElectroPneumatic && mvOccupied->Handle->TimeEP && !ForcePNBrake) { mvOccupied->BrakeLevelSet(mvOccupied->Handle->GetPos(bh_EPN)); } - if (BrakeSystem == TBrakeSystem::Pneumatic && mvOccupied->Handle->Time) + if ((BrakeSystem == TBrakeSystem::Pneumatic || ForcePNBrake) && mvOccupied->Handle->Time) { if (BrakeCtrlPosition > 0) mvOccupied->BrakeLevelSet(mvOccupied->Handle->GetPos(bh_MB)); @@ -6493,6 +6496,44 @@ TController::UpdateSituation(double dt) { } } // koniec predkosci aktualnej + if (Global.DynamicBrakeTest) + { + // hamowanie kontrolne + if ((OrderCurrentGet() & Obey_train) && (DynamicBrakeTest == 0) && (vel < VelDesired) + && (AccDesired > 0) && (TrainParams.TTVmax >= 10.0) && (primary()) + && (vel > std::min(TrainParams.TTVmax - 2.0, 58.0))) + { + DynamicBrakeTest = 1; + DBT_VelocityBrake = vel; + DBT_VelocityRelease = vel - 8.0; + DBT_BrakingTime = ElapsedTime; + } + switch (DynamicBrakeTest) + { + case 1: + AccDesired = fAccThreshold * 1.01; + ForcePNBrake = true; + mvOccupied->EpFuseSwitch(false); + if (vel <= DBT_VelocityRelease) + { + DynamicBrakeTest = 2; + DBT_BrakingTime = ElapsedTime - DBT_BrakingTime; + DBT_MidPointAcc = AbsAccS; + DBT_ReleasingTime = ElapsedTime; + } + break; + case 2: + if (fReady < 0.5) + { + mvOccupied->EpFuseSwitch(true); + ForcePNBrake = false; + DynamicBrakeTest = 3; + DBT_ReleasingTime = ElapsedTime - DBT_ReleasingTime; + DBT_VelocityFinish = vel; + } + break; + } + } // last step sanity check, until the whole calculation is straightened out AccDesired = std::min( AccDesired, AccPreferred ); @@ -6759,7 +6800,7 @@ TController::UpdateSituation(double dt) { DecSpeed(); } } - if( mvOccupied->TrainType == dt_EZT ) { + if( (mvOccupied->TrainType == dt_EZT) && (!ForcePNBrake) ) { // właściwie, to warunek powinien być na działający EP // Ra: to dobrze hamuje EP w EZT // HACK: when going downhill be more responsive to desired deceleration diff --git a/Driver.h b/Driver.h index b19ed43b..7bb308d7 100644 --- a/Driver.h +++ b/Driver.h @@ -350,6 +350,12 @@ private: 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 + double DBT_VelocityBrake = 0; + double DBT_VelocityRelease = 0; + double DBT_VelocityFinish = 0; + double DBT_BrakingTime = 0; + double DBT_ReleasingTime = 0; + double DBT_MidPointAcc = 0; int StaticBrakeTest = 0; //is it necessary to make brake test while standing double LastReactionTime = 0.0; double fActionTime = 0.0; // czas używany przy regulacji prędkości i zamykaniu drzwi diff --git a/Globals.cpp b/Globals.cpp index 0cd9817c..849113c4 100644 --- a/Globals.cpp +++ b/Globals.cpp @@ -658,6 +658,12 @@ global_settings::ConfigParse(cParser &Parser) { Parser.getTokens(1, false); Parser >> iHiddenEvents; } + else if (token == "dynamicbraketest") + { + // enable dynamic brake tests made by AI drivers + Parser.getTokens(); + Parser >> DynamicBrakeTest; + } else if (token == "pause") { // czy po wczytaniu ma być pauza? diff --git a/Globals.h b/Globals.h index e485e882..9cfb2909 100644 --- a/Globals.h +++ b/Globals.h @@ -100,6 +100,7 @@ struct global_settings { bool bRollFix{ true }; // czy wykonać przeliczanie przechyłki bool bJoinEvents{ false }; // czy grupować eventy o tych samych nazwach int iHiddenEvents{ 1 }; // czy łączyć eventy z torami poprzez nazwę toru + bool DynamicBrakeTest { false }; //enable dynamic brake tests made by AI drivers // ui int PythonScreenUpdateRate{ 200 }; // delay between python-based screen updates, in milliseconds int iTextMode{ 0 }; // tryb pracy wyświetlacza tekstowego