05-19-2009, 12:21 PM
|
#23
|
Registered Member
Join Date: Jul 2007
Posts: 280
|
Sorry I disappeared there.
Everything happens here and looking at it again I'm very stupid, the -127-128 can be changed at your will, looks like it just gets a byte by default and turns it in to those int values.
Here's the code with my own comments:
void processChunk(byte[] b, int c) {
double ih = 0; #injections, some amount of fuel
double vt = 0; # vss pulses
double rev = 0; # revs of engine
# Read all bytes that happened since we were here last in 2 byte chunks (left and right at 8bit)
for (int x = 0; x < c; x += 2) {
#the first channel (left?) is vss and here's were it manipulates the byte into an int between -127 to 128
int val = ((int) b[x] & 255) - 127;
if (val > vssThreshold && vg) {
# If it's greater than the threshold then add one to the pulse count
vt++;
//System.out.println(" vss going hi "
// + (current.sampleCount + (x / 2)));
vg = false;
}
if (val < 0) {
vg = true;
}
# Parsing the next channel, injector and turning into -127 to 128
val = ((int) b[x + 1] & 255) - 127;
if (val < injThreshold) {
# if less than the threshold then set ig to true
ig = true;
}
if (ig && val > 0)
{
rev += 1;
}
if (val > 0)
ig = false;
# These are my own changes to try to captures revs but it looks wrong rereading it now. Basically I just want to +1 to ih if we're ever less than threshold, but I was doing other stuff to try to count rpms, so I could get < threshold 3 bytes in a row but wanted that to count as 1 revolution (just a longer injection pulse).
if (ig)
ih++;
}
instant.Update((double)c / 2, ih, vt, rev);
current.Update((double)c / 2, ih, vt, rev);
tank.Update((double)c / 2, ih, vt, rev);
if (coastTest.coasting && instant.instantmph()<=coastTest.startmph() ) {
if (instant.instantmph()>=coastTest.endmph()) {
coastTest.UpdateDrag(instant.acceleration(), instant.instantmph());
} else { coastTest.coasting=false; }
}
}
So after looking over it (well my modified code), the real code will be similar but I still say -50 and 80 look good based on your signals, this will trigger correctly to turn a pulse in the audio into an injection or vss pulse.
Gallons are probably way off because your fuel fudge isn't calibrated right.
Gallons is simply the total number of injections we've gotten since last reset (so per/sec for instant, /min for current and /tank for tank) divided by fuelFudge:
public double gallons() {
return injHiTot / fuelFudge;
}
So even though you have the right amount of injections you still need to have the fudge right before the value will make sense. His fudge was
fuelFudge=8000000.00 by default for a 4 cyl (EDIT: this was a 3 Cyl metro, doh!)
You could try calculating, like ignore injector openning closing time and just assume it's 300cc/min injectors and we're sampling every 44Khz * 60 (secs in a min) so 1.136 * 10^4 cc/cycle if on, 1 cc = 0.000264172052 US Gallons, so
3 * 10^-8 gallons/cycle. We're dividing by fudge though, not multiplying so invert: 33.3 * 10^6
This is just completely off the cuff but matches fairly closely to the 8 * 10^6 default value. Keep in mind this is one injector you're watching, if you've got a 4cyl with 4 300cc/min injectors we'd have to divide that 33.3 by 4 (that is we're giving 4 times the weight to each pulse because there were actually 4 of them), that's 8.3 * 10^6.
My truck has only 2 throttle body injectors, I think 500-600cc/min each, but basically I just took the 8 * 10^6 default, dividing by 5.7 (thought being that 8 was for total injections to a 1L metro). Still haven't been able to debug in car to know if that value is useful though.
NOTE! Also, it seems obvious that each thing to needs to be on a particular channel. I'm not sure if skewbe mentioned that, but the code clearly works this way. You'd could swap the inj and vss blocks in ProcessChunk if you think you're reading the wrong channel for each. I was just guessing that left was first though.
EDIT: Yeah, skewbe set up VSS as the left channel and inj as the right, so that's probably why it appears first, though looking at it again, the for loop works backwards. We have an array of byte and look at them 2 at a time starting with 0, I'm not sure how this array is given to us or filled but to work the way I imagine in my head, the code uses it like this:
cycle 5 -> cycle 1
RL RL RL RL RL RL
Because it's saying b[0] is the 1st cycle's left or vss and b[1] is right, then adding 2 and saying b[2] is left and b[3] is right.
Skewbe can you comment? I finally have a laptop (and now the truck is dead) so looking to set this up in the Festy and have at it, hopefully sooner rather than later!
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Car Talk & Chit Chat |
|
|
|
|
|
» Fuelly iOS Apps |
|
» Fuelly Android Apps |
|
|