Speeduino
Loading...
Searching...
No Matches
Classes | Functions
table3d_interpolate.h File Reference

Functions for interpolating values from 3D tables. More...

#include "table3d_typedefs.h"
#include "maths.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  xy_values
 A pair of x and y values used for lookups in 3D tables. More...
 
struct  xy_coord2d
 2D coordinate structure for table lookups More...
 
struct  table3DGetValueCache
 Cache structure for 3D table value lookups. More...
 

Functions

static bool operator== (const xy_values &lhs, const xy_values &rhs)
 Equality operator for xy_values.
 
static void invalidate_cache (table3DGetValueCache *pCache)
 Invalidate the cache by resetting the last lookup values.
 
template<uint16_t xFactor, uint16_t yFactor>
table3d_value_t get3DTableValue (struct table3DGetValueCache *pValueCache, const table3d_dim_t axisSize, const table3d_value_t *pValues, const table3d_axis_t *pXAxis, const table3d_axis_t *pYAxis, const xy_values &lookupValues)
 Get a value from a 3D table using the specified lookup values.
 

Detailed Description

Functions for interpolating values from 3D tables.

See also
get3DTableValue

Function Documentation

◆ get3DTableValue()

template<uint16_t xFactor, uint16_t yFactor>
table3d_value_t get3DTableValue ( struct table3DGetValueCache pValueCache,
const table3d_dim_t  axisSize,
const table3d_value_t pValues,
const table3d_axis_t pXAxis,
const table3d_axis_t pYAxis,
const xy_values lookupValues 
)

Get a value from a 3D table using the specified lookup values.

Conceptually, a 3d table consists of a 2D table (rows & columns) and 2 axes. E.g. 6x6 table (tables are always square):

  • X: x axis value (e.g. RPM)
  • Y: y axis value (e.g. Load)
  • V: values of a 2d table (e.g. VE)
    YMax | V  V  V  V  V  V
    Y    | V  V  V  V  V  V
    Y    | V  V  V  V  V  V
    Y    | V  V  V  V  V  V
    Y    | V  V  V  V  V  V
    YMin | V  V  V  V  V  V
    -----+-------------------
         | X  X  X  X  X  X
         |Min            Max
    

Our overall task is to accurately interpolate a value from the table, given X and Y axis values. The x/y values will likely be in-between axis values. The function performs a 2D linear interpolation as described in: www.megamanual.com/v22manual/ve_tuner.pdf

Note
[x|y]Factor are multipliers used to convert the lookup values to the same scale as the axis values.
Background: the axes are sent from TunerStudio compressed into a byte. E.g. RPM is stored /100 (I.e. 2500->25) in the table x-axis. We can save a lot of SRAM by not rehydrating the axis values. However, we do not want to simply divide the axis lookup value by 100, as that would result in a loss of fidelity when interpolating the x-axis position: see compute_bin_position()
Instead, we:
  1. Divide the axis lookup value when searching for the axis bin (no loss of fidelity, since we're comparing bin thresholds). E.g RPM of 2153/100 -> 22
  2. Multiply the axis values when interpolating the axis position (retain fidelity). E.g. bin [20,25] becomes [2000,2500] which gives a bin position of 31% (instead of 40%)
Template Parameters
xFactorThe factor used to scale the lookup value to/from the same units as the axis values.
yFactorThe factor for the Y axis values.
Parameters
pValueCachePointer to the value cache structure.
axisSizeThe size of the axis.
pValuesPointer to the table values.
pXAxisPointer to the X axis array.
pYAxisPointer to the Y axis array.
lookupValuesThe X axis and Y axis values to look up.
Returns
The interpolated value from the table.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ invalidate_cache()

static void invalidate_cache ( table3DGetValueCache pCache)
inlinestatic

Invalidate the cache by resetting the last lookup values.

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

◆ operator==()

static bool operator== ( const xy_values lhs,
const xy_values rhs 
)
inlinestatic

Equality operator for xy_values.

Here is the call graph for this function: