Map3D accepts any scaled_channel type (#3712)

* Map3D accepts any scaled_channel type

* consistency

* reinstate test

* fix ratio
This commit is contained in:
Matthew Kennedy 2021-12-21 15:52:46 -08:00 committed by GitHub
parent 45eab7f8a0
commit 0f133f88a1
2 changed files with 21 additions and 23 deletions

View File

@ -25,7 +25,7 @@ public:
/**
* this helper class brings together 3D table with two 2D axis curves
*/
template<int TColNum, int TRowNum, typename TValue, typename TColumn, typename TRow, typename TValueMultiplier = efi::ratio<1>>
template<int TColNum, int TRowNum, typename TValue, typename TColumn, typename TRow>
class Map3D : public ValueProvider3D {
public:
template <typename TValueInit, typename TRowInit, typename TColumnInit>
@ -47,7 +47,7 @@ public:
return interpolate3d(*m_values,
*m_rowBins, yRow * m_rowMult,
*m_columnBins, xColumn * m_colMult) *
TValueMultiplier::asFloat();
m_valueMult;
}
void setAll(TValue value) {
@ -55,28 +55,27 @@ public:
for (size_t r = 0; r < TRowNum; r++) {
for (size_t c = 0; c < TColNum; c++) {
(*m_values)[r][c] = value / TValueMultiplier::asFloat();
(*m_values)[r][c] = value / m_valueMult;
}
}
}
private:
template <int TMult>
void initValues(scaled_channel<TValue, TMult> (&table)[TRowNum][TColNum]) {
static_assert(TValueMultiplier::den == TMult);
static_assert(TValueMultiplier::num == 1);
template <int TMult, int TDiv>
void initValues(scaled_channel<TValue, TMult, TDiv> (&table)[TRowNum][TColNum]) {
m_values = reinterpret_cast<TValue (*)[TRowNum][TColNum]>(&table);
m_valueMult = 1 / efi::ratio<TMult, TDiv>::asFloat();
}
void initValues(TValue (&table)[TRowNum][TColNum]) {
m_values = &table;
m_valueMult = 1;
}
template <int TRowMult, int TRowDiv>
void initRows(const scaled_channel<TRow, TRowMult, TRowDiv> (&rowBins)[TRowNum]) {
m_rowBins = reinterpret_cast<const TRow (*)[TRowNum]>(&rowBins);
m_rowMult = (float)TRowMult / TRowDiv;
m_rowMult = efi::ratio<TRowMult, TRowDiv>::asFloat();
}
void initRows(const TRow (&rowBins)[TRowNum]) {
@ -87,7 +86,7 @@ private:
template <int TColMult, int TColDiv>
void initCols(const scaled_channel<TColumn, TColMult, TColDiv> (&columnBins)[TColNum]) {
m_columnBins = reinterpret_cast<const TColumn (*)[TColNum]>(&columnBins);
m_colMult = (float)TColMult / TColDiv;
m_colMult = efi::ratio<TColMult, TColDiv>::asFloat();
}
void initCols(const TColumn (&columnBins)[TColNum]) {
@ -115,16 +114,17 @@ private:
float m_rowMult = 1;
float m_colMult = 1;
float m_valueMult = 1;
};
typedef Map3D<FUEL_RPM_COUNT, FUEL_LOAD_COUNT, uint8_t, uint16_t, uint16_t, efi::ratio<1, PACK_MULT_LAMBDA_CFG>> lambda_Map3D_t;
typedef Map3D<FUEL_RPM_COUNT, FUEL_LOAD_COUNT, uint8_t, uint16_t, uint16_t> lambda_Map3D_t;
typedef Map3D<FUEL_RPM_COUNT, FUEL_LOAD_COUNT, float, uint16_t, uint16_t> fuel_Map3D_t;
typedef Map3D<BARO_CORR_SIZE, BARO_CORR_SIZE, float, float, float> baroCorr_Map3D_t;
typedef Map3D<PEDAL_TO_TPS_SIZE, PEDAL_TO_TPS_SIZE, uint8_t, uint8_t, uint8_t> pedal2tps_t;
typedef Map3D<BOOST_RPM_COUNT, BOOST_LOAD_COUNT, uint8_t, uint8_t, uint8_t, efi::ratio<LOAD_1_BYTE_PACKING_MULT>> boostOpenLoop_Map3D_t;
typedef Map3D<BOOST_RPM_COUNT, BOOST_LOAD_COUNT, uint8_t, uint8_t, uint8_t> boostOpenLoop_Map3D_t;
typedef Map3D<BOOST_RPM_COUNT, BOOST_LOAD_COUNT, uint8_t, uint8_t, uint8_t> boostClosedLoop_Map3D_t;
typedef Map3D<GPPWM_RPM_COUNT, GPPWM_LOAD_COUNT, uint8_t, uint8_t, uint8_t> gppwm_Map3D_t;
typedef Map3D<FUEL_RPM_COUNT, FUEL_LOAD_COUNT, uint16_t, uint16_t, uint16_t, efi::ratio<1, PACK_MULT_MAP_ESTIMATE>> mapEstimate_Map3D_t;
typedef Map3D<FUEL_RPM_COUNT, FUEL_LOAD_COUNT, uint16_t, uint16_t, uint16_t> mapEstimate_Map3D_t;
/**
* @param precision for example '0.1' for one digit fractional part. Default to 0.01, two digits.

View File

@ -18,16 +18,12 @@ float mafBins[4] = { 1, 2, 3, 4 };
scaled_channel<int, 10> mafBinsScaledInt[4] = { 1, 2, 3, 4 };
scaled_channel<uint8_t, 10> mafBinsScaledByte[4] = { 1, 2, 3, 4 };
scaled_channel<uint8_t, 1, 50> mapScaledByByte;
/*
= {
scaled_channel<uint32_t, 10000, 3> mapScaledChannel[4][5] = {
{ 1, 2, 3, 4, 4},
{ 2, 3, 4, 200, 200 },
{ 3, 4, 200, 500, 500 },
{ 4, 5, 300, 600, 600 },
};
*/
float map[4][5] = {
{ 1, 2, 3, 4, 4},
@ -39,11 +35,6 @@ float map[4][5] = {
#define EXPECT_NEAR_M4(a, b) EXPECT_NEAR(a, b, 1e-4)
static float getValue(float rpm, float maf) {
Map3D<5, 4, uint8_t, float, float> x0;
// x0.init(mapScaledByByte, mafBins, rpmBins);
// float result0 = x0.getValue(rpm, maf);
Map3D<5, 4, float, float, float> x1;
x1.init(map, mafBins, rpmBins);
float result1 = x1.getValue(rpm, maf);
@ -72,6 +63,12 @@ static float getValue(float rpm, float maf) {
);
EXPECT_NEAR_M4(result1, result5);
// Test with values stored in scaled bytes
Map3D<5, 4, uint32_t, float, float> x6;
x6.init(mapScaledChannel, mafBins, rpmBins);
float result6 = x6.getValue(rpm, maf);
EXPECT_NEAR(result1, result6, 1e-3);
return result1;
}
@ -84,6 +81,7 @@ static void newTestToComfirmInterpolation() {
//______|__2|__3|_LOAD
map[1][2] = 10;
mapScaledChannel[1][2] = 10;
// let's start by testing corners