desiredRpmCurve = findCurveIndex("desired_rpm") desiredBoostCurve = findCurveIndex("desired_boost") initialTorqueReductionTable = findTableIndex("torque_red") sparkCutByTorqueCurve = findCurveIndex("spark_cut") sparkRetardByTorqueCurve = findCurveIndex("spark_retard") previousLaunchButtonState = 0 -- 50Hz setTickRate(50) -- p, i, d, min, max pid = Pid.new(2, 0, 0, -100, 100) function onTick() launchButtonState = getAuxAnalog(0) > 1.5 launchStrength = getAuxAnalog(1) if previousLaunchButtonState == 1 and launchButtonState == 0 then print "Exiting LC" elseif previousLaunchButtonState == 0 and launchButtonState == 1 then desiredRPM = curve(desiredRpmCurve, launchStrength) 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