From 91a7a94682ea8c3c7d8dc948878c2ff91446fc74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=B3lik=20Uszasty?= Date: Thu, 21 Mar 2019 21:47:35 +0100 Subject: [PATCH] Fix for autoreturning controller --- Driver.cpp | 4 +++- McZapkie/MOVER.h | 19 +++++++++++++++ McZapkie/Mover.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/Driver.cpp b/Driver.cpp index 8ac0229f..120e1ef1 100644 --- a/Driver.cpp +++ b/Driver.cpp @@ -4384,7 +4384,9 @@ TController::UpdateSituation(double dt) { auto const reactiontime = std::min( ReactionTime, 2.0 ); if( LastReactionTime < reactiontime ) { return; } - CheckTimeControllers(); + if (AIControllFlag) { + CheckTimeControllers(); + } LastReactionTime -= reactiontime; // Ra: nie wiem czemu ReactionTime potrafi dostać 12 sekund, to jest przegięcie, bo przeżyna STÓJ diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 782c9fd2..77ed3e3f 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -96,6 +96,7 @@ static int const maxcc = 4; /*max. ilosc odbierakow pradu*/ //static int const MainBrakeMaxPos = 10; /*max. ilosc nastaw hamulca zasadniczego*/ static int const ManualBrakePosNo = 20; /*ilosc nastaw hamulca recznego*/ static int const LightsSwitchPosNo = 16; +static int const UniversalCtrlArraySize = 32; /*max liczba pozycji uniwersalnego nastawnika*/ /*uszkodzenia toru*/ static int const dtrack_railwear = 2; @@ -572,6 +573,20 @@ struct TMotorParameters } }; +struct TUniversalCtrl +{ + int mode = 0; /*tryb pracy zadajnika - pomocnicze*/ + double MinCtrlVal = 0.0; /*minimalna wartosc nastawy*/ + double MaxCtrlVal = 0.0; /*maksymalna wartosc nastawy*/ + double SetCtrlVal = 0.0; /*docelowa wartosc nastawy*/ + double SpeedUp = 0.0; /*szybkosc zwiekszania nastawy*/ + double SpeedDown = 0.0; /*szybkosc zmniejszania nastawy*/ + int ReturnPosition = 0; /*pozycja na ktora odskakuje zadajnik*/ + int NextPosFastInc = 0; /*nastepna duza pozycja przy przechodzeniu szybkim*/ + int PrevPosFastDec = 0; /*poprzednia duza pozycja przy przechodzeniu szybkim*/ +}; +typedef TUniversalCtrl TUniversalCtrlTable[UniversalCtrlArraySize + 1]; /*tablica sterowania uniwersalnego nastawnika*/ + struct TSecuritySystem { int SystemType { 0 }; /*0: brak, 1: czuwak aktywny, 2: SHP/sygnalizacja kabinowa*/ @@ -940,6 +955,8 @@ public: bool MBrake = false; /*Czy jest hamulec reczny*/ double StopBrakeDecc = 0.0; TSecuritySystem SecuritySystem; + TUniversalCtrlTable UniCtrlList; /*lista pozycji uniwersalnego nastawnika*/ + int UniCtrlListSize = 0; /*wielkosc listy pozycji uniwersalnego nastawnika*/ /*-sekcja parametrow dla lokomotywy elektrycznej*/ TSchemeTable RList; /*lista rezystorow rozruchowych i polaczen silnikow, dla dizla: napelnienia*/ @@ -1563,6 +1580,7 @@ private: void LoadFIZ_MotorParamTable( std::string const &Input ); void LoadFIZ_Circuit( std::string const &Input ); void LoadFIZ_RList( std::string const &Input ); + void LoadFIZ_UCList(std::string const &Input); void LoadFIZ_DList( std::string const &Input ); void LoadFIZ_FFList( std::string const &Input ); void LoadFIZ_LightsList( std::string const &Input ); @@ -1577,6 +1595,7 @@ private: bool readMPTDieselEngine( std::string const &line ); bool readBPT(/*int const ln,*/ std::string const &line); //Q 20160721 bool readRList( std::string const &Input ); + bool readUCList(std::string const &Input); bool readDList( std::string const &line ); bool readFFList( std::string const &line ); bool readWWList( std::string const &line ); diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index db89fbf7..acad6b49 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -5994,6 +5994,10 @@ void TMoverParameters::CheckEIMIC(double dt) break; } break; + case 3: + eimic -= clamp(-UniCtrlList[MainCtrlPos].SetCtrlVal + eimic, 0.0, dt * UniCtrlList[MainCtrlPos].SpeedDown); //odejmuj do X + eimic += clamp(UniCtrlList[MainCtrlPos].SetCtrlVal - eimic, 0.0, dt * UniCtrlList[MainCtrlPos].SpeedUp); //dodawaj do X + eimic = clamp(eimic, UniCtrlList[MainCtrlPos].MinCtrlVal, UniCtrlList[MainCtrlPos].MaxCtrlVal); } eimic = clamp(eimic, -1.0, 1.0); } @@ -7242,7 +7246,7 @@ bool TMoverParameters::switch_physics(bool const State) // DO PRZETLUMACZENIA NA // ************************************************************************************************* bool startBPT; bool startMPT, startMPT0; -bool startRLIST; +bool startRLIST, startUCLIST; bool startDLIST, startFFLIST, startWWLIST; bool startLIGHTSLIST; int LISTLINE; @@ -7437,6 +7441,31 @@ bool TMoverParameters::readRList( std::string const &Input ) { return true; } +bool TMoverParameters::readUCList(std::string const &line) { + + cParser parser(line); + parser.getTokens(10, false); + auto idx = LISTLINE++; + if (idx >= sizeof(UniCtrlList) / sizeof(TUniversalCtrl)) { + WriteLog("Read UCList: number of entries exceeded capacity of the data table"); + return false; + } + int i = 0; + parser + >> i + >> UniCtrlList[idx].mode + >> UniCtrlList[idx].MinCtrlVal + >> UniCtrlList[idx].MaxCtrlVal + >> UniCtrlList[idx].SetCtrlVal + >> UniCtrlList[idx].SpeedUp + >> UniCtrlList[idx].SpeedDown + >> UniCtrlList[idx].ReturnPosition + >> UniCtrlList[idx].NextPosFastInc + >> UniCtrlList[idx].PrevPosFastDec; + + return true; +} + bool TMoverParameters::readDList( std::string const &line ) { cParser parser( line ); @@ -7626,6 +7655,7 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) startMPT = false; startMPT0 = false; startRLIST = false; + startUCLIST = false; startDLIST = false; startFFLIST = false; startWWLIST = false; @@ -7677,6 +7707,11 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) startRLIST = false; continue; } + if (issection("END-RL", inputline)) { + startBPT = false; + startUCLIST = false; + continue; + } if( issection( "END-DL", inputline ) ) { startBPT = false; startDLIST = false; @@ -7880,6 +7915,15 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) continue; } + if (issection("UCList:", inputline)) + { + startBPT = false; + fizlines.emplace("UCList", inputline); + startUCLIST = true; LISTLINE = 0; + LoadFIZ_RList(inputline); + continue; + } + if( issection( "DList:", inputline ) ) { startBPT = false; @@ -7929,6 +7973,10 @@ bool TMoverParameters::LoadFIZ(std::string chkpath) readRList( inputline ); continue; } + if (true == startUCLIST) { + readRList(inputline); + continue; + } if( true == startDLIST ) { readDList( inputline ); continue; @@ -8537,7 +8585,7 @@ void TMoverParameters::LoadFIZ_Cntrl( std::string const &line ) { extract_value( CoupledCtrl, "CoupledCtrl", line, "" ); extract_value( EIMCtrlType, "EIMCtrlType", line, "" ); - clamp( EIMCtrlType, 0, 2 ); + clamp( EIMCtrlType, 0, 3 ); extract_value( ScndS, "ScndS", line, "" ); // brak pozycji rownoleglej przy niskiej nastawie PSR @@ -8966,6 +9014,12 @@ void TMoverParameters::LoadFIZ_RList( std::string const &Input ) { extract_value( DynamicBrakeRes2, "DynBrakeRes2", Input, ""); } +void TMoverParameters::LoadFIZ_UCList(std::string const &Input) { + + extract_value(UniCtrlListSize, "Size", Input, ""); + +} + void TMoverParameters::LoadFIZ_DList( std::string const &Input ) { extract_value( dizel_Mmax, "Mmax", Input, "" );