fome-fw/firmware/controllers/algo/advance_map.cpp

60 lines
1.8 KiB
C++
Raw Normal View History

2014-08-29 07:52:33 -07:00
/**
* @file advance_map.c
*
* @date Mar 27, 2013
2015-01-12 15:04:10 -08:00
* @author Andrey Belomutskiy, (c) 2012-2015
2014-08-29 07:52:33 -07:00
*
* This file is part of rusEfi - see http://rusefi.com
*
* rusEfi is free software; you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "main.h"
#include "advance_map.h"
#include "interpolation.h"
// that's for 'max' function
#include "idle_controller.h"
#include "engine_configuration.h"
#include "engine_math.h"
2014-11-25 08:04:15 -08:00
EXTERN_ENGINE;
2014-08-29 07:52:33 -07:00
static Map3D1616 advanceMap;
2014-11-25 08:04:15 -08:00
float getBaseAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_S) {
2014-09-13 13:04:13 -07:00
if (cisnan(engineLoad)) {
warning(OBD_PCM_Processor_Fault, "NaN engine load");
return NAN;
}
2014-08-29 07:52:33 -07:00
efiAssert(!cisnan(engineLoad), "invalid el", NAN);
efiAssert(!cisnan(engineLoad), "invalid rpm", NAN);
2014-09-13 13:04:13 -07:00
return advanceMap.getValue(engineLoad, engineConfiguration->ignitionLoadBins, (float) rpm,
2014-08-29 07:52:33 -07:00
engineConfiguration->ignitionRpmBins);
}
2014-11-12 13:05:43 -08:00
float getAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_S) {
2014-08-29 07:52:33 -07:00
float angle;
if (isCrankingR(rpm)) {
2014-11-08 13:03:10 -08:00
angle = -engineConfiguration->crankingTimingAngle;
2014-08-29 07:52:33 -07:00
} else {
2014-11-25 08:04:15 -08:00
angle = getBaseAdvance(rpm, engineLoad PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
}
2015-01-11 21:03:57 -08:00
angle -= engineConfiguration->ignitionBaseAngle;
2014-11-25 08:04:15 -08:00
fixAngle(angle);
2014-11-25 07:03:25 -08:00
return angle;
2014-08-29 07:52:33 -07:00
}
2014-11-25 08:04:15 -08:00
void prepareTimingMap(DECLARE_ENGINE_PARAMETER_F) {
2014-08-29 07:52:33 -07:00
advanceMap.init(engineConfiguration->ignitionTable);
}