rusefi-1/firmware/controllers/math/engine_math.h

89 lines
3.1 KiB
C
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file engine_math.h
*
* @date Jul 13, 2013
2017-01-03 03:05:22 -08:00
* @author Andrey Belomutskiy, (c) 2012-2017
2015-07-10 06:01:56 -07:00
*/
#ifndef ENGINE_MATH_H_
#define ENGINE_MATH_H_
#include "engine_configuration.h"
#include "trigger_structure.h"
#include "table_helper.h"
#include "engine.h"
2017-05-15 20:33:22 -07:00
void setAlgorithm(engine_load_mode_e algo DECLARE_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
2018-02-03 07:48:35 -08:00
#define assertEngineReference() efiAssertVoid(engine != NULL, "engine is NULL")
2015-07-10 06:01:56 -07:00
2016-06-30 21:02:20 -07:00
#if EFI_ENABLE_ASSERTS
2018-01-23 09:05:14 -08:00
#define assertAngleRange(angle, msg) if(angle > 10000000 || angle < -10000000) { firmwareError(ERROR_ANGLE_RANGE, "angle range %s %.2f", msg, angle);angle = 0;}
2016-06-30 21:02:20 -07:00
#else
2016-12-05 19:01:54 -08:00
#define assertAngleRange(angle, msg) {}
2016-06-30 21:02:20 -07:00
#endif
2017-06-11 11:40:29 -07:00
void setFlatInjectorLag(float value DECLARE_ENGINE_PARAMETER_SUFFIX);
2016-06-30 21:02:20 -07:00
2015-07-10 06:01:56 -07:00
/**
* @brief Shifts angle into the [0..720) range for four stroke and [0..360) for two stroke
* I guess this implementation would be faster than 'angle % engineCycle'
*/
2017-12-02 15:58:40 -08:00
#define fixAngle(angle, msg) \
2016-01-14 21:01:42 -08:00
{ \
2017-12-02 15:58:40 -08:00
if (cisnan(angle)) { \
2017-12-03 15:17:59 -08:00
firmwareError(CUSTOM_ERR_ANGLE, "angle NaN %s", msg); \
2017-12-02 15:58:40 -08:00
angle = 0; \
} \
assertAngleRange(angle, msg); \
2016-01-14 21:01:42 -08:00
float engineCycleDurationLocalCopy = ENGINE(engineCycle); \
/* todo: split this method into 'fixAngleUp' and 'fixAngleDown'*/ \
/* as a performance optimization?*/ \
while (angle < 0) \
angle += engineCycleDurationLocalCopy; \
/* todo: would 'if' work as good as 'while'? */ \
while (angle >= engineCycleDurationLocalCopy) \
angle -= engineCycleDurationLocalCopy; \
2015-11-12 09:01:26 -08:00
}
2015-07-10 06:01:56 -07:00
/**
* @return time needed to rotate crankshaft by one degree, in milliseconds.
* @deprecated use at least Us, maybe even Nt
*/
#define getOneDegreeTimeMs(rpm) (1000.0f * 60 / 360 / (rpm))
/**
* @return float, time needed to rotate crankshaft by one degree, in microseconds.
* See also engine->rpmCalculator.oneDegreeUs
*/
#define getOneDegreeTimeUs(rpm) (1000000.0f * 60 / 360 / (rpm))
/**
* @return float, time needed to rotate crankshaft by one degree, in native clicks.
*/
#define getOneDegreeTimeNt(rpm) (US2NT(1000000) * 60.0f / 360 / (rpm))
2015-09-07 06:03:24 -07:00
floatms_t getCrankshaftRevolutionTimeMs(int rpm);
2017-05-15 20:33:22 -07:00
floatms_t getEngineCycleDuration(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
2017-05-15 20:33:22 -07:00
float getEngineLoadT(DECLARE_ENGINE_PARAMETER_SIGNATURE);
2015-07-10 06:01:56 -07:00
2017-05-15 20:33:22 -07:00
floatms_t getSparkDwell(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
2017-05-15 20:33:22 -07:00
int getCylinderId(int index DECLARE_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
2017-05-15 20:33:22 -07:00
void setFuelRpmBin(float from, float to DECLARE_ENGINE_PARAMETER_SUFFIX);
void setFuelLoadBin(float from, float to DECLARE_ENGINE_PARAMETER_SUFFIX);
void setTimingRpmBin(float from, float to DECLARE_ENGINE_PARAMETER_SUFFIX);
void setTimingLoadBin(float from, float to DECLARE_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
void setSingleCoilDwell(engine_configuration_s *engineConfiguration);
#define tdcPosition() \
2017-03-01 19:18:25 -08:00
(ENGINE(triggerCentral.triggerShape.tdcPosition) + CONFIG(globalTriggerAngleOffset))
2015-07-10 06:01:56 -07:00
#endif /* ENGINE_MATH_H_ */