only: lua_biquad.h

This commit is contained in:
Andrey 2024-06-02 16:33:12 -04:00
parent 577620e478
commit af8afafdb8
4 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,23 @@
#include "pch.h"
#include "biquad.h"
#pragma once
struct LuaBiQuad {
Biquad delegate;
float filter(float input) {
if (isFirstValue) {
delegate.cookSteadyState(input);
isFirstValue = false;
}
return delegate.filter(input);
}
void configureLowpass(float samplingFrequency, float cutoffFrequency) {
delegate.configureLowpass(samplingFrequency, cutoffFrequency);
isFirstValue = true;
}
bool isFirstValue = true;
};

View File

@ -3,6 +3,7 @@
#include "rusefi_lua.h"
#include "lua_hooks.h"
#include "lua_biquad.h"
#include "fuel_math.h"
#include "airmass.h"
#include "lua_airmass.h"
@ -744,6 +745,12 @@ BOARD_WEAK void boardConfigureLuaHooks(lua_State* lState) { }
void configureRusefiLuaHooks(lua_State* lState) {
boardConfigureLuaHooks(lState);
LuaClass<LuaBiQuad> biQuard(lState, "Biquad");
biQuard
.ctor()
.fun("filter", &LuaBiQuad::filter)
.fun("configureLowpass", &LuaBiQuad::configureLowpass);
LuaClass<Timer> luaTimer(lState, "Timer");
luaTimer
.ctor()

View File

@ -0,0 +1,38 @@
#include "pch.h"
#include "lua_biquad.h"
TEST(util, luaBiQuad100_1) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE); // LOL engineConfiguration->verboseQuad
LuaBiQuad b;
b.configureLowpass(100, 1);
ASSERT_NEAR(b.filter(25), 25, EPS2D);
ASSERT_NEAR(b.filter(20), 25, EPS2D);
ASSERT_NEAR(b.filter(20), 24.98, EPS2D);
ASSERT_NEAR(b.filter(20), 24.94, EPS2D);
}
TEST(util, luaBiQuad100_10) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE); // LOL engineConfiguration->verboseQuad
LuaBiQuad b;
b.configureLowpass(100, 10);
ASSERT_NEAR(b.filter(25), 25, EPS2D);
ASSERT_NEAR(b.filter(20), 24.69, EPS2D);
ASSERT_NEAR(b.filter(20), 23.74, EPS2D);
}
TEST(util, luaBiQuad1000_01) {
EngineTestHelper eth(engine_type_e::TEST_ENGINE); // LOL engineConfiguration->verboseQuad
LuaBiQuad b;
b.configureLowpass(1000, 0.1);
ASSERT_NEAR(b.filter(25), 23.64, EPS2D);
}

View File

@ -7,6 +7,7 @@ CPPSRC += $(PROJECT_DIR)/../unit_tests/tests/util/test_buffered_writer.cpp \
$(PROJECT_DIR)/../unit_tests/tests/util/test_closed_loop_controller.cpp \
$(PROJECT_DIR)/../unit_tests/tests/util/test_scaled_channel.cpp \
$(PROJECT_DIR)/../unit_tests/tests/util/test_timer.cpp \
$(PROJECT_DIR)/../unit_tests/tests/util/test_lua_biquad.cpp \
$(PROJECT_DIR)/../unit_tests/tests/util/test_hash.cpp \
INCDIR += $(PROJECT_DIR)/controllers/system