launch control for autocross on micro rusefi #4341
This commit is contained in:
parent
604a3f4ba2
commit
e91d72bba5
|
@ -23,17 +23,23 @@ function onTick()
|
|||
desiredBoost = curve(desiredBoostCurve, launchStrength)
|
||||
|
||||
initialTorqueReduction = table3d(initialTorqueReductionTable, desiredRPM, desiredBoost)
|
||||
pid:setOffset(initialTorqueReduction)
|
||||
|
||||
|
||||
print ("Running LC " ..desiredRPM .." boost=" + desiredBoost ..' t=' ..initialTorqueReduction)
|
||||
|
||||
elseif launchButtonState == 1 then
|
||||
|
||||
rpm = getSensor("RPM")
|
||||
-- handle nil RPM, todo: change firmware to avoid nil RPM
|
||||
rpm = (rpm == nil and 0 or rpm)
|
||||
|
||||
|
||||
print ("Running LC " ..desiredRPM .." boost=" + desiredBoost)
|
||||
|
||||
else
|
||||
print "Not running LC"
|
||||
setTimingAdd(0)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -395,6 +395,11 @@ struct LuaPid final {
|
|||
return m_pid.getOutput(target, input, dt);
|
||||
}
|
||||
|
||||
void setOffset(float offset) {
|
||||
m_params.offset = offset;
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
m_pid.reset();
|
||||
}
|
||||
|
@ -422,6 +427,7 @@ void configureRusefiLuaHooks(lua_State* l) {
|
|||
luaPid
|
||||
.ctor<float, float, float, float, float>()
|
||||
.fun("get", &LuaPid::get)
|
||||
.fun("setOffset", &LuaPid::setOffset)
|
||||
.fun("reset", &LuaPid::reset);
|
||||
|
||||
configureRusefiLuaUtilHooks(l);
|
||||
|
|
|
@ -90,6 +90,16 @@ TEST(LuaBasic, ExpectNumOrNilReturnsNumber) {
|
|||
)").value_or(0));
|
||||
}
|
||||
|
||||
TEST(LuaPid, Offset) {
|
||||
EXPECT_FLOAT_EQ(18.0f, testLuaReturnsNumberOrNil(R"(
|
||||
function testFunc()
|
||||
pid = Pid.new(2, 0, 0, -100, 100)
|
||||
pid:setOffset(20)
|
||||
return pid:get(20, 21)
|
||||
end
|
||||
)").value_or(0));
|
||||
}
|
||||
|
||||
TEST(LuaBasic, ExpectNumOrNilReturnsNothing) {
|
||||
// Returning nothing is generally functionally equivalent to returning nil
|
||||
EXPECT_EQ(testLuaReturnsNumberOrNil(R"(
|
||||
|
|
Loading…
Reference in New Issue