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)
|
desiredBoost = curve(desiredBoostCurve, launchStrength)
|
||||||
|
|
||||||
initialTorqueReduction = table3d(initialTorqueReductionTable, desiredRPM, desiredBoost)
|
initialTorqueReduction = table3d(initialTorqueReductionTable, desiredRPM, desiredBoost)
|
||||||
|
pid:setOffset(initialTorqueReduction)
|
||||||
|
|
||||||
|
|
||||||
print ("Running LC " ..desiredRPM .." boost=" + desiredBoost ..' t=' ..initialTorqueReduction)
|
print ("Running LC " ..desiredRPM .." boost=" + desiredBoost ..' t=' ..initialTorqueReduction)
|
||||||
|
|
||||||
elseif launchButtonState == 1 then
|
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)
|
print ("Running LC " ..desiredRPM .." boost=" + desiredBoost)
|
||||||
|
|
||||||
else
|
else
|
||||||
print "Not running LC"
|
print "Not running LC"
|
||||||
|
setTimingAdd(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -395,6 +395,11 @@ struct LuaPid final {
|
||||||
return m_pid.getOutput(target, input, dt);
|
return m_pid.getOutput(target, input, dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setOffset(float offset) {
|
||||||
|
m_params.offset = offset;
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
m_pid.reset();
|
m_pid.reset();
|
||||||
}
|
}
|
||||||
|
@ -422,6 +427,7 @@ void configureRusefiLuaHooks(lua_State* l) {
|
||||||
luaPid
|
luaPid
|
||||||
.ctor<float, float, float, float, float>()
|
.ctor<float, float, float, float, float>()
|
||||||
.fun("get", &LuaPid::get)
|
.fun("get", &LuaPid::get)
|
||||||
|
.fun("setOffset", &LuaPid::setOffset)
|
||||||
.fun("reset", &LuaPid::reset);
|
.fun("reset", &LuaPid::reset);
|
||||||
|
|
||||||
configureRusefiLuaUtilHooks(l);
|
configureRusefiLuaUtilHooks(l);
|
||||||
|
|
|
@ -90,6 +90,16 @@ TEST(LuaBasic, ExpectNumOrNilReturnsNumber) {
|
||||||
)").value_or(0));
|
)").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) {
|
TEST(LuaBasic, ExpectNumOrNilReturnsNothing) {
|
||||||
// Returning nothing is generally functionally equivalent to returning nil
|
// Returning nothing is generally functionally equivalent to returning nil
|
||||||
EXPECT_EQ(testLuaReturnsNumberOrNil(R"(
|
EXPECT_EQ(testLuaReturnsNumberOrNil(R"(
|
||||||
|
|
Loading…
Reference in New Issue