Removed old s19 files and installed new ones.
[freeems-vanilla.git] / src / derivedVarsGenerator.c
blob48cf4dedaaf97138d4d0a4f4f6a48714531c5696
1 /* Copyright 2008 Fred Cooke
3 This file is part of the FreeEMS project.
5 FreeEMS software is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 FreeEMS software is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with any FreeEMS software. If not, see http://www.gnu.org/licenses/
18 We ask that if you make any changes to this file you email them upstream to
19 us at admin(at)diyefi(dot)org or, even better, fork the code on github.com!
21 Thank you for choosing FreeEMS to run your engine! */
24 /** @file derivedVarsGenerator.c
25 * @ingroup measurementsAndCalculations
27 * @brief Generate the derived variables.
29 * Second level variables are derived from the core variables and generated here.
31 * @author Fred Cooke
35 #define DERIVEDVARSGENERATOR_C
36 #include "inc/freeEMS.h"
37 #include "inc/commsCore.h"
38 #include "inc/tableLookup.h"
39 #include "inc/derivedVarsGenerator.h"
42 /** @brief Generate the derived variables.
44 * This function uses the core variables to lookup and calculate further second
45 * order variables such as load, VE, Lamdda, Transient fuel correction, engine
46 * temperature enrichment, Injector dead time, etc.
48 * @author Fred Cooke
50 void generateDerivedVars(){
51 /*&&&&&&&&&&&&&&&&&&&& Use basic variables to lookup and calculate derived variables &&&&&&&&&&&&&&&&&&&*/
54 /* Determine load based on options */
55 if(TRUE){ /* Use MAP as load */
56 DerivedVars->LoadMain = CoreVars->MAP;
57 }else if(FALSE){ /* Use TPS as load */
58 DerivedVars->LoadMain = CoreVars->TPS;
59 }else if(FALSE){ /* Use AAP corrected MAP as load */
60 DerivedVars->LoadMain = ((unsigned long)CoreVars->MAP * CoreVars->AAP) / seaLevelKPa;
61 }else{ /* Default to MAP, but throw error */
62 DerivedVars->LoadMain = CoreVars->MAP;
63 /* If anyone is listening, let them know something is wrong */
64 sendErrorIfClear(LOAD_NOT_CONFIGURED_CODE); // or maybe queue it?
68 /* Look up VE with RPM and Load */
69 DerivedVars->VEMain = lookupPagedMainTableCellValue((mainTable*)&TablesA.VETableMain, CoreVars->RPM, DerivedVars->LoadMain, currentFuelRPage);
72 /* Look up target Lambda with RPM and Load */
73 DerivedVars->Lambda = lookupPagedMainTableCellValue((mainTable*)&TablesD.LambdaTable, CoreVars->RPM, DerivedVars->LoadMain, currentFuelRPage);
76 /* Look up injector dead time with battery voltage */
77 DerivedVars->IDT = lookupTwoDTableUS((twoDTableUS*)&TablesA.SmallTablesA.injectorDeadTimeTable, CoreVars->BRV);
80 /* Calculate the engine temperature enrichment */
81 // unsigned short localETEPercentage = lookupTwoDTableUS(&engineTempEnrichmentTable, CoreVars.CHT);
82 // DerivedVars->ETE = ((unsigned long)finalMasterTotalEndPW * localETEPercentage) / oneHundredPercentETE;
83 /* TODO The above needs some careful thought put into it around different loads and correction effects. */
86 /* Calculate the Transient Fuel Correction */
87 if(TRUE /*WWTFC*/){ /* Do ONLY WW correction if enabled */
88 // Do ww stuff, maybe pre done via RTC/RTI for consistent period?
89 DerivedVars->TFCTotal = 0; /* TODO replace with real code */
90 }else if(FALSE /*STDTFC*/){ /* Do any combination of standard approximate methods */
91 /* Initialse the variable as a base */
92 DerivedVars->TFCTotal = 0;
93 /* Based on the rate of change of MAP and some history/taper time */
94 if(FALSE /*MAPTFC*/){
95 // Do MAP based
96 DerivedVars->TFCTotal += 0;
99 /* Based on the rate of change of TPS and some history/taper time */
100 if(FALSE /*TPSTFC*/){
101 // Do TPS based
102 DerivedVars->TFCTotal += 0;
105 /* Based on the rate of change of RPM and some history/taper time */
106 if(FALSE /*RPMTFC*/){
107 // Do RPM based
108 DerivedVars->TFCTotal += 0;
110 }else{ /* Default to no correction */
111 DerivedVars->TFCTotal = 0;
112 /* Don't throw error as correction may not be required */
116 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/