mirror of https://github.com/rusefi/rusefi.git
setSparkSkipRatio limitation #5231
This commit is contained in:
parent
902c61f9d8
commit
1aa8e879dd
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue