setSparkSkipRatio limitation #5231

This commit is contained in:
Andrey 2023-05-25 15:17:07 -04:00
parent 902c61f9d8
commit 1aa8e879dd
2 changed files with 34 additions and 2 deletions

View File

@ -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;
}

View File

@ -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;
}