diff --git a/stdafx.h b/stdafx.h index f2b377196..164edc240 100644 --- a/stdafx.h +++ b/stdafx.h @@ -91,7 +91,7 @@ #if defined(__aarch64__) || defined(__arm64__) #define GLM_FORCE_NEON -#else +#elif defined(__AVX2__) // set by /arch:AVX2 or -mavx2 (ENABLE_AVX2); without it GLM falls back to SSE2 #define GLM_FORCE_AVX2 #endif #define GLM_FORCE_SWIZZLE diff --git a/tests/unit/test_compressor.cpp b/tests/unit/test_compressor.cpp index c5aa2fff7..4f55ce0b8 100644 --- a/tests/unit/test_compressor.cpp +++ b/tests/unit/test_compressor.cpp @@ -113,3 +113,93 @@ TEST_CASE("compressor: without a pressure switch the air over the cut-out pressu REQUIRE(vehicle->CompressorFlag); // nothing stops it CHECK(vehicle->CompressedVolume < 8.5 * 0.81); // a fifth of the air let out } + +TEST_CASE("compressor: an engine stopped before the delay passed counts the whole delay again") { + auto vehicle{compressor_vehicle(30.0)}; + vehicle->Mains = true; // engine started + run_compressor(vehicle, 20.0); + REQUIRE_FALSE(vehicle->CompressorFlag); + + vehicle->Mains = false; // engine stopped, 10 s short of the delay + run_compressor(vehicle, 1.0); + vehicle->Mains = true; + run_compressor(vehicle, 15.0); // 36 s since the first start, but only 15 s since this one + CHECK_FALSE(vehicle->CompressorFlag); + + run_compressor(vehicle, 15.1); + CHECK(vehicle->CompressorFlag); +} + +TEST_CASE("compressor: the start delay holds back a compressor switched on by hand too") { + auto vehicle{compressor_vehicle(30.0)}; + vehicle->CompressorStart = start_t::manual; + vehicle->CompressorAllow = true; // switch in the cabinet on before the engine start + vehicle->Mains = true; + + run_compressor(vehicle, 29.9); + CHECK_FALSE(vehicle->CompressorFlag); + run_compressor(vehicle, 0.2); + CHECK(vehicle->CompressorFlag); +} + +TEST_CASE("compressor: the start delay is read from the brake section") { + auto const delay{[](std::string const &Section) { + return vehicle{definition::load("wagon").set(Section, "CompressorStartDelay", 30)}->CompressorStartDelay; + }}; + CHECK(delay("Brake") == doctest::Approx(30.0)); + CHECK(delay("Cntrl") == doctest::Approx(0.0)); // the key isn't taken from the control section +} + +namespace { + +// 401Da: the compressor runs from the 110 V of the auxiliary generator driven by the engine, here the converter +// started with the main circuit, which gets up to voltage the converter start delay after the engine start +definition generator_vehicle(double const ConverterDelay, double const CompressorDelay) { + return definition::load("cab_vehicle") + .set("Param", "PWR", 370) + .set("Light", "Light", "Generator") + .set("Light", "LMaxVoltage", 110) + .set("Brake", "Vv", 0.6) + .set("Brake", "MinCP", 6.5) + .set("Brake", "MaxCP", 8.0) + .set("Brake", "CompressorSpeed", 0.003) + .set("Brake", "CompressorPower", "Converter") + .set("Brake", "CompressorStartDelay", CompressorDelay) + .set("Cntrl", "CompressorStart", "Automatic") + .set("Cntrl", "ConverterStart", "Automatic") + .set("Cntrl", "ConverterStartDelay", ConverterDelay); +} + +} // namespace + +TEST_CASE("compressor: fed from the converter it waits for the converter start delay") { + vehicle loco{generator_vehicle(30.0, 0.0)}; + REQUIRE(loco->CompressorPower == 2); + REQUIRE(loco->ConverterStartDelay == doctest::Approx(30.0)); + + loco.run(1.0); // engine off + CHECK_FALSE(loco->Power110vIsAvailable); + + loco->Mains = true; // engine started + loco.run(25.0); + CHECK_FALSE(loco->Power110vIsAvailable); + CHECK_FALSE(loco->CompressorFlag); + + loco.run(10.0); + CHECK(loco->Power110vIsAvailable); + CHECK(loco->CompressorFlag); +} + +TEST_CASE("compressor: fed from the converter the start delay counts from the converter voltage") { + vehicle loco{generator_vehicle(20.0, 10.0)}; + REQUIRE(loco->CompressorStartDelay == doctest::Approx(10.0)); + + loco.run(1.0); // engine off + loco->Mains = true; // engine started + loco.run(25.0); + REQUIRE(loco->Power110vIsAvailable); // the converter is up + CHECK_FALSE(loco->CompressorFlag); // but the compressor waits for its own delay as well + + loco.run(10.0); + CHECK(loco->CompressorFlag); +} diff --git a/tests/unit/test_oil_pump.cpp b/tests/unit/test_oil_pump.cpp new file mode 100644 index 000000000..a5f623233 --- /dev/null +++ b/tests/unit/test_oil_pump.cpp @@ -0,0 +1,55 @@ +#include "stdafx.h" +#include "doctest.h" +#include "vehicle.h" + +using test::definition; +using test::vehicle; + +// the oil pump lamp of the cab (i-oilpump) shows OilPump.is_active: the pre-lubrication pump of 401Da, which works +// before the engine start and stops once the engine runs and makes the oil pressure itself (eu07/maszyna#546) +// NOTE: the test vehicle has no diesel engine, so the pump check is called the way dizel_Update() calls it + +TEST_CASE("oil pump: the pre-lubrication pump works before the engine start and stops once the engine runs") { + vehicle loco{definition::load("cab_vehicle").set("Cntrl", "OilStart", "Manual")}; + REQUIRE(loco->OilPump.start_type == start_t::manual); + loco->Power24vIsAvailable = true; // battery on + + loco->OilPumpCheck(0.01); + CHECK_FALSE(loco->OilPump.is_active); // not switched on yet + + loco->OilPump.is_enabled = true; // pump switch on: pre-lubrication + loco->OilPumpCheck(0.01); + CHECK(loco->OilPump.is_active); + + loco->Mains = true; // engine started + loco->OilPumpCheck(0.01); + CHECK_FALSE(loco->OilPump.is_active); +} + +TEST_CASE("oil pump: the pump started with the engine start procedure stops once the engine runs") { + vehicle loco{definition::load("cab_vehicle").set("Cntrl", "OilStart", "Automatic")}; + REQUIRE(loco->OilPump.start_type == start_t::automatic); + loco->Power24vIsAvailable = true; + + loco->dizel_startup = true; // starter button pressed + loco->OilPumpCheck(0.01); + CHECK(loco->OilPump.is_active); + + loco->dizel_startup = false; // start procedure done, the pump keeps working until the engine runs + loco->OilPumpCheck(0.01); + CHECK(loco->OilPump.is_active); + + loco->Mains = true; + loco->OilPumpCheck(0.01); + CHECK_FALSE(loco->OilPump.is_active); +} + +TEST_CASE("oil pump: without power the pump and its lamp stay off") { + vehicle loco{definition::load("cab_vehicle")}; + loco->Power24vIsAvailable = false; + loco->Power110vIsAvailable = false; + + loco->OilPump.is_enabled = true; + loco->OilPumpCheck(0.01); + CHECK_FALSE(loco->OilPump.is_active); +} diff --git a/vehicle/DynObj.cpp b/vehicle/DynObj.cpp index d5f60e332..2da371e86 100644 --- a/vehicle/DynObj.cpp +++ b/vehicle/DynObj.cpp @@ -557,6 +557,33 @@ void TDynamicObject::UpdateAxle(TAnim *pAnim) pAnim->smAnimated->future_transform = glm::rotate((float)glm::radians(m_future_wheels_angle[wheel_id]), glm::vec3(1.0f, 0.0f, 0.0f)); }; +// angle of a slotted lever for given angle of the wheel, which drives the coupling rod with the pin +// all points of the coupling rod move along circles of crank radius, the lever follows the pin sliding in its slot +double TDynamicObject::slottedlever_angle( slottedlever_data const &Lever, double const Wheelangle ) { + // crank turned around X axis, the same way as the wheel + auto const wheelangle { glm::radians( Wheelangle ) }; + auto const crank { glm::dvec2( + Lever.crank.x * std::cos( wheelangle ) - Lever.crank.y * std::sin( wheelangle ), + Lever.crank.x * std::sin( wheelangle ) + Lever.crank.y * std::cos( wheelangle ) ) }; + auto const pin { Lever.pin - Lever.crank + crank }; + // angle relative to the pose of the lever in the model, which matches wheel angle 0 + return glm::degrees( std::atan2( pin.y, pin.x ) - std::atan2( Lever.pin.y, Lever.pin.x ) ); +} + +void TDynamicObject::update_slottedlevers() { + + for( auto const &lever : m_slottedlevers ) { + auto const wheelid { ( + ( lever.axle < iAnimType[ ANIM_WHEELS ] ) && ( lever.axle < static_cast( pAnimations.size() ) ) ? + pAnimations[ lever.axle ].dWheelAngle : + 1 ) }; // driving wheels and coupling rods by default + auto const angle { slottedlever_angle( lever, dWheelAngle[ wheelid ] ) }; + auto const futureangle { slottedlever_angle( lever, dWheelAngle[ wheelid ] + m_future_wheels_angle[ wheelid ] ) }; + lever.submodel->SetRotate( float3( 1, 0, 0 ), angle ); + lever.submodel->future_transform = glm::rotate( (float)glm::radians( std::remainder( futureangle - angle, 360.0 ) ), glm::vec3( 1.0f, 0.0f, 0.0f ) ); + } +} + // animacja drzwi - przesuw void TDynamicObject::UpdateDoorTranslate(TAnim *pAnim) { if( pAnim->smAnimated == nullptr ) { return; } @@ -841,6 +868,7 @@ void TDynamicObject::ABuLittleUpdate(double ObjSqrDist) animation.yUpdate( &animation ); } } + update_slottedlevers(); if( mdModel != nullptr && ObjSqrDist < 50 * 50 ) { @@ -5739,6 +5767,35 @@ void TDynamicObject::LoadMMediaFile( std::string const &TypeName, std::string co } } + else if( token == "animslottedlever:" ) { + // lever with a slot, turned by a pin on the coupling rod (e.g. speedometer drive) + // parameters: submodel name, number of axle (from animwheelprefix) driving the coupling rod, crank radius [m], + // pin position relative to the lever axis [m] and crank angle [deg] for wheel angle 0, in local (Y, Z) plane of the lever + // angle is measured from Y axis towards Z axis, i.e. in the direction of rotation around X axis + slottedlever_data lever; + int axle { 1 }; + double crankradius { 0.0 }; + double crankangle { 0.0 }; + parser.getTokens( 6, false ); + parser + >> asAnimName + >> axle + >> crankradius + >> lever.pin.x + >> lever.pin.y + >> crankangle; + lever.submodel = GetSubmodelFromName( mdModel, asAnimName ); + if( lever.submodel != nullptr ) { + lever.submodel->WillBeAnimated(); + lever.axle = std::max( 0, axle - 1 ); + lever.crank = crankradius * glm::dvec2( std::cos( glm::radians( crankangle ) ), std::sin( glm::radians( crankangle ) ) ); + m_slottedlevers.emplace_back( lever ); + } + else { + ErrorLog( "Bad model: " + asFileName + " - missed submodel " + asAnimName, logtype::model ); + } + } + else if( token == "animdoorprefix:" ) { // nazwa animowanych drzwi int i, j; diff --git a/vehicle/DynObj.h b/vehicle/DynObj.h index 577f0f020..9df2d93b6 100644 --- a/vehicle/DynObj.h +++ b/vehicle/DynObj.h @@ -316,6 +316,16 @@ private: TSubModel *sm_summer_variant {}; // submodel letniego wariantu TSubModel *sm_autumn_variant {}; // submodel jesiennego wariantu double fWahaczeAmp; + // levers with a slot, turned by a pin on the coupling rod sliding in the slot (e.g. speedometer drive of 401Da) + struct slottedlever_data { + TSubModel *submodel { nullptr }; // lever, turned around its local X axis like the wheels + int axle { 0 }; // index of the axle animation, whose crank drives the coupling rod + glm::dvec2 pin { 0.0 }; // pin position relative to the lever axis for wheel angle 0, in local (Y, Z) plane [m] + glm::dvec2 crank { 0.0 }; // crank vector for wheel angle 0, in local (Y, Z) plane [m] + }; + std::vector m_slottedlevers; + static double slottedlever_angle( slottedlever_data const &Lever, double const Wheelangle ); + void update_slottedlevers(); // Winger 160204 - pantografy double pantspeedfactor; // animacje typu przesuw diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index 9fdb97bf9..5f27f2720 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -9044,6 +9044,7 @@ bool TTrain::Update(double const Deltatime) btLampkaSprezarka.Turn(mvControlled->CompressorFlag); // mutopsitka dziala btLampkaSprezarkaOff.Turn(!mvControlled->CompressorFlag); btLampkaFuelPumpOff.Turn(!mvControlled->FuelPump.is_active); + btLampkaOilPump.Turn(mvControlled->OilPump.is_active); // pre-lubrication pump, goes off once the engine is started // boczniki // Ra: w SU45 boczniki wchodzą na ScndCtrlPos, a nie na ScndCtrlActualPos @@ -9203,6 +9204,7 @@ bool TTrain::Update(double const Deltatime) btLampkaSprezarka.Turn(false); btLampkaSprezarkaOff.Turn(false); btLampkaFuelPumpOff.Turn(false); + btLampkaOilPump.Turn(false); btLampkaBezoporowa.Turn(false); btLampkaHamowanie1zes.Turn(false); btLampkaHamienie.Turn(false); @@ -11236,6 +11238,7 @@ void TTrain::clear_cab_controls() btLampkaSprezarkaOff.Clear(); btLampkaSprezarkaBOff.Clear(); btLampkaFuelPumpOff.Clear(); + btLampkaOilPump.Clear(); btLampkaNapNastHam.Clear(); btLampkaOporyB.Clear(); btLampkaStycznB.Clear(); @@ -11658,6 +11661,7 @@ bool TTrain::initialize_button(cParser &Parser, std::string const &Label, int co {"i-compressoroff:", btLampkaSprezarkaOff}, {"i-compressorboff:", btLampkaSprezarkaBOff}, {"i-fuelpumpoff:", btLampkaFuelPumpOff}, + {"i-oilpump:", btLampkaOilPump}, {"i-voltbrake:", btLampkaNapNastHam}, {"i-resistorsb:", btLampkaOporyB}, {"i-contactorsb:", btLampkaStycznB}, diff --git a/vehicle/Train.h b/vehicle/Train.h index 009b349b4..e664c231a 100644 --- a/vehicle/Train.h +++ b/vehicle/Train.h @@ -760,6 +760,7 @@ public: // reszta może by?publiczna TButton btLampkaSprezarkaOff; TButton btLampkaSprezarkaBOff; TButton btLampkaFuelPumpOff; + TButton btLampkaOilPump; TButton btLampkaBocznik1; TButton btLampkaBocznik2; TButton btLampkaBocznik3;