From 7c07aa9682b2fd23d5147e8f57d53c75dd8d3563 Mon Sep 17 00:00:00 2001 From: tmj-fstate Date: Sat, 29 Jun 2019 15:02:33 +0200 Subject: [PATCH] main circuit logic enhancement, ai route scanning fix, event0 activation fix --- Driver.cpp | 21 ++++++++++++++------- Globals.cpp | 2 +- McZapkie/MOVER.h | 3 +++ McZapkie/Mover.cpp | 45 +++++++++++++++++++++++++++++++++++++++++---- Train.cpp | 18 +++++++++++------- TrkFoll.cpp | 2 +- 6 files changed, 71 insertions(+), 20 deletions(-) diff --git a/Driver.cpp b/Driver.cpp index 730ccdd3..ecf0e551 100644 --- a/Driver.cpp +++ b/Driver.cpp @@ -1392,6 +1392,12 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN fVelDes = v; } } + if( ( true == TestFlag( sSpeedTable[ i ].iFlags, spEnd ) ) + && ( mvOccupied->CategoryFlag & 1 ) ) { + // if the railway track ends here set the velnext accordingly as well + // TODO: test this with turntables and such + fNext = 0.0; + } } else if (sSpeedTable[i].iFlags & spTrack) // jeśli tor { // tor ogranicza prędkość, dopóki cały skład nie przejedzie, @@ -1403,12 +1409,6 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN // ograniczenie aktualnej prędkości aż do wyjechania za ograniczenie fVelDes = v; } - if( ( sSpeedTable[ i ].iFlags & spEnd ) - && ( mvOccupied->CategoryFlag & 1 ) ) { - // if the railway track ends here set the velnext accordingly as well - // TODO: test this with turntables and such - fNext = 0.0; - } // if (v==0.0) fAcc=-0.9; //hamowanie jeśli stop continue; // i tyle wystarczy } @@ -2271,6 +2271,12 @@ bool TController::CheckVehicles(TOrders user) // zmiana czoła przez manewry iDrivigFlags &= ~movePushPull; } + + if( ( user == Connect ) + || ( user == Disconnect ) ) { + // HACK: force route table update on consist change, new consist length means distances to points of interest are now wrong + iTableDirection = 0; + } } // blok wykonywany, gdy aktywnie prowadzi return true; } @@ -4813,7 +4819,7 @@ TController::UpdateSituation(double dt) { iCoupler = 0; // dalsza jazda manewrowa już bez łączenia iDrivigFlags &= ~moveConnect; // zdjęcie flagi doczepiania SetVelocity( 0, 0, stopJoin ); // wyłączyć przyspieszanie - CheckVehicles(); // sprawdzić światła nowego składu + CheckVehicles( Connect ); // sprawdzić światła nowego składu JumpToNextOrder(); // wykonanie następnej komendy } } @@ -5180,6 +5186,7 @@ TController::UpdateSituation(double dt) { // tylko jeśli odepnie WriteLog( mvOccupied->Name + " odczepiony." ); iVehicleCount = -2; + CheckVehicles( Disconnect ); // update trainset state } // a jak nie, to dociskać dalej } if ((mvOccupied->Vel < 0.01) && !(iDrivigFlags & movePress)) diff --git a/Globals.cpp b/Globals.cpp index c52082f0..c095ed65 100644 --- a/Globals.cpp +++ b/Globals.cpp @@ -58,7 +58,7 @@ global_settings::ConfigParse(cParser &Parser) { Parser.getTokens( 1, false ); Parser >> FieldOfView; // guard against incorrect values - FieldOfView = clamp( FieldOfView, 15.0f, 75.0f ); + FieldOfView = clamp( FieldOfView, 10.0f, 75.0f ); } else if (token == "width") { diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index f0af2996..b47fd1c3 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -1247,6 +1247,8 @@ public: /*-zmienne dla lokomotyw*/ bool Mains = false; /*polozenie glownego wylacznika*/ + double MainsInitTime{ 0.0 }; // config, initialization time (in seconds) of the main circuit after it receives power, before it can be closed + double MainsInitTimeCountdown{ 0.0 }; // current state of main circuit initialization, remaining time (in seconds) until it's ready int MainCtrlPos = 0; /*polozenie glownego nastawnika*/ int ScndCtrlPos = 0; /*polozenie dodatkowego nastawnika*/ int LightsPos = 0; @@ -1527,6 +1529,7 @@ public: bool CompressorSwitch( bool State, range_t const Notify = range_t::consist );/*! wl/wyl sprezarki*/ /*-funkcje typowe dla lokomotywy elektrycznej*/ + void MainsCheck( double const Deltatime ); void PowerCouplersCheck( double const Deltatime ); void ConverterCheck( double const Timestep ); // przetwornica void HeatingCheck( double const Timestep ); diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index b0833b13..6b3efdae 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -1309,10 +1309,11 @@ void TMoverParameters::compute_movement_( double const Deltatime ) { RunInternalCommand(); // automatyczny rozruch - if (EngineType == TEngineType::ElectricSeriesMotor) - - if (AutoRelayCheck()) - SetFlag(SoundFlag, sound::relay); + if( EngineType == TEngineType::ElectricSeriesMotor ) { + if( AutoRelayCheck() ) { + SetFlag( SoundFlag, sound::relay ); + } + } if( ( EngineType == TEngineType::DieselEngine ) || ( EngineType == TEngineType::DieselElectric ) ) { @@ -1324,6 +1325,8 @@ void TMoverParameters::compute_movement_( double const Deltatime ) { // TODO: gather and move current calculations to dedicated method TotalCurrent = 0; + // main circuit + MainsCheck( Deltatime ); // traction motors MotorBlowersCheck( Deltatime ); // uklady hamulcowe: @@ -1365,6 +1368,37 @@ void TMoverParameters::compute_movement_( double const Deltatime ) { PowerCouplersCheck( Deltatime ); } +void TMoverParameters::MainsCheck( double const Deltatime ) { + + // TODO: move other main circuit checks here + + if( MainsInitTime == 0.0 ) { return; } + + if( MainsInitTimeCountdown > 0.0 ) { + MainsInitTimeCountdown -= Deltatime; + } + // TBD, TODO: move voltage calculation to separate method and use also in power coupler state calculation? + auto localvoltage { 0.0 }; + switch( EnginePowerSource.SourceType ) { + case TPowerSource::CurrentCollector: { + localvoltage = + std::max( + localvoltage, + std::max( + PantFrontVolt, + PantRearVolt ) ); + break; + } + default: { + break; + } + } + if( ( localvoltage == 0.0 ) + && ( GetTrainsetVoltage() == 0 ) ) { + MainsInitTimeCountdown = MainsInitTime; + } +} + void TMoverParameters::PowerCouplersCheck( double const Deltatime ) { // TODO: add support for other power sources auto localvoltage { 0.0 }; @@ -2846,6 +2880,7 @@ void TMoverParameters::MainSwitch_( bool const State ) { if( ( false == State ) || ( ( ( ScndCtrlPos == 0 ) || ( EngineType == TEngineType::ElectricInductionMotor ) ) && ( ( ConvOvldFlag == false ) || ( TrainType == dt_EZT ) ) + && ( MainsInitTimeCountdown <= 0.0 ) && ( true == NoVoltRelay ) && ( true == OvervoltageRelay ) && ( LastSwitchingTime > CtrlDelay ) @@ -8959,6 +8994,8 @@ void TMoverParameters::LoadFIZ_Cntrl( std::string const &line ) { false; extract_value(SpeedCtrlAutoTurnOffFlag, "SpeedCtrlATOF", line, ""); + // main circuit + extract_value( MainsInitTime, "MainInitTime", line, "" ); // converter { std::map starts { diff --git a/Train.cpp b/Train.cpp index caafa3d6..d04a3622 100644 --- a/Train.cpp +++ b/Train.cpp @@ -448,6 +448,8 @@ dictionary_source *TTrain::GetTrainState() { // basic systems state data dict->insert( "battery", mvControlled->Battery ); dict->insert( "linebreaker", mvControlled->Mains ); + dict->insert( "main_init", ( mvControlled->MainsInitTimeCountdown < mvControlled->MainsInitTime ) && ( mvControlled->MainsInitTimeCountdown > 0.0 ) ); + dict->insert( "main_ready", ( false == mvControlled->Mains ) && ( fHVoltage > 0.0 ) && ( mvControlled->MainsInitTimeCountdown <= 0.0 ) ); dict->insert( "converter", mvControlled->ConverterFlag ); dict->insert( "converter_overload", mvControlled->ConvOvldFlag ); dict->insert( "compress", mvControlled->CompressorFlag ); @@ -5107,10 +5109,11 @@ bool TTrain::Update( double const Deltatime ) if( ( ggMainButton.GetDesiredValue() > 0.95 ) || ( ggMainOnButton.GetDesiredValue() > 0.95 ) ) { // keep track of period the line breaker button is held down, to determine when/if circuit closes - if( ( fHVoltage > 0.5 * mvControlled->EnginePowerSource.MaxVoltage ) - || ( ( mvControlled->EngineType != TEngineType::ElectricSeriesMotor ) - && ( mvControlled->EngineType != TEngineType::ElectricInductionMotor ) - && ( true == mvControlled->Battery ) ) ) { + if( ( mvControlled->MainsInitTimeCountdown <= 0.0 ) + && ( ( fHVoltage > 0.5 * mvControlled->EnginePowerSource.MaxVoltage ) + || ( ( mvControlled->EngineType != TEngineType::ElectricSeriesMotor ) + && ( mvControlled->EngineType != TEngineType::ElectricInductionMotor ) + && ( true == mvControlled->Battery ) ) ) ) { // prevent the switch from working if there's no power // TODO: consider whether it makes sense for diesel engines and such fMainRelayTimer += Deltatime; @@ -5648,9 +5651,10 @@ bool TTrain::Update( double const Deltatime ) || (true == mvControlled->Mains) ) ? true : false ) ); - // NOTE: 'off' variant uses the same test, but opposite resulting states btLampkaWylSzybkiOff.Turn( - ( ( ( m_linebreakerstate == 2 ) + ( ( ( mvControlled->MainsInitTimeCountdown > 0.0 ) + || ( fHVoltage == 0.0 ) + || ( m_linebreakerstate == 2 ) || ( true == mvControlled->Mains ) ) ? false : true ) ); @@ -5882,7 +5886,7 @@ bool TTrain::Update( double const Deltatime ) auto const *mover { tmp->MoverParameters }; btLampkaWylSzybkiB.Turn( mover->Mains ); - btLampkaWylSzybkiBOff.Turn( false == mover->Mains ); + btLampkaWylSzybkiBOff.Turn( ( false == mover->Mains ) && ( mover->MainsInitTimeCountdown <= 0.0 ) && ( fHVoltage != 0.0 ) ); btLampkaOporyB.Turn(mover->ResistorsFlagCheck()); btLampkaBezoporowaB.Turn( diff --git a/TrkFoll.cpp b/TrkFoll.cpp index 77e4e2e3..dc462a78 100644 --- a/TrkFoll.cpp +++ b/TrkFoll.cpp @@ -95,7 +95,7 @@ bool TTrackFollower::Move(double fDistance, bool bPrimary) { // przesuwanie wózka po torach o odległość (fDistance), z wyzwoleniem eventów // bPrimary=true - jest pierwszą osią w pojeździe, czyli generuje eventy i przepisuje pojazd // Ra: zwraca false, jeśli pojazd ma być usunięty - auto const ismoving { ( std::abs( fDistance ) > 0.01 ) && ( Owner->GetVelocity() > 0.01 ) }; + auto const ismoving { /* ( std::abs( fDistance ) > 0.01 ) && */ ( Owner->GetVelocity() > 0.01 ) }; fDistance *= fDirection; // dystans mnożnony przez kierunek double s; // roboczy dystans double dir; // zapamiętany kierunek do sprawdzenia, czy się zmienił