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

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

#include <iterator>
#include "table3d_typedefs.h"
#include "maths.h"
#include "table2d.h"

Go to the source code of this file.

Classes

struct  xy_pair_t
 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...
 
struct  row_col2d
 Row and column coordinates in a 2D table. More...
 

Functions

static void invalidate_cache (table3DGetValueCache *pCache)
 Invalidate the cache by resetting the last lookup values.
 
template<uint16_t xFactor, uint16_t yFactor, typename TValues , typename TXAxis , typename TYAxis >
table3d_value_t get3DTableValue (struct table3DGetValueCache *pValueCache, const TValues &values, const TXAxis &xAxis, const TYAxis &yAxis, const xy_pair_t &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, typename TValues , typename TXAxis , typename TYAxis >
table3d_value_t get3DTableValue ( struct table3DGetValueCache pValueCache,
const TValues &  values,
const TXAxis &  xAxis,
const TYAxis &  yAxis,
const xy_pair_t 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.
valuesThe table values.
xAxisThe X axis array.
yAxisThe Y axis array.
lookupValuesThe X axis and Y axis values to look up.
Returns
The interpolated value from the table.

◆ invalidate_cache()

static void invalidate_cache ( table3DGetValueCache pCache)
inlinestatic

Invalidate the cache by resetting the last lookup values.