public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType) { if (destType == typeof(string) && value is AFRMeasurement) { // Cast the value to an Employee type AFRMeasurement pp = (AFRMeasurement)value; return(pp.AfrValue); } return(base.ConvertTo(context, culture, value, destType)); }
//when starting autotune function, first the adaption map should be implemented //into the main fuel map, and than the adaption map must be cleared. public float HandleRealtimeData(double rpm, double tps, double boost, double afr, bool _idleMapActive) { float targetafr_currentcell = 0; if (_isAutoMappingActive && _wideBandAFRSymbol != "") // must be wideband { if (_idleMapActive) { double currentLoad = boost; currentLoad += 1; currentLoad /= 0.01; int rpmindex = LookUpIndexAxisRPMMap(rpm, "Idle_st_rpm!", 10); int mapindex = LookUpIndexAxisMap(currentLoad, "Idle_st_last!"); if (rpmindex != _monitoringCellRPMIndex || mapindex != _monitoringCellMAPIndex) { // set both values _afrMeasurements.Clear(); // clear average collection _monitoringCellRPMIndex = rpmindex; _monitoringCellMAPIndex = mapindex; // reset stopwatch _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } else { // appearantly we are in the same cell if (_monitoringCellMAPIndex >= 0 && _monitoringCellRPMIndex >= 0) { AFRMeasurement _measurement = new AFRMeasurement(); _measurement.AfrValue = afr; _afrMeasurements.Add(_measurement); long elapsed_ms = _cellDurationMonitor.ElapsedMilliseconds; if (elapsed_ms > _CellStableTime_ms) { Console.WriteLine("Stable in cell: " + rpmindex.ToString() + " " + mapindex.ToString()); if (!IsIdleCellLocked(mapindex, rpmindex)) { // check afr against target afr // get the average AFR from the collection float average_afr_in_cell = (float)GetAverageFromMeasurements(); targetafr_currentcell = (float)idletargetmap.GetValue((rpmindex * 12) + mapindex); // calculate the difference in percentage float _afr_diff_percentage = Math.Abs(((targetafr_currentcell - average_afr_in_cell) / targetafr_currentcell) * 100); if (_afr_diff_percentage > _AcceptableTargetErrorPercentage) { // afr is outside of limits (difference > set percentage).. now what? // is the afr lower or higher than the target? // we should correct with the set percentage _CorrectionPercentage // but no more than _MaximumAdjustmentPerCyclePercentage of the original fuelmap value float afr_diff_to_correct = Math.Abs(_afr_diff_percentage); afr_diff_to_correct *= _CorrectionPercentage; afr_diff_to_correct /= 100; // cap it to _MaximumAdjustmentPerCyclePercentage if (afr_diff_to_correct > _MaximumAdjustmentPerCyclePercentage) { afr_diff_to_correct = _MaximumAdjustmentPerCyclePercentage; } // get the current fuel map value for the given cell // get the number of changes that have been made already to this cell // if the number of changes > x then don't do changes anymore and notify the user int _fuelcorrectionvalue = (int)idlefuelmap[(rpmindex * 12) + mapindex]; if (average_afr_in_cell > targetafr_currentcell) { // we're running too lean, so we need to increase the fuelmap value by afr_diff_to_correct % // get the current fuelmap value // correct it with the percentage _fuelcorrectionvalue *= (int)(100 + afr_diff_to_correct); _fuelcorrectionvalue /= 100; if (_fuelcorrectionvalue > 254) _fuelcorrectionvalue = 254; // save it to the map } else { // we're running too rich, so we need to decrease the fuelmap value by afr_diff_to_correct % // correct it with the percentage _fuelcorrectionvalue *= (int)(100 - afr_diff_to_correct); _fuelcorrectionvalue /= 100; // don't go under 25, seems to be some kind of boundary! // <GS-28102010> changed for testing purposes, if problems occur, revert back to 25 as boundary if (_fuelcorrectionvalue < 1) _fuelcorrectionvalue = 1; // save it to the map } if (idlefuelmap[(rpmindex * 12) + mapindex] != (byte)_fuelcorrectionvalue) { // if autowrite to ECU if (_AutoUpdateFuelMap) { // if the user should be notified, do so now, ask permission to alter the fuel map //Console.WriteLine("Altering rpmidx: " + rpmindex.ToString() + " mapidx: " + mapindex.ToString() + " from value: " + fuelmap[(rpmindex * 16) + mapindex].ToString() + " to value: " + _fuelcorrectionvalue.ToString()); idlefuelmap[(rpmindex * 12) + mapindex] = (byte)_fuelcorrectionvalue; // increase counter idlefuelcorrectioncountermap[(rpmindex * 12) + mapindex]++; // cast an event that will write the data into the ECU (?) CastIdleFuelmapCellChangedEvent((rpmindex * 12) + mapindex, (byte)_fuelcorrectionvalue); } else { // keep track of the changes in the fuelmapinfo m_FuelMapInformation.UpdateIdleFuelMap(mapindex, rpmindex, _fuelcorrectionvalue); } //<GS-09082010> play an optional PING sound here! CastCellLockedEvent(); } //now we reset the stopwatch and wait for another event to occur _afrMeasurements.Clear(); // clear average collection _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } else { //what to do if AFR is correct (within limits), should we reset the stopwatch? _afrMeasurements.Clear(); // clear average collection _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } } else { _afrMeasurements.Clear(); // clear average collection _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } } } else { // nothing, invalid index from map _afrMeasurements.Clear(); // clear average collection _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } } } else { // only handle this stuff if automapping is active // first off, get the index in the fuel map for the given engine speed and load double currentLoad = boost; currentLoad += 1; currentLoad /= 0.01; int rpmindex = LookUpIndexAxisRPMMap(rpm, "Fuel_map_yaxis!", 10); int mapindex = LookUpIndexAxisMap(currentLoad, "Fuel_map_xaxis!"); //Console.WriteLine("MAP index: " + mapindex.ToString() + " for load: " + boost.ToString()); //so we now know in what cell we are // if the cell changed, we need to restart the stopwatch // if the cell is unchanged we need to check the stopwatchduration against the settings if (rpmindex != _monitoringCellRPMIndex || mapindex != _monitoringCellMAPIndex) { // set both values _afrMeasurements.Clear(); // clear average collection _monitoringCellRPMIndex = rpmindex; _monitoringCellMAPIndex = mapindex; // reset stopwatch _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } else { // appearantly we are in the same cell if (_monitoringCellMAPIndex >= 0 && _monitoringCellRPMIndex >= 0) { AFRMeasurement _measurement = new AFRMeasurement(); _measurement.AfrValue = afr; _afrMeasurements.Add(_measurement); long elapsed_ms = _cellDurationMonitor.ElapsedMilliseconds; if (elapsed_ms > _CellStableTime_ms) { // check afr against target afr // get the average AFR from the collection if (!IsCellLocked(mapindex, rpmindex)) { float average_afr_in_cell = (float)GetAverageFromMeasurements(); targetafr_currentcell = (float)targetmap.GetValue((rpmindex * 16) + mapindex); // calculate the difference in percentage float _afr_diff_percentage = Math.Abs(((targetafr_currentcell - average_afr_in_cell) / targetafr_currentcell) * 100); if (_afr_diff_percentage > _AcceptableTargetErrorPercentage) { //Console.WriteLine("Stable in cell: " + rpmindex.ToString() + " " + mapindex.ToString() + " afrtarget = " + targetafr_currentcell.ToString("F2") + " afravg: " + average_afr_in_cell.ToString("F2") + " percdiff: " + _afr_diff_percentage.ToString("F2")); // afr is outside of limits (difference > set percentage).. now what? // is the afr lower or higher than the target? // we should correct with the set percentage _CorrectionPercentage // but no more than _MaximumAdjustmentPerCyclePercentage of the original fuelmap value float afr_diff_to_correct = Math.Abs(_afr_diff_percentage); afr_diff_to_correct *= _CorrectionPercentage; afr_diff_to_correct /= 100; // cap it to _MaximumAdjustmentPerCyclePercentage if (afr_diff_to_correct > _MaximumAdjustmentPerCyclePercentage) { afr_diff_to_correct = _MaximumAdjustmentPerCyclePercentage; } // get the current fuel map value for the given cell // get the number of changes that have been made already to this cell // if the number of changes > x then don't do changes anymore and notify the user int _fuelcorrectionvalue = (int)fuelmap[(rpmindex * 16) + mapindex]; if (average_afr_in_cell > targetafr_currentcell) { if (afr_diff_to_correct < 2) { Console.WriteLine("Stable in cell (LEAN): " + rpmindex.ToString() + " " + mapindex.ToString() + " afrtarget = " + targetafr_currentcell.ToString("F2") + " afravg: " + average_afr_in_cell.ToString("F2") + " percdiff: " + _afr_diff_percentage.ToString("F2") + " corrperc: " + afr_diff_to_correct.ToString("F2")); Console.WriteLine("Ori fuel value: " + _fuelcorrectionvalue.ToString()); } // we're running too lean, so we need to increase the fuelmap value by afr_diff_to_correct % // get the current fuelmap value // correct it with the percentage float _tempcorrectionvalue = _fuelcorrectionvalue; _tempcorrectionvalue *= 100F + afr_diff_to_correct; _tempcorrectionvalue /= 100F; if (afr_diff_to_correct < 10) { Console.WriteLine("Multiply fuel value: " + _tempcorrectionvalue.ToString("F3")); } if (_tempcorrectionvalue > 254) _tempcorrectionvalue = 254; _fuelcorrectionvalue = Convert.ToInt32(Math.Round(_tempcorrectionvalue)); if (afr_diff_to_correct < 2) { Console.WriteLine("New fuel value: " + _fuelcorrectionvalue.ToString()); } /*_fuelcorrectionvalue *= (int)(100 + afr_diff_to_correct); if (afr_diff_to_correct < 10) { Console.WriteLine("Multiply fuel value: " + _fuelcorrectionvalue.ToString()); } _fuelcorrectionvalue /= 100; if (afr_diff_to_correct < 10) { Console.WriteLine("New fuel value: " + _fuelcorrectionvalue.ToString()); } if (_fuelcorrectionvalue > 254) _fuelcorrectionvalue = 254;*/ // save it to the map } else { // we're running too rich, so we need to decrease the fuelmap value by afr_diff_to_correct % // correct it with the percentage Console.WriteLine("Stable in cell (RICH): " + rpmindex.ToString() + " " + mapindex.ToString() + " afrtarget = " + targetafr_currentcell.ToString("F2") + " afravg: " + average_afr_in_cell.ToString("F2") + " percdiff: " + _afr_diff_percentage.ToString("F2") + " corrperc: " + afr_diff_to_correct.ToString("F2")); float _tempcorrectionvalue = _fuelcorrectionvalue; _tempcorrectionvalue *= 100F - afr_diff_to_correct; _tempcorrectionvalue /= 100F; if (_tempcorrectionvalue < 1) _tempcorrectionvalue = 1; _fuelcorrectionvalue = Convert.ToInt32(Math.Round(_tempcorrectionvalue)); /* _fuelcorrectionvalue *= (int)(100 - afr_diff_to_correct); _fuelcorrectionvalue /= 100; // don't go under 25, seems to be some kind of boundary! // <GS-28102010> changed for testing purposes, if problems occur, revert back to 25 as boundary if (_fuelcorrectionvalue < 1) _fuelcorrectionvalue = 1;*/ // save it to the map } if (fuelmap[(rpmindex * 16) + mapindex] != (byte)_fuelcorrectionvalue) { // if autowrite to ECU if (_AutoUpdateFuelMap) { // if the user should be notified, do so now, ask permission to alter the fuel map //Console.WriteLine("Altering rpmidx: " + rpmindex.ToString() + " mapidx: " + mapindex.ToString() + " from value: " + fuelmap[(rpmindex * 16) + mapindex].ToString() + " to value: " + _fuelcorrectionvalue.ToString()); fuelmap[(rpmindex * 16) + mapindex] = (byte)_fuelcorrectionvalue; // increase counter fuelcorrectioncountermap[(rpmindex * 16) + mapindex]++; // cast an event that will write the data into the ECU (?) CastFuelmapCellChangedEvent((rpmindex * 16) + mapindex, (byte)_fuelcorrectionvalue); } else { // keep track of the changes in the fuelmapinfo m_FuelMapInformation.UpdateFuelMap(mapindex, rpmindex, _fuelcorrectionvalue); } //<GS-09082010> play an optional PING sound here! CastCellLockedEvent(); } //now we reset the stopwatch and wait for another event to occur _afrMeasurements.Clear(); // clear average collection _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } else { Console.WriteLine("Fuelling correct in cell: " + rpmindex.ToString() + " " + mapindex.ToString() + " afrtarget = " + targetafr_currentcell.ToString("F2") + " afravg: " + average_afr_in_cell.ToString("F2") + " percdiff: " + _afr_diff_percentage.ToString("F2")); //what to do if AFR is correct (within limits), should we reset the stopwatch? _afrMeasurements.Clear(); // clear average collection _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } } else { _afrMeasurements.Clear(); // clear average collection _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } } } else { // nothing, invalid index from map _afrMeasurements.Clear(); // clear average collection _cellDurationMonitor.Stop(); _cellDurationMonitor.Reset(); _cellDurationMonitor.Start(); } } } } return targetafr_currentcell; }
public bool Contains(AFRMeasurement value) { // If value is not of type Int16, this will return false. return(List.Contains(value)); }
public void Insert(int index, AFRMeasurement value) { List.Insert(index, value); }
public void Remove(AFRMeasurement value) { List.Remove(value); }
public int Add(AFRMeasurement value) { return(List.Add(value)); }
public int IndexOf(AFRMeasurement value) { return(List.IndexOf(value)); }
public bool Contains(AFRMeasurement value) { // If value is not of type Int16, this will return false. return (List.Contains(value)); }
public int Add(AFRMeasurement value) { return (List.Add(value)); }
public int IndexOf(AFRMeasurement value) { return (List.IndexOf(value)); }