I understand how to use a simple array to to increment through the array's position.
say 1, 2, 3, 4,
However I am looking into fuel injection for remote control lawnmower.
I plan to have the X axis represent RPM
and Y axis to represent MAP sensor
The MAP sensor value would be mapped 0-7
% increase injector PWM
MAP-----------------------------------------------------------------------------------------------
0///////20/////////20////////20/////////20//////40////////50///////50//////48
----------------------------------------------------------------------------------------------------
1///////20/////////20////////20/////////33//////43////////54///////54//////51
----------------------------------------------------------------------------------------------------
2///////20/////////20////////22/////////35//////47////////59///////59//////56
----------------------------------------------------------------------------------------------------
3///////20/////////20////////24/////////37//////50////////63///////63//////60
----------------------------------------------------------------------------------------------------
4///////20/////////20////////26/////////39//////53////////66///////66//////63
----------------------------------------------------------------------------------------------------
5///////20/////////20////////28/////////41//////57////////72///////72//////68
----------------------------------------------------------------------------------------------------
6///////20/////////20////////30/////////43//////60////////75///////75//////71
----------------------------------------------------------------------------------------------------
7///////20/////////20////////32/////////45//////63////////79///////79//////75
----------------------------------------------------------------------------------------------------
RPM///700 //////1200///// 1600/////1900////2300////2600/////3000///3300
so say the RPM is >3K but <3.3K
and the engine is under medium load with a MAP reading of 4
the returned value would be 66
As alaways thanks for the help!
8X8 Table (array)
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- jcgoodman
- Posts: 107
- Joined: Thu Jan 23, 2014 6:03 pm
Re: 8X8 Table (array)
If you're willing to tweak the RPM values a bit so they're evenly spaced, you can use the "Map" function:
http://arduino.cc/en/reference/map#.Uv8HK179pts
Otherwise it's if/else hell.
http://arduino.cc/en/reference/map#.Uv8HK179pts
Otherwise it's if/else hell.
-
- Posts: 28
- Joined: Sun Sep 01, 2013 12:36 pm
Re: 8X8 Table (array)
i believe what you are suggesting will just change the range of a set of numbers.
say the x axis had an original range of 0-100 it would now output 100-200 mapped out.
and the same could be said for the Y axis.
I do not believe it will not work as a coordinate grid system and return the value of X,Y.
but your if else hell statement might have to be the way to go.
say the x axis had an original range of 0-100 it would now output 100-200 mapped out.
and the same could be said for the Y axis.
I do not believe it will not work as a coordinate grid system and return the value of X,Y.
but your if else hell statement might have to be the way to go.
- jcgoodman
- Posts: 107
- Joined: Thu Jan 23, 2014 6:03 pm
Re: 8X8 Table (array)
Sorry, I only gave you a hint for the process. You want something like this:
Just realized: you never said, but I assume you're working with an Arduino here. Same basic idea with other languages, but you don't get the "map" function and have to use if/else to figure out the column value.
Code: Select all
byte table[8][8] = {{20,20,20,20,40,50,50,48},{ ... and so on ... } };
byte row, column;
column = map(rpmvalue,700,3300,0,7); // Tweak 3300 and 700 as needed
row = mapvalue;
return table[row][column];
- zener
- Posts: 4567
- Joined: Sat Feb 21, 2009 2:38 am
Re: 8X8 Table (array)
It may compile the same anyway.
-
- Posts: 28
- Joined: Sun Sep 01, 2013 12:36 pm
Re: 8X8 Table (array)
Sorry, yes i am using an Arduino.
I think I understand what you are saying.
Ill give it a try and see where I end up.
thanks.
edit*
now that I think about it wouldn't that just give me the first row and column and anything indexed > 0 not be there?
edit* edit*
just to see if my thought was correct
my test code
returns error I have not encountered yet and do not understand.
sketch_feb15a.ino: In function 'void loop()':
sketch_feb15a:36: error: return-statement with a value, in function returning 'void'
sketch_feb15a:45: error: call of overloaded 'println(byte [2][8])' is ambiguous
I think I understand what you are saying.
Ill give it a try and see where I end up.
thanks.
edit*
now that I think about it wouldn't that just give me the first row and column and anything indexed > 0 not be there?
edit* edit*
just to see if my thought was correct
my test code
returns error I have not encountered yet and do not understand.
sketch_feb15a.ino: In function 'void loop()':
sketch_feb15a:36: error: return-statement with a value, in function returning 'void'
sketch_feb15a:45: error: call of overloaded 'println(byte [2][8])' is ambiguous
Code: Select all
int MapPin = A0;
int RPMPin = A1;
byte table[][8] = {{21,22,23,24,40,50,51,48},{ 10,11,12,13,14,15,16,17}};
byte ROW, COLUMN;
int RPM = 0;
int MAP = 0;
void setup ()
{
pinMode (MapPin, INPUT);
pinMode (RPMPin, INPUT);
Serial.begin(9600);
}
void loop ()
{
RPM = analogRead (RPMPin);
ROW = map(RPM, 0, 1023, 0, 7);
MAP = analogRead (MapPin);
COLUMN = map(MAP, 0, 1023, 0, 7);
return table[ROW][COLUMN];
Serial.print ("RPM ");
Serial.println (RPM);
Serial.println ();
Serial.print ("MAP ");
Serial.println (MAP);
Serial.println (table);
Serial.println ();
Serial.println ();
Serial.println ();
Serial.println ();
Serial.println ();
delay (1000);
}
-
- Posts: 564
- Joined: Wed Jun 19, 2013 3:35 am
Re: 8X8 Table (array)
sketch_feb15a.ino: In function 'void loop()':
sketch_feb15a:36: error: return-statement with a value, in function returning 'void'
This might help -
http://arduino.cc/en/Reference/Function ... wBBZH-9KSM
http://arduino.cc/en/Reference/Return#.UwBBDX-9KSM
Remember, arrays are zero-indexed. Your array only goes up to [1][7]
sketch_feb15a:45: error: call of overloaded 'println(byte [2][8])' is ambiguous
What you are creating is called a "multidimensional array" (array of arrays).
Here is some more info about different array types -
http://www.cplusplus.com/doc/tutorial/arrays/
- jcgoodman
- Posts: 107
- Joined: Thu Jan 23, 2014 6:03 pm
Re: 8X8 Table (array)
If ROW = 1 and COLUMN = 3, table[ROW][COLUMN] will equal whatever value is in row 1, column 3 of table[][]. But remember that arrays start at zero, so that's the second row, fourth column as a human would count it.steves123 wrote: now that I think about it wouldn't that just give me the first row and column and anything indexed > 0 not be there?
You were talking earlier about "returning" a value, so I assumed this was inside a function. Chicagodave has good info on how functions and return-values work, but your current code doesn't need to return anything.sketch_feb15a.ino: In function 'void loop()':
sketch_feb15a:36: error: return-statement with a value, in function returning 'void'
You can't really print out a whole table of data at once with println(). Trysketch_feb15a:45: error: call of overloaded 'println(byte [2][8])' is ambiguous
Code: Select all
println(table[ROW][COLUMN]);
- Renate
- Posts: 291
- Joined: Tue Nov 13, 2012 3:21 pm
Re: 8X8 Table (array)
This all comes down to how thoroughly you want to do this.
Since the MAP sensor seems to only put out 3 bits, this reduces the complexity of the problem.
There are no "out of range" or "in between" values for the MAP sensor.
On the other hand, the RPMs could be 0, 4000 or 2650.
There are four cases:
If your table were a lot bigger, it would pay to use a Binary Search.
The advantage of a binary search is that it quickly tells you if you have an exact match or it gives you the two nearest.
If you find an exact match your problem is solved.
If you find two nearest, you just have to Linear Interpolate between the two.
This lists the output for specific RPMs and the "weights" to be applied to the injector values:
Since the MAP sensor seems to only put out 3 bits, this reduces the complexity of the problem.
There are no "out of range" or "in between" values for the MAP sensor.
On the other hand, the RPMs could be 0, 4000 or 2650.
There are four cases:
- RPM below lowest value
- RPM above highest value
- RPM exactly a table value
- RPM lies between two table values
If your table were a lot bigger, it would pay to use a Binary Search.
The advantage of a binary search is that it quickly tells you if you have an exact match or it gives you the two nearest.
If you find an exact match your problem is solved.
If you find two nearest, you just have to Linear Interpolate between the two.
This lists the output for specific RPMs and the "weights" to be applied to the injector values:
Code: Select all
500 - below 700
600 - below 700
700 - exactly 700
800 - between 700 (%80) and 1200 (%20)
900 - between 700 (%60) and 1200 (%40)
1000 - between 700 (%40) and 1200 (%60)
1100 - between 700 (%20) and 1200 (%80)
1200 - exactly 1200
1300 - between 1200 (%75) and 1600 (%25)
1400 - between 1200 (%50) and 1600 (%50)
1500 - between 1200 (%25) and 1600 (%75)
1600 - exactly 1600
1700 - between 1600 (%67) and 1900 (%33)
1800 - between 1600 (%33) and 1900 (%67)
1900 - exactly 1900
2000 - between 1900 (%75) and 2300 (%25)
2100 - between 1900 (%50) and 2300 (%50)
2200 - between 1900 (%25) and 2300 (%75)
2300 - exactly 2300
2400 - between 2300 (%67) and 2600 (%33)
2500 - between 2300 (%33) and 2600 (%67)
2600 - exactly 2600
2700 - between 2600 (%75) and 3000 (%25)
2800 - between 2600 (%50) and 3000 (%50)
2900 - between 2600 (%25) and 3000 (%75)
3000 - exactly 3000
3100 - between 3000 (%67) and 3300 (%33)
3200 - between 3000 (%33) and 3300 (%67)
3300 - exactly 3300
3400 - above 3300
3500 - above 3300
- zener
- Posts: 4567
- Joined: Sat Feb 21, 2009 2:38 am
Re: 8X8 Table (array)
In your first post you appear to have 8 columns of values. However, the first two contain a single value (20). And the second and third from the end are exactly the same. So you really only have 5 columns with unique numbers.
I would just make 6 ' if ' statements. The first would just assign the value 20. The next 5 would each have case statements in them for the 8 possible MAP values.
This has the value of easy readability and easy troubleshooting.
I would just make 6 ' if ' statements. The first would just assign the value 20. The next 5 would each have case statements in them for the 8 possible MAP values.
This has the value of easy readability and easy troubleshooting.
- Renate
- Posts: 291
- Joined: Tue Nov 13, 2012 3:21 pm
Re: 8X8 Table (array)
Some of those steps in RPM have pretty large output changes.
It would really make sense to interpolate.
I hope that you are adjusting for ambient temperature somewhere?
Real Engine Control Units use large tables, more than 400 entries.
Even then, they use bilinear interpolation to come up with an output value for a sample from 4 corner values.
Ok, I know that a lawn mower is not a racing street car.
It would really make sense to interpolate.
I hope that you are adjusting for ambient temperature somewhere?
Real Engine Control Units use large tables, more than 400 entries.
Even then, they use bilinear interpolation to come up with an output value for a sample from 4 corner values.
Ok, I know that a lawn mower is not a racing street car.
Please be positive and constructive with your questions and comments.