View Single Post
Old 11-11-2009, 04:12 AM   #24 (permalink)
Sebastian
EcoModding Lurker
 
Join Date: Oct 2009
Location: Austria
Posts: 28
Thanks: 0
Thanked 1 Time in 1 Post
Quote:
Originally Posted by mluckham View Post
I found bugs in my original post (.77m) thought it would be nice to post a corrected version. If I should be posting in some other manner, I welcome your suggestion please.
I like the idea with built-in calibration method so I copied some lines from yours. I think I found the mentioned bug, but I also have another suggestion for you.

Your code:
Code:
parms[calibrationDistanceIdx] = tank.distance();   // distance x 1000, for updating parms[vssPulsesPerDistanceUnitIdx]
          parms[calibrationFuelIdx] = tank.fuel();           // fuel x 1000, for updating parms[microSecondsPerFuelUnitIdx]
          
          initGuino();   // edit parms[] array
          
          // if distance or fuel values are different from tank, recalculate VSS and INJECTOR parameters
          if (parms[calibrationDistanceIdx] != tank.distance())
              parms[vssPulsesPerDistanceUnitIdx] = recalculate(missing_parms[]_BugvssPulsesPerDistanceUnitIdx, tank.distance(), parms[calibrationDistanceIdx]);
          
          if (parms[calibrationFuelIdx] != tank.fuel())
              parms[microSecondsPerFuelUnitIdx] = recalculate(parms[microSecondsPerFuelUnitIdx], tank.fuel(), parms[calibrationFuelIdx]);
My one:
Code:
unsigned long tmptankdistance = tank.distance();
          unsigned long tmptankfuel = tank.fuel();
          parms[calibrationDistanceIdx] = tmptankdistance;   // distance x 1000, for updating parms[vssPulsesPerDistanceUnitIdx]
          parms[calibrationFuelIdx] = tmptankfuel;           // fuel x 1000, for updating parms[microSecondsPerFuelUnitIdx]
          
          initGuino();  
          
          // if distance or fuel values are different from tank, recalculate VSS and INJECTOR parameters
          if (parms[calibrationDistanceIdx] != tmptankdistance)
              parms[vssPulsesPerDistanceUnitIdx] = calibrate(parms[vssPulsesPerDistanceUnitIdx], tmptankdistance, parms[calibrationDistanceIdx]);
          
          if (parms[calibrationFuelIdx] != tmptankfuel)
              parms[microSecondsPerFuelUnitIdx] = calibrate(parms[microSecondsPerFuelUnitIdx], tmptankfuel, parms[calibrationFuelIdx]);
I would recommend to save tank.distance() and tank.fuel() into variables first. On the one hand, you save recaculate them 3 more times. On the other hand, doing not so could lead to unexpected behavior like wrong vssPulsesPerDistanceUnit also if you don't change the values in setup menue.
Simply think at a situation, where you go into setup menue while engine is running or you are still driving.
parms[calibrationFuelIdx] != tank.fuel() will always be true, because tank.fuel() increased since last capture
  Reply With Quote