rusefi/unit_tests/afm2mapConverter.cpp

99 lines
7.3 KiB
C++

/*
* @file afm2mapConverter.cpp
*
* Helper code for https://github.com/rusefi/rusefi/issues/538 conversion RPM,MAP>MAF to RPM,MAF>MAP
* @author Andrey Belomutskiy, (c) 2012-2020
* @date Jan 20, 2018
*/
#include <stdio.h>
#include <stdlib.h>
#include "afm2mapConverter.h"
#include "table_helper.h"
#include "interpolation.h"
#include "map.h"
#define ASIZE 16
/* rpm bins */
static const float rpmBins[ASIZE] = {500.0, 1000.0, 1500.0, 2000.0, 2500.0, 3000.0, 3500.0, 4000.0, 4500.0, 5000.0, 5500.0, 6000.0, 6500.0, 7000.0, 7500.0, 8000.0};
/* Generated by TS2C on Sat Jan 20 23:46:29 EST 2018*/
static const float afr2map[ASIZE][ASIZE]= {
{/* 0 500.000 *//* 0 500.0*/4.500, /* 1 1000.0*/4.280, /* 2 1500.0*/4.100, /* 3 2000.0*/3.740, /* 4 2500.0*/3.310, /* 5 3000.0*/2.830, /* 6 3500.0*/2.510, /* 7 4000.0*/2.355, /* 8 4500.0*/2.240, /* 9 5000.0*/2.050, /* 10 5500.0*/1.940, /* 11 6000.0*/1.810, /* 12 6500.0*/1.660, /* 13 7000.0*/1.500, /* 14 7500.0*/1.350, /* 15 8000.0*/1.230, },
{/* 1 1000.000 *//* 0 500.0*/4.000, /* 1 1000.0*/3.650, /* 2 1500.0*/3.150, /* 3 2000.0*/2.750, /* 4 2500.0*/2.600, /* 5 3000.0*/2.600, /* 6 3500.0*/2.450, /* 7 4000.0*/2.200, /* 8 4500.0*/1.880, /* 9 5000.0*/1.650, /* 10 5500.0*/1.550, /* 11 6000.0*/1.450, /* 12 6500.0*/1.350, /* 13 7000.0*/1.250, /* 14 7500.0*/1.150, /* 15 8000.0*/1.050, },
{/* 2 1500.000 *//* 0 500.0*/3.600, /* 1 1000.0*/2.850, /* 2 1500.0*/2.200, /* 3 2000.0*/1.900, /* 4 2500.0*/1.600, /* 5 3000.0*/1.500, /* 6 3500.0*/1.490, /* 7 4000.0*/1.420, /* 8 4500.0*/1.360, /* 9 5000.0*/1.250, /* 10 5500.0*/1.160, /* 11 6000.0*/1.090, /* 12 6500.0*/1.040, /* 13 7000.0*/1.000, /* 14 7500.0*/0.950, /* 15 8000.0*/0.870, },
{/* 3 2000.000 *//* 0 500.0*/2.500, /* 1 1000.0*/2.100, /* 2 1500.0*/1.650, /* 3 2000.0*/1.450, /* 4 2500.0*/1.330, /* 5 3000.0*/1.200, /* 6 3500.0*/1.160, /* 7 4000.0*/1.100, /* 8 4500.0*/1.066, /* 9 5000.0*/1.020, /* 10 5500.0*/0.970, /* 11 6000.0*/0.920, /* 12 6500.0*/0.890, /* 13 7000.0*/0.850, /* 14 7500.0*/0.800, /* 15 8000.0*/0.770, },
{/* 4 2500.000 *//* 0 500.0*/2.150, /* 1 1000.0*/1.800, /* 2 1500.0*/1.500, /* 3 2000.0*/1.300, /* 4 2500.0*/1.180, /* 5 3000.0*/1.000, /* 6 3500.0*/0.980, /* 7 4000.0*/0.950, /* 8 4500.0*/0.911, /* 9 5000.0*/0.870, /* 10 5500.0*/0.750, /* 11 6000.0*/0.690, /* 12 6500.0*/0.670, /* 13 7000.0*/0.650, /* 14 7500.0*/0.630, /* 15 8000.0*/0.600, },
{/* 5 3000.000 *//* 0 500.0*/1.750, /* 1 1000.0*/1.490, /* 2 1500.0*/1.310, /* 3 2000.0*/1.140, /* 4 2500.0*/1.010, /* 5 3000.0*/0.910, /* 6 3500.0*/0.870, /* 7 4000.0*/0.777, /* 8 4500.0*/0.740, /* 9 5000.0*/0.700, /* 10 5500.0*/0.620, /* 11 6000.0*/0.580, /* 12 6500.0*/0.560, /* 13 7000.0*/0.540, /* 14 7500.0*/0.520, /* 15 8000.0*/0.500, },
{/* 6 3500.000 *//* 0 500.0*/1.550, /* 1 1000.0*/1.350, /* 2 1500.0*/1.200, /* 3 2000.0*/1.000, /* 4 2500.0*/0.910, /* 5 3000.0*/0.820, /* 6 3500.0*/0.770, /* 7 4000.0*/0.700, /* 8 4500.0*/0.667, /* 9 5000.0*/0.610, /* 10 5500.0*/0.560, /* 11 6000.0*/0.490, /* 12 6500.0*/0.470, /* 13 7000.0*/0.470, /* 14 7500.0*/0.460, /* 15 8000.0*/0.430, },
{/* 7 4000.000 *//* 0 500.0*/1.350, /* 1 1000.0*/1.200, /* 2 1500.0*/1.050, /* 3 2000.0*/0.900, /* 4 2500.0*/0.830, /* 5 3000.0*/0.760, /* 6 3500.0*/0.700, /* 7 4000.0*/0.650, /* 8 4500.0*/0.590, /* 9 5000.0*/0.540, /* 10 5500.0*/0.490, /* 11 6000.0*/0.470, /* 12 6500.0*/0.450, /* 13 7000.0*/0.440, /* 14 7500.0*/0.420, /* 15 8000.0*/0.390, },
{/* 8 4500.000 *//* 0 500.0*/1.150, /* 1 1000.0*/1.020, /* 2 1500.0*/0.920, /* 3 2000.0*/0.800, /* 4 2500.0*/0.730, /* 5 3000.0*/0.670, /* 6 3500.0*/0.630, /* 7 4000.0*/0.590, /* 8 4500.0*/0.540, /* 9 5000.0*/0.480, /* 10 5500.0*/0.450, /* 11 6000.0*/0.430, /* 12 6500.0*/0.410, /* 13 7000.0*/0.400, /* 14 7500.0*/0.380, /* 15 8000.0*/0.360, },
{/* 9 5000.000 *//* 0 500.0*/0.850, /* 1 1000.0*/0.780, /* 2 1500.0*/0.740, /* 3 2000.0*/0.680, /* 4 2500.0*/0.650, /* 5 3000.0*/0.600, /* 6 3500.0*/0.560, /* 7 4000.0*/0.530, /* 8 4500.0*/0.470, /* 9 5000.0*/0.440, /* 10 5500.0*/0.410, /* 11 6000.0*/0.400, /* 12 6500.0*/0.390, /* 13 7000.0*/0.380, /* 14 7500.0*/0.360, /* 15 8000.0*/0.340, },
{/* 10 5500.000 *//* 0 500.0*/0.750, /* 1 1000.0*/0.690, /* 2 1500.0*/0.670, /* 3 2000.0*/0.630, /* 4 2500.0*/0.590, /* 5 3000.0*/0.560, /* 6 3500.0*/0.530, /* 7 4000.0*/0.480, /* 8 4500.0*/0.450, /* 9 5000.0*/0.420, /* 10 5500.0*/0.400, /* 11 6000.0*/0.380, /* 12 6500.0*/0.370, /* 13 7000.0*/0.360, /* 14 7500.0*/0.340, /* 15 8000.0*/0.320, },
{/* 11 6000.000 *//* 0 500.0*/0.660, /* 1 1000.0*/0.620, /* 2 1500.0*/0.600, /* 3 2000.0*/0.550, /* 4 2500.0*/0.510, /* 5 3000.0*/0.480, /* 6 3500.0*/0.460, /* 7 4000.0*/0.440, /* 8 4500.0*/0.420, /* 9 5000.0*/0.390, /* 10 5500.0*/0.370, /* 11 6000.0*/0.350, /* 12 6500.0*/0.330, /* 13 7000.0*/0.320, /* 14 7500.0*/0.310, /* 15 8000.0*/0.300, },
{/* 12 6500.000 *//* 0 500.0*/0.590, /* 1 1000.0*/0.560, /* 2 1500.0*/0.540, /* 3 2000.0*/0.490, /* 4 2500.0*/0.450, /* 5 3000.0*/0.420, /* 6 3500.0*/0.410, /* 7 4000.0*/0.400, /* 8 4500.0*/0.390, /* 9 5000.0*/0.370, /* 10 5500.0*/0.350, /* 11 6000.0*/0.330, /* 12 6500.0*/0.300, /* 13 7000.0*/0.290, /* 14 7500.0*/0.290, /* 15 8000.0*/0.280, },
{/* 13 7000.000 *//* 0 500.0*/0.530, /* 1 1000.0*/0.520, /* 2 1500.0*/0.500, /* 3 2000.0*/0.430, /* 4 2500.0*/0.390, /* 5 3000.0*/0.380, /* 6 3500.0*/0.370, /* 7 4000.0*/0.360, /* 8 4500.0*/0.350, /* 9 5000.0*/0.340, /* 10 5500.0*/0.330, /* 11 6000.0*/0.320, /* 12 6500.0*/0.290, /* 13 7000.0*/0.280, /* 14 7500.0*/0.260, /* 15 8000.0*/0.260, },
{/* 14 7500.000 *//* 0 500.0*/0.480, /* 1 1000.0*/0.480, /* 2 1500.0*/0.460, /* 3 2000.0*/0.390, /* 4 2500.0*/0.350, /* 5 3000.0*/0.350, /* 6 3500.0*/0.340, /* 7 4000.0*/0.330, /* 8 4500.0*/0.320, /* 9 5000.0*/0.320, /* 10 5500.0*/0.310, /* 11 6000.0*/0.310, /* 12 6500.0*/0.290, /* 13 7000.0*/0.270, /* 14 7500.0*/0.240, /* 15 8000.0*/0.240, },
{/* 15 8000.000 *//* 0 500.0*/0.450, /* 1 1000.0*/0.450, /* 2 1500.0*/0.430, /* 3 2000.0*/0.360, /* 4 2500.0*/0.320, /* 5 3000.0*/0.330, /* 6 3500.0*/0.310, /* 7 4000.0*/0.300, /* 8 4500.0*/0.290, /* 9 5000.0*/0.290, /* 10 5500.0*/0.280, /* 11 6000.0*/0.270, /* 12 6500.0*/0.270, /* 13 7000.0*/0.260, /* 14 7500.0*/0.230, /* 15 8000.0*/0.230, },
};
float PSI_BINS[ASIZE];
/**
* see maf2map.cpp#voltageBins
*/
const float V_BINS[ASIZE] = {0.23, 0.3, 0.4, 0.5,
0.6, 0.7, 0.8, 1.0,
1.1, 1.2, 1.5, 2.0,
2.5, 3, 3.5, 4.5};
void printConvertedTable() {
printf("printConvertedTable for miata 1.6\n");
// setLinearCurve(V_BINS, ASIZE, 0.2, 4.5 , 0.01);
for (int i = 0; i< ASIZE;i++) {
printf("%f, ", V_BINS[i]);
}
printf("\n");
setLinearCurve(PSI_BINS, PSI2KPA(18), PSI2KPA(-14.5f), 0.1f); // we invert PSI scale since voltage is inverted below
for (int i = 0; i< ASIZE;i++) {
printf("%f, ", PSI_BINS[i]);
}
printf("\n");
for (int rpmIndex = 0; rpmIndex< ASIZE;rpmIndex++) {
float rpmValue = rpmBins[rpmIndex];
float vValues[ASIZE];
for (int vIndex = 0; vIndex< ASIZE;vIndex++) {
// fliping indexes to get proper ascending sorting
vValues[ASIZE - 1 - vIndex] = afr2map[vIndex][rpmIndex];
}
// printf("vArray for %f\n", rpmValue);
// for (int i = 0; i< ASIZE;i++) {
// printf("/*psi=%f v=*/ %f, ", PSI_BINS[i], vValues[i]);
// }
// printf("\n");
// float psiValues[ASIZE];
for (int vIndex = 0; vIndex< ASIZE;vIndex++) {
float volts = V_BINS[vIndex];
float psiValue = interpolate2d("conv", volts, vValues, PSI_BINS);
// psiValues[vIndex] = psiValue;
printf("/*v=%f kpa=*/ %f, ", volts, psiValue);
}
printf("\n");
}
}