2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file engine_math.h
|
|
|
|
*
|
|
|
|
* @date Jul 13, 2013
|
2020-01-13 18:57:43 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
2019-07-08 15:02:21 -07:00
|
|
|
#pragma once
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#include "trigger_structure.h"
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void setAlgorithm(engine_load_mode_e algo);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void setFlatInjectorLag(float value);
|
2016-06-30 21:02:20 -07:00
|
|
|
|
2021-12-02 14:05:47 -08:00
|
|
|
/**
|
|
|
|
* See also wrapVvt
|
|
|
|
* TODO: replace all usages of fixAngle with wrapAngle?
|
|
|
|
* Should we make this a nice method instead of that off macro which changes parameter value?
|
|
|
|
*/
|
2022-09-15 18:27:20 -07:00
|
|
|
#define fixAngle(angle, msg, code) wrapAngle2(angle, msg, code, getEngineState()->engineCycle)
|
2021-12-02 14:05:47 -08:00
|
|
|
#define wrapAngle(angle, msg, code) fixAngle(angle, msg, code)
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2022-08-31 21:13:55 -07:00
|
|
|
// proper method avoids un-wrapped state of variables
|
|
|
|
angle_t wrapAngleMethod(angle_t param, const char *msg, obd_code_e code);
|
|
|
|
|
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))
|
|
|
|
|
2015-09-07 06:03:24 -07:00
|
|
|
floatms_t getCrankshaftRevolutionTimeMs(int rpm);
|
2021-11-16 01:15:29 -08:00
|
|
|
floatms_t getEngineCycleDuration(int rpm);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
float getFuelingLoad();
|
|
|
|
float getIgnitionLoad();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
floatms_t getSparkDwell(int rpm);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
ignition_mode_e getCurrentIgnitionMode();
|
2018-03-10 17:58:51 -08:00
|
|
|
|
2022-03-22 13:53:24 -07:00
|
|
|
size_t getCylinderId(size_t index);
|
|
|
|
size_t getNextFiringCylinderId(size_t prevCylinderId);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void setTimingRpmBin(float from, float to);
|
|
|
|
void setTimingLoadBin(float from, float to);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void setSingleCoilDwell();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-17 00:54:21 -08:00
|
|
|
// we combine trigger-defined triggerShape.tdcPosition with user-defined engineConfiguration->globalTriggerAngleOffset
|
|
|
|
// expectation is that for well-known triggers engineConfiguration->globalTriggerAngleOffset would usually be zero
|
2018-10-13 06:24:41 -07:00
|
|
|
// while for toothed wheels user would have to provide a value
|
2015-07-10 06:01:56 -07:00
|
|
|
#define tdcPosition() \
|
2021-11-17 00:54:21 -08:00
|
|
|
(TRIGGER_WAVEFORM(tdcPosition) + engineConfiguration->globalTriggerAngleOffset)
|
2021-12-05 07:46:35 -08:00
|
|
|
|
|
|
|
/** Gets phase offset for a particular cylinder's ID and number
|
|
|
|
* For example on 4 cylinder engine with firing order 1-3-4-2, this
|
|
|
|
* returns 0-180-360-540 for index 0-1-2-3
|
|
|
|
* Cylinder number is used for per-cylinder adjustment, if you have
|
|
|
|
* an odd-fire engine (v-twin, V10, some v6, etc)
|
|
|
|
*/
|
|
|
|
angle_t getCylinderAngle(uint8_t cylinderIndex, uint8_t cylinderNumber);
|