lua pid class #3411
This commit is contained in:
parent
821276197b
commit
9b0f617664
|
@ -484,10 +484,11 @@ void configureRusefiLuaHooks(lua_State* l) {
|
||||||
.fun("set", &LuaSensor::set)
|
.fun("set", &LuaSensor::set)
|
||||||
.fun("invalidate", &LuaSensor::invalidate);
|
.fun("invalidate", &LuaSensor::invalidate);
|
||||||
|
|
||||||
|
// not enough Lua memory even to initialize Lua :(
|
||||||
|
#if defined(STM32F7) || defined(STM32H7) || EFI_UNIT_TEST
|
||||||
LuaClass<LuaPid> luaPid(l, "Pid");
|
LuaClass<LuaPid> luaPid(l, "Pid");
|
||||||
luaPid
|
luaPid
|
||||||
.ctor()
|
.ctor()
|
||||||
/*
|
|
||||||
.fun("get", &LuaPid::get)
|
.fun("get", &LuaPid::get)
|
||||||
.fun("setTarget", &LuaPid::setTarget)
|
.fun("setTarget", &LuaPid::setTarget)
|
||||||
.fun("setP", &LuaPid::setP)
|
.fun("setP", &LuaPid::setP)
|
||||||
|
@ -496,8 +497,8 @@ void configureRusefiLuaHooks(lua_State* l) {
|
||||||
.fun("setMinValue", &LuaPid::setMinValue)
|
.fun("setMinValue", &LuaPid::setMinValue)
|
||||||
.fun("setMaxValue", &LuaPid::setMaxValue)
|
.fun("setMaxValue", &LuaPid::setMaxValue)
|
||||||
.fun("reset", &LuaPid::reset)
|
.fun("reset", &LuaPid::reset)
|
||||||
*/
|
|
||||||
;
|
;
|
||||||
|
#endif
|
||||||
|
|
||||||
configureRusefiLuaUtilHooks(l);
|
configureRusefiLuaUtilHooks(l);
|
||||||
|
|
||||||
|
|
|
@ -140,3 +140,41 @@ TEST(LuaHooks, LuaSensor) {
|
||||||
// Ensure that the sensor got unregistered on teardown of the Lua interpreter
|
// Ensure that the sensor got unregistered on teardown of the Lua interpreter
|
||||||
EXPECT_FALSE(Sensor::hasSensor(SensorType::Clt));
|
EXPECT_FALSE(Sensor::hasSensor(SensorType::Clt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char* pidTest = R"(
|
||||||
|
function testFunc()
|
||||||
|
local pid = Pid.new()
|
||||||
|
pid:setP(0.5)
|
||||||
|
pid:setMinValue(-10)
|
||||||
|
pid:setMaxValue(10)
|
||||||
|
|
||||||
|
pid:setTarget(3)
|
||||||
|
|
||||||
|
-- delta is -4, output -2
|
||||||
|
if pid:get(7) ~= -2 then
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
pid:setTarget(4)
|
||||||
|
-- delta is 6, output 3
|
||||||
|
if pid:get(-2) ~= 3 then
|
||||||
|
return 2
|
||||||
|
end
|
||||||
|
|
||||||
|
pid:setTarget(0)
|
||||||
|
-- test clamping
|
||||||
|
if pid:get(100) ~= -10 then
|
||||||
|
return 3
|
||||||
|
end
|
||||||
|
|
||||||
|
if pid:get(-100) ~= 10 then
|
||||||
|
return 4
|
||||||
|
end
|
||||||
|
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
)";
|
||||||
|
|
||||||
|
TEST(LuaHooks, LuaPid) {
|
||||||
|
EXPECT_EQ(testLuaReturnsNumber(pidTest), 0);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue