From c47d7394c5ebf43c45869fcd44a30ec505e3e84e Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 16 Mar 2023 01:19:03 -0700 Subject: [PATCH] convert throttle model to g/s instead of kg/s --- firmware/controllers/math/throttle_model.h | 6 +- firmware/controllers/math/throttle_model.txt | 2 +- firmware/integration/rusefi_config.txt | 2 +- unit_tests/tests/test_throttle_model.cpp | 107 ++++++++++--------- 4 files changed, 59 insertions(+), 58 deletions(-) diff --git a/firmware/controllers/math/throttle_model.h b/firmware/controllers/math/throttle_model.h index 88c3215bf4..d57906fcd7 100644 --- a/firmware/controllers/math/throttle_model.h +++ b/firmware/controllers/math/throttle_model.h @@ -15,15 +15,15 @@ public: float throttlePositionForFlow(float flow, float pressureRatio, float p_up, float iat) const; protected: - // Given some TPS, what is the normalized choked flow in kg/s? + // Given some TPS, what is the normalized choked flow in g/s? virtual float effectiveArea(float tps) const = 0; - // Given some MAP, what is the most the engine can pull through a wide open throttle, in kg/s? + // Given some MAP, what is the most the engine can pull through a wide open throttle, in g/s? virtual float maxEngineFlow(float map) const = 0; }; -struct ThrottleModel : public ThrottleModelBase { +class ThrottleModel : public ThrottleModelBase { float effectiveArea(float tps) const override; float maxEngineFlow(float map) const override; }; diff --git a/firmware/controllers/math/throttle_model.txt b/firmware/controllers/math/throttle_model.txt index 10e54f83b8..9efccbe1d3 100644 --- a/firmware/controllers/math/throttle_model.txt +++ b/firmware/controllers/math/throttle_model.txt @@ -3,5 +3,5 @@ struct_no_prefix throttle_model_s int16_t autoscale throttleModelCrossoverAngle;;"%", 0.01, 0, 0, 100, 1 - float throttleEstimatedFlow;;"kg/s", 1, 0, 0, 5, 4 + float throttleEstimatedFlow;;"g/s", 1, 0, 0, 5, 2 end_struct diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index a7e3b28567..9e85d306ef 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -1703,7 +1703,7 @@ blend_table_s[IGN_BLEND_COUNT iterate] ignBlends blend_table_s[VE_BLEND_COUNT iterate] veBlends uint16_t[12] autoscale throttleEstimateEffectiveAreaBins;;"%", 0.1, 0, 0, 100, 1 -uint16_t[12] autoscale throttleEstimateEffectiveAreaValues;In units of kg/s normalized to choked flow conditions;"kg/s", 0.0001, 0, 0, 6.5, 4 +uint16_t[12] autoscale throttleEstimateEffectiveAreaValues;In units of g/s normalized to choked flow conditions;"g/s", 0.1, 0, 0, 6500, 1 end_struct diff --git a/unit_tests/tests/test_throttle_model.cpp b/unit_tests/tests/test_throttle_model.cpp index 53e776ae61..534d7c52fe 100644 --- a/unit_tests/tests/test_throttle_model.cpp +++ b/unit_tests/tests/test_throttle_model.cpp @@ -8,7 +8,8 @@ static const float throttle70mmFlowValues[] = { 0.000095, 0.002, 0.0107, 0.045, class MockThrottleModel : public ThrottleModelBase { public: float effectiveArea(float tps) const override { - return interpolate2d(tps, throttle70mmFlowBins, throttle70mmFlowValues); + // table is kg/s, function returns g/s + return 1000 * interpolate2d(tps, throttle70mmFlowBins, throttle70mmFlowValues); } MOCK_METHOD(float, maxEngineFlow, (float map), (const, override)); @@ -17,102 +18,102 @@ public: TEST(ThrottleModel, PartThrottle) { MockThrottleModel model; - EXPECT_CALL(model, maxEngineFlow(::testing::_)).WillRepeatedly([](float map) { return map / 100 * 0.5f; }); + EXPECT_CALL(model, maxEngineFlow(::testing::_)).WillRepeatedly([](float map) { return map / 100 * 500; }); // Vary throttle at constant PR/temp // 100kPa inlet // 45 kPa MAP // 0C IAT - EXPECT_NEAR(0.01056, model.estimateThrottleFlow(100, 10, 45, 0), 1e-4); - EXPECT_NEAR(0.04441, model.estimateThrottleFlow(100, 20, 45, 0), 1e-4); - EXPECT_NEAR(0.10165, model.estimateThrottleFlow(100, 30, 45, 0), 1e-4); - EXPECT_NEAR(0.18258, model.estimateThrottleFlow(100, 40, 45, 0), 1e-4); + EXPECT_NEAR( 10.56, model.estimateThrottleFlow(100, 10, 45, 0), 1e-1); + EXPECT_NEAR( 44.41, model.estimateThrottleFlow(100, 20, 45, 0), 1e-1); + EXPECT_NEAR(101.65, model.estimateThrottleFlow(100, 30, 45, 0), 1e-1); + EXPECT_NEAR(182.58, model.estimateThrottleFlow(100, 40, 45, 0), 1e-1); // Vary inlet pressure - EXPECT_NEAR(1.0 * 0.04441, model.estimateThrottleFlow(100, 20, 45, 0), 1e-4); - EXPECT_NEAR(1.5 * 0.04441, model.estimateThrottleFlow(150, 20, 45, 0), 1e-4); + EXPECT_NEAR(1.0 * 44.41, model.estimateThrottleFlow(100, 20, 45, 0), 1e-1); + EXPECT_NEAR(1.5 * 44.41, model.estimateThrottleFlow(150, 20, 45, 0), 1e-1); } TEST(ThrottleModel, InverseFlowLowPressureRatio) { MockThrottleModel model; - EXPECT_NEAR( 2.329, model.throttlePositionForFlow(0.0003, 0.3, 100, 0), 1e-2); - EXPECT_NEAR( 3.446, model.throttlePositionForFlow(0.001, 0.3, 100, 0), 1e-2); - EXPECT_NEAR( 9.674, model.throttlePositionForFlow(0.010, 0.3, 100, 0), 1e-2); - EXPECT_NEAR(29.711, model.throttlePositionForFlow(0.100, 0.3, 100, 0), 1e-2); - EXPECT_NEAR(41.395, model.throttlePositionForFlow(0.200, 0.3, 100, 0), 1e-2); - EXPECT_NEAR(57.415, model.throttlePositionForFlow(0.400, 0.3, 100, 0), 1e-2); - EXPECT_NEAR(71.255, model.throttlePositionForFlow(0.600, 0.3, 100, 0), 1e-2); - EXPECT_NEAR(77.965, model.throttlePositionForFlow(0.700, 0.3, 100, 0), 1e-2); - EXPECT_NEAR(83.323, model.throttlePositionForFlow(0.750, 0.3, 100, 0), 1e-2); - EXPECT_NEAR(85.070, model.throttlePositionForFlow(0.760, 0.3, 100, 0), 1e-2); + EXPECT_NEAR( 2.329, model.throttlePositionForFlow( 0.3, 0.3, 100, 0), 1e-2); + EXPECT_NEAR( 3.446, model.throttlePositionForFlow( 1, 0.3, 100, 0), 1e-2); + EXPECT_NEAR( 9.674, model.throttlePositionForFlow( 10, 0.3, 100, 0), 1e-2); + EXPECT_NEAR(29.711, model.throttlePositionForFlow(100, 0.3, 100, 0), 1e-2); + EXPECT_NEAR(41.395, model.throttlePositionForFlow(200, 0.3, 100, 0), 1e-2); + EXPECT_NEAR(57.415, model.throttlePositionForFlow(400, 0.3, 100, 0), 1e-2); + EXPECT_NEAR(71.255, model.throttlePositionForFlow(600, 0.3, 100, 0), 1e-2); + EXPECT_NEAR(77.965, model.throttlePositionForFlow(700, 0.3, 100, 0), 1e-2); + EXPECT_NEAR(83.323, model.throttlePositionForFlow(750, 0.3, 100, 0), 1e-2); + EXPECT_NEAR(85.070, model.throttlePositionForFlow(760, 0.3, 100, 0), 1e-2); // Throttle is maxed out here! - EXPECT_NEAR(100.00, model.throttlePositionForFlow(0.770, 0.3, 100, 0), 1e-2); - EXPECT_NEAR(100.00, model.throttlePositionForFlow(0.800, 0.3, 100, 0), 1e-2); - EXPECT_NEAR(100.00, model.throttlePositionForFlow(0.900, 0.3, 100, 0), 1e-2); + EXPECT_NEAR(100.00, model.throttlePositionForFlow(770, 0.3, 100, 0), 1e-2); + EXPECT_NEAR(100.00, model.throttlePositionForFlow(800, 0.3, 100, 0), 1e-2); + EXPECT_NEAR(100.00, model.throttlePositionForFlow(900, 0.3, 100, 0), 1e-2); } TEST(ThrottleModel, InverseFlowHighPressureRatio) { MockThrottleModel model; - EXPECT_NEAR( 2.626, model.throttlePositionForFlow(0.0003, 0.9, 100, 0), 1e-2); - EXPECT_NEAR( 4.437, model.throttlePositionForFlow(0.001, 0.9, 100, 0), 1e-2); - EXPECT_NEAR( 5.738, model.throttlePositionForFlow(0.002, 0.9, 100, 0), 1e-2); - EXPECT_NEAR( 8.571, model.throttlePositionForFlow(0.005, 0.9, 100, 0), 1e-2); - EXPECT_NEAR(11.670, model.throttlePositionForFlow(0.010, 0.9, 100, 0), 1e-2); - EXPECT_NEAR(37.473, model.throttlePositionForFlow(0.100, 0.9, 100, 0), 1e-2); - EXPECT_NEAR(51.348, model.throttlePositionForFlow(0.200, 0.9, 100, 0), 1e-2); - EXPECT_NEAR(74.510, model.throttlePositionForFlow(0.400, 0.9, 100, 0), 1e-2); - EXPECT_NEAR(87.093, model.throttlePositionForFlow(0.470, 0.9, 100, 0), 1e-2); - EXPECT_NEAR(88.737, model.throttlePositionForFlow(0.471, 0.9, 100, 0), 1e-2); + EXPECT_NEAR( 2.626, model.throttlePositionForFlow( 0.3, 0.9, 100, 0), 1e-2); + EXPECT_NEAR( 4.437, model.throttlePositionForFlow( 1, 0.9, 100, 0), 1e-2); + EXPECT_NEAR( 5.738, model.throttlePositionForFlow( 2, 0.9, 100, 0), 1e-2); + EXPECT_NEAR( 8.571, model.throttlePositionForFlow( 5, 0.9, 100, 0), 1e-2); + EXPECT_NEAR(11.670, model.throttlePositionForFlow( 10, 0.9, 100, 0), 1e-2); + EXPECT_NEAR(37.473, model.throttlePositionForFlow(100, 0.9, 100, 0), 1e-2); + EXPECT_NEAR(51.348, model.throttlePositionForFlow(200, 0.9, 100, 0), 1e-2); + EXPECT_NEAR(74.510, model.throttlePositionForFlow(400, 0.9, 100, 0), 1e-2); + EXPECT_NEAR(87.093, model.throttlePositionForFlow(470, 0.9, 100, 0), 1e-2); + EXPECT_NEAR(88.737, model.throttlePositionForFlow(471, 0.9, 100, 0), 1e-2); // Throttle is maxed out here! - EXPECT_NEAR(100.00, model.throttlePositionForFlow(0.473, 0.9, 100, 0), 1e-2); - EXPECT_NEAR(100.00, model.throttlePositionForFlow(0.500, 0.9, 100, 0), 1e-2); - EXPECT_NEAR(100.00, model.throttlePositionForFlow(0.600, 0.9, 100, 0), 1e-2); - EXPECT_NEAR(100.00, model.throttlePositionForFlow(0.700, 0.9, 100, 0), 1e-2); + EXPECT_NEAR(100.00, model.throttlePositionForFlow(473, 0.9, 100, 0), 1e-2); + EXPECT_NEAR(100.00, model.throttlePositionForFlow(500, 0.9, 100, 0), 1e-2); + EXPECT_NEAR(100.00, model.throttlePositionForFlow(600, 0.9, 100, 0), 1e-2); + EXPECT_NEAR(100.00, model.throttlePositionForFlow(700, 0.9, 100, 0), 1e-2); } TEST(ThrottleModel, SmallEngineBigThrottle) { MockThrottleModel model; - // Engine can only flow 0.2kg/s at 100kPa, much less than wide open throttle - EXPECT_CALL(model, maxEngineFlow(::testing::_)).WillRepeatedly([](float map) { return map / 100 * 0.2f; }); + // Engine can only flow 200g/s at 100kPa, much less than wide open throttle + EXPECT_CALL(model, maxEngineFlow(::testing::_)).WillRepeatedly([](float map) { return map / 100 * 200; }); // v part throttle model v - EXPECT_NEAR(0.082f, model.estimateThrottleFlow(100, 40, 95, 0), 1e-3); - EXPECT_NEAR(0.138f, model.estimateThrottleFlow(100, 50, 95, 0), 1e-3); + EXPECT_NEAR( 81.9, model.estimateThrottleFlow(100, 40, 95, 0), 1e-1); + EXPECT_NEAR(138.0, model.estimateThrottleFlow(100, 50, 95, 0), 1e-1); // ^ part throttle model ^ // this engine does 0.95PR at 59% throttle, as the throttle is very big for the engine // v blend from part throttle to WOT v - EXPECT_NEAR(0.190f, model.estimateThrottleFlow(100, 60, 95, 0), 1e-3); - EXPECT_NEAR(0.193f, model.estimateThrottleFlow(100, 70, 95, 0), 1e-3); - EXPECT_NEAR(0.195f, model.estimateThrottleFlow(100, 80, 95, 0), 1e-3); - EXPECT_NEAR(0.198f, model.estimateThrottleFlow(100, 90, 95, 0), 1e-3); + EXPECT_NEAR(190.2, model.estimateThrottleFlow(100, 60, 95, 0), 1e-1); + EXPECT_NEAR(192.6, model.estimateThrottleFlow(100, 70, 95, 0), 1e-1); + EXPECT_NEAR(195.1, model.estimateThrottleFlow(100, 80, 95, 0), 1e-1); + EXPECT_NEAR(197.5, model.estimateThrottleFlow(100, 90, 95, 0), 1e-1); // ^ blend from part throttle to WOT ^ // v WOT v - EXPECT_NEAR(0.20f, model.estimateThrottleFlow(100, 100, 95, 0), 1e-3); + EXPECT_NEAR(200.0, model.estimateThrottleFlow(100, 100, 95, 0), 1e-3); } TEST(ThrottleModel, BigEngineSmallThrottle) { MockThrottleModel model; - // Big engine can flow 2g/s, much more than wide open throttle will support - EXPECT_CALL(model, maxEngineFlow(::testing::_)).WillRepeatedly([](float map) { return map / 100 * 2; }); + // Big engine can flow 2000g/s, much more than wide open throttle will support + EXPECT_CALL(model, maxEngineFlow(::testing::_)).WillRepeatedly([](float map) { return map / 100 * 2000; }); // v part throttle model v - EXPECT_NEAR(0.082f, model.estimateThrottleFlow(100, 40, 95, 0), 1e-3); - EXPECT_NEAR(0.138f, model.estimateThrottleFlow(100, 50, 95, 0), 1e-3); - EXPECT_NEAR(0.194f, model.estimateThrottleFlow(100, 60, 95, 0), 1e-3); - EXPECT_NEAR(0.261f, model.estimateThrottleFlow(100, 70, 95, 0), 1e-3); - EXPECT_NEAR(0.327f, model.estimateThrottleFlow(100, 80, 95, 0), 1e-3); - EXPECT_NEAR(0.343f, model.estimateThrottleFlow(100, 90, 95, 0), 1e-3); - EXPECT_NEAR(0.343f, model.estimateThrottleFlow(100, 100, 95, 0), 1e-3); + EXPECT_NEAR( 82.0, model.estimateThrottleFlow(100, 40, 95, 0), 1e-1); + EXPECT_NEAR(138.0, model.estimateThrottleFlow(100, 50, 95, 0), 1e-1); + EXPECT_NEAR(194.1, model.estimateThrottleFlow(100, 60, 95, 0), 1e-1); + EXPECT_NEAR(261.0, model.estimateThrottleFlow(100, 70, 95, 0), 1e-1); + EXPECT_NEAR(327.9, model.estimateThrottleFlow(100, 80, 95, 0), 1e-1); + EXPECT_NEAR(343.4, model.estimateThrottleFlow(100, 90, 95, 0), 1e-1); + EXPECT_NEAR(343.4, model.estimateThrottleFlow(100, 100, 95, 0), 1e-1); // ^ part throttle model ^ }