From 1aa8e879dd59959f3e4a10781778d879650e91e2 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 25 May 2023 15:17:07 -0400 Subject: [PATCH] setSparkSkipRatio limitation #5231 --- firmware/controllers/algo/launch_control.cpp | 4 +-- unit_tests/tests/test_launch.cpp | 32 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/firmware/controllers/algo/launch_control.cpp b/firmware/controllers/algo/launch_control.cpp index 44c03e4a84..962a93edd1 100644 --- a/firmware/controllers/algo/launch_control.cpp +++ b/firmware/controllers/algo/launch_control.cpp @@ -148,13 +148,13 @@ void SoftSparkLimiter::setTargetSkipRatio(float targetSkipRatio) { static tinymt32_t tinymt; bool SoftSparkLimiter::shouldSkip() { - if (targetSkipRatio == 0 || wasJustSkipped) { + if (targetSkipRatio == 0 || (!allowHardCut && wasJustSkipped)) { wasJustSkipped = false; return false; } float r = tinymt32_generate_float(&tinymt); - wasJustSkipped = r < 2 * targetSkipRatio; + wasJustSkipped = r < (allowHardCut ? 1 : 2) * targetSkipRatio; return wasJustSkipped; } diff --git a/unit_tests/tests/test_launch.cpp b/unit_tests/tests/test_launch.cpp index 4070b9cb9f..fb30c32c9d 100644 --- a/unit_tests/tests/test_launch.cpp +++ b/unit_tests/tests/test_launch.cpp @@ -193,3 +193,35 @@ TEST(LaunchControl, CompleteRun) { EXPECT_FALSE(engine->launchController.isLaunchFuelRpmRetardCondition()); } + +TEST(LaunchControl, hardSkip) { + SoftSparkLimiter hardSparkLimiter(true); + ASSERT_FALSE(hardSparkLimiter.shouldSkip()); + + + hardSparkLimiter.setTargetSkipRatio(1); + // open question if we need special handling of '1' or random would just work? + ASSERT_TRUE(hardSparkLimiter.shouldSkip()); + + int counter = 0; + hardSparkLimiter.setTargetSkipRatio(0.5); + for (int i =0;i<1000;i++) { + if (hardSparkLimiter.shouldSkip()) { + counter++; + } + + } + ASSERT_TRUE(counter > 400 && counter < 600) << "How good is random " << counter; +} + + + + + + + + + + + +