Completely bug tested and confirmed working the interpolation code

This commit is contained in:
Josh Stewart 2013-02-06 00:17:54 +11:00
parent 439a936d87
commit 066e0ee9e8
3 changed files with 60 additions and 22 deletions

View File

@ -45,6 +45,7 @@ struct table fuelTable;
void setup() {
//Begin the main crank trigger interrupt pin setup
@ -71,6 +72,7 @@ void setup() {
Serial.begin(9600);
dummyFuelTable(&fuelTable);
}
@ -88,26 +90,28 @@ void loop()
long revolutionTime = (triggerTeeth * (toothLastToothTime - toothLastMinusOneToothTime)); //The time in us that one revolution would take at current speed
rpm = US_IN_MINUTE / revolutionTime;
}
rpm = 1000;
//Get the current MAP value
int MAP = 50; //Placeholder
int MAP = 20; //Placeholder
//Perform lookup into fuel map for RPM vs MAP value
int VE = getTableValue(fuelTable, rpm, MAP);
int VE = getTableValue(fuelTable, MAP, rpm);
//From all of the above, calculate an injector pulsewidth
int pulseWidth = PW(req_fuel, VE, MAP, 100, engineInjectorDeadTime); //The 100 here is just a placeholder for any enrichment factors (Cold start, acceleration etc). To add 10% extra fuel, this would be 110
//Serial.println(VE);
Serial.print("VE: ");
Serial.println(VE);
}
else
{ getSync(); }
Serial.print("Time");
Serial.println(micros());
Serial.println(toothLastToothTime);
Serial.println(toothLastMinusOneToothTime);
Serial.println(rpm);
//Serial.println(toothLastToothTime);
//Serial.println(toothLastMinusOneToothTime);
//Serial.println(rpm);
delay(100);
}

29
table.h
View File

@ -9,8 +9,8 @@ struct table {
int values[ySize][xSize];
//int axisX[xSize];
int axisX[];
int axisY[];
int axisX[8];
int axisY[8];
//static boolean useInterp = false; //Whether or not interpolation should be used (Assuming we have enough CPU for it)
};
@ -38,12 +38,17 @@ int getTableValue(struct table fromTable, int Y, int X)
// This is because the important tables (fuel and injection) will have the highest RPM at the top of the X axis, so starting there will mean the best case occurs when the RPM is highest (And hence the CPU is needed most)
int xMin = fromTable.axisX[0];
int xMax = fromTable.axisX[fromTable.xSize-1];
int xMinValue = 0;
int xMaxValue = 0;
for (int x = fromTable.xSize-1; x > 0; x--)
{
if ( (X <= fromTable.axisX[x]) && (X >= fromTable.axisX[x-1]) )
{
xMax = fromTable.axisX[x];
xMin = fromTable.axisX[x-1];
xMaxValue = fromTable.axisX[x];
xMinValue = fromTable.axisX[x-1];
xMax = x;
xMin = x-1;
break;
}
}
@ -51,15 +56,22 @@ int getTableValue(struct table fromTable, int Y, int X)
//Loop through the Y axis bins for the min/max pair
int yMin = fromTable.axisY[0];
int yMax = fromTable.axisY[fromTable.ySize-1];
int yMinValue = 0;
int yMaxValue = 0;
for (int y = fromTable.ySize-1; y > 0; y--)
{
if ( (Y >= fromTable.axisY[y]) && (Y <= fromTable.axisY[y-1]) )
{
yMax = fromTable.axisY[y];
yMin = fromTable.axisY[y-1];
yMaxValue = fromTable.axisY[y];
yMinValue = fromTable.axisY[y-1];
yMax = y;
yMin = y-1;
break;
}
}
/*
At this point we have the 4 corners of the map where the interpolated value will fall in
@ -79,8 +91,9 @@ int getTableValue(struct table fromTable, int Y, int X)
int D = fromTable.values[yMax][xMax];
//Create some normalised position values
float p = ((float)(X - xMin)) / (xMax - xMin);
float q = ((float)(Y - yMax)) / (yMin - yMax);
//These are essentially percentages (between 0 and 1) of where the desired value falls between the nearest bins on each axis
float p = ((float)(X - xMinValue)) / (float)(xMaxValue - xMinValue);
float q = ((float)(Y - yMaxValue)) / (float)(yMinValue - yMaxValue);
float m = (1.0-p) * (1.0-q);
float n = p * (1-q);

View File

@ -43,12 +43,33 @@ VE = ( (17 * 0.2083) + (21 * 0.2083) + (15 * 0.9166) + (20 * 0.29166) ) = 18.125
*/
void dummyFuelTable()
void dummyFuelTable(struct table *myFuelTable)
{
table myFuelTable;
//table myFuelTable;
int tempXAxis[8] = {100,88,75,63,50,38,25,13};
*myFuelTable.axisY = *tempXAxis;
int tempYAxis[8] = {500,1500,2500,3000,4000,5000,6000};
*myFuelTable.axisY = *tempYAxis;
int tempXAxis[8] = {500,1500,2000,2500,3000,4000,5000,6000};
for (int x = 0; x< myFuelTable->xSize; x++) { myFuelTable->axisX[x] = tempXAxis[x]; }
//*myFuelTable->axisX = *tempXAxis;
int tempYAxis[8] = {100,88,75,63,50,38,25,13};
for (int x = 0; x< myFuelTable->ySize; x++) { myFuelTable->axisY[x] = tempYAxis[x]; }
//*myFuelTable->axisY = *tempYAxis;
//Go through the 8 rows and add the column values
int tempRow1[8] = {78,88,92,95,97,101,107,110};
int tempRow2[8] = {58,88,75,63,50,38,25,13};
int tempRow3[8] = {45,88,75,63,50,38,25,13};
int tempRow4[8] = {35,88,75,63,50,38,25,13};
int tempRow5[8] = {28,88,75,63,50,38,25,13};
int tempRow6[8] = {22,23,75,63,50,38,25,13};
int tempRow7[8] = {17,21,75,63,50,38,25,13};
int tempRow8[8] = {15,20,25,63,50,38,25,13};
for (int x = 0; x< myFuelTable->xSize; x++) { myFuelTable->values[0][x] = tempRow1[x]; }
for (int x = 0; x< myFuelTable->xSize; x++) { myFuelTable->values[1][x] = tempRow2[x]; }
for (int x = 0; x< myFuelTable->xSize; x++) { myFuelTable->values[2][x] = tempRow3[x]; }
for (int x = 0; x< myFuelTable->xSize; x++) { myFuelTable->values[3][x] = tempRow4[x]; }
for (int x = 0; x< myFuelTable->xSize; x++) { myFuelTable->values[4][x] = tempRow5[x]; }
for (int x = 0; x< myFuelTable->xSize; x++) { myFuelTable->values[5][x] = tempRow6[x]; }
for (int x = 0; x< myFuelTable->xSize; x++) { myFuelTable->values[6][x] = tempRow7[x]; }
for (int x = 0; x< myFuelTable->xSize; x++) { myFuelTable->values[7][x] = tempRow8[x]; }
}