rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
interpolation.cpp File Reference

Detailed Description

Linear interpolation algorithms.

See test_interpolation_3d.cpp

Date
Oct 17, 2013
Author
Andrey Belomutskiy, (c) 2012-2020
Dmitry Sidin, (c) 2015

Definition in file interpolation.cpp.

Functions

float interpolateMsg (const char *msg, float x1, float y1, float x2, float y2, float x)
 Linear interpolation by two points.
 
float interpolateClampedWithValidation (float x1, float y1, float x2, float y2, float x)
 
float interpolateClamped (float x1, float y1, float x2, float y2, float x)
 

Function Documentation

◆ interpolateClamped()

float interpolateClamped ( float  x1,
float  y1,
float  x2,
float  y2,
float  x 
)

todo: use 'interpolateClampedWithValidation' wider?

See also
interpolateMsg

Definition at line 69 of file interpolation.cpp.

69 {
70 // note how we assume order of x1 and x2 here! see also interpolateClampedWithValidation
71 if (x <= x1)
72 return y1;
73 if (x >= x2)
74 return y2;
75
76 // todo: do we care with code duplication with interpolateMsg above?
77 float a = INTERPOLATION_A(x1, y1, x2, y2);
78 float b = y1 - a * x1;
79 return a * x + b;
80}

Referenced by LaunchControlBase::calculateSparkSkipRatio(), ThrottleModelBase::estimateThrottleFlow(), flexCallback(), IdleController::getClosedLoop(), getCrankingAdvance(), getCrankingFuel3(), IdleController::getIdleTimingAdjustment(), IdleController::getOpenLoop(), getRunningAdvance(), IdleController::getRunningOpenLoop(), EtbController::getSetpointEtb(), FuelComputer::getStoichiometricRatio(), IdleController::getTargetRpm(), IFuelComputer::getTCharge(), IFuelComputer::getTChargeCoefficient(), DfcoController::getTimingRetard(), AirmassVeModelBase::getVe(), interpolateClampedWithValidation(), HellaOilLevelSensor::onEdge(), setHysteresis(), LimpManager::updateRevLimit(), and updateVrThresholdPwm().

Here is the caller graph for this function:

◆ interpolateClampedWithValidation()

float interpolateClampedWithValidation ( float  x1,
float  y1,
float  x2,
float  y2,
float  x 
)

Definition at line 58 of file interpolation.cpp.

58 {
59 if (x1 >= x2) {
60 criticalError("interpolateClamped %f has to be smaller than %f", x1, x2);
61 }
62 return interpolateClamped(x1, y1, x2, y2, x);
63}
float interpolateClamped(float x1, float y1, float x2, float y2, float x)
Here is the call graph for this function:

◆ interpolateMsg()

float interpolateMsg ( const char msg,
float  x1,
float  y1,
float  x2,
float  y2,
float  x 
)

Linear interpolation by two points.

Parameters
x1key of the first point
y1value of the first point
x2key of the second point
y2value of the second point
Xkey to be interpolated
Note
For example, "interpolateMsg("", engineConfiguration.tpsMin, 0, engineConfiguration.tpsMax, 100, adc);"
See also
interpolateClamped

we could end up here for example while resetting bins while changing engine type

Definition at line 28 of file interpolation.cpp.

28 {
29 if (std::isnan(x1) || std::isnan(x2) || std::isnan(y1) || std::isnan(y2)) {
30 warning(ObdCode::CUSTOM_ERR_INTERPOLATE_1, "interpolate%s: why param", msg);
31 return NAN;
32 }
33 if (std::isnan(x)) {
34 warning(ObdCode::CUSTOM_ERR_INTERPOLATE_2, "interpolate%s: why X", msg);
35 return NAN;
36 }
37 // todo: double comparison using EPS
38 if (x1 == x2) {
39 /**
40 * we could end up here for example while resetting bins while changing engine type
41 */
42 warning(ObdCode::CUSTOM_ERR_INTERPOLATE_3, "interpolate%s: Same x1 and x2 in interpolate: %.2f/%.2f", msg, x1, x2);
43 return NAN;
44 }
45
46 // a*x1 + b = y1
47 // a*x2 + b = y2
48// efiAssertVoid(ObdCode::CUSTOM_ERR_ASSERT_VOID, x1 != x2, "no way we can interpolate");
49 float a = INTERPOLATION_A(x1, y1, x2, y2);
50 if (std::isnan(a)) {
51 warning(ObdCode::CUSTOM_ERR_INTERPOLATE_4, "interpolate%s: why a", msg);
52 return NAN;
53 }
54 float b = y1 - a * x1;
55 return a * x + b;
56}
bool warning(ObdCode code, const char *fmt,...)
@ CUSTOM_ERR_INTERPOLATE_3
@ CUSTOM_ERR_INTERPOLATE_4
@ CUSTOM_ERR_INTERPOLATE_2
@ CUSTOM_ERR_INTERPOLATE_1

Referenced by decodeTpsSentValue(), getAdvanceForRpm(), getAfr(), IFuelComputer::getTChargeCoefficient(), lua_interpolate(), and setLinearCurve().

Here is the call graph for this function:
Here is the caller graph for this function:

Go to the source code of this file.