From ef496916f928d30ec962ccb1867b1291ff880842 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sun, 22 Jan 2017 17:03:31 -0500 Subject: [PATCH] auto-sync --- firmware/console/binary/tunerstudio_configuration.h | 3 ++- firmware/console/status_loop.cpp | 2 ++ firmware/controllers/algo/aux_pid.cpp | 2 +- firmware/controllers/algo/engine.cpp | 3 ++- firmware/controllers/algo/engine.h | 7 +++++++ firmware/controllers/algo/fuel_math.cpp | 2 +- firmware/controllers/alternatorController.cpp | 2 +- firmware/controllers/electronic_throttle.cpp | 2 +- firmware/controllers/math/pid.cpp | 4 ++++ firmware/controllers/math/pid.h | 1 + firmware/controllers/sensors/ego.cpp | 2 +- .../controllers/trigger/main_trigger_callback.cpp | 12 +++++++++--- firmware/tunerstudio/rusefi.ini | 6 +++++- firmware/tunerstudio/rusefi.input | 4 ++++ unit_tests/.cproject | 2 ++ 15 files changed, 43 insertions(+), 11 deletions(-) diff --git a/firmware/console/binary/tunerstudio_configuration.h b/firmware/console/binary/tunerstudio_configuration.h index 836bc6a84a..0b5eb99956 100644 --- a/firmware/console/binary/tunerstudio_configuration.h +++ b/firmware/console/binary/tunerstudio_configuration.h @@ -149,7 +149,8 @@ typedef struct { float debugFloatField6; // 256 float debugFloatField7; // 260 int firmwareVersion; // 264 - int unused3[22]; + float fuelPidCorrection; // 268 + int unused3[21]; } TunerStudioOutputChannels; #endif /* TUNERSTUDIO_CONFIGURATION_H_ */ diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index c8c4695a68..bf27cbe215 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -245,6 +245,7 @@ static void printSensors(Logging *log, bool fileFormat) { reportSensorF(log, fileFormat, "f: actual", "ms", ENGINE(actualLastInjection), 2); reportSensorF(log, fileFormat, "f: lag", "ms", engine->engineState.injectorLag, 2); reportSensorF(log, fileFormat, "f: running", "ms", ENGINE(engineState.runningFuel), 2); + reportSensorF(log, fileFormat, "f: pid", "ms", ENGINE(engineState.fuelPidCorrection), 2); reportSensorF(log, fileFormat, "f: wall amt", "v", ENGINE(wallFuel).getWallFuel(0), 2); reportSensorF(log, fileFormat, "f: wall crr", "v", ENGINE(wallFuelCorrection), 2); @@ -690,6 +691,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ tsOutputChannels->injectorDutyCycle = getInjectorDutyCycle(rpm PASS_ENGINE_PARAMETER); tsOutputChannels->fuelRunning = ENGINE(engineState.runningFuel); + tsOutputChannels->fuelPidCorrection = ENGINE(engineState.fuelPidCorrection); tsOutputChannels->injectorLagMs = ENGINE(engineState.injectorLag); tsOutputChannels->fuelBase = engine->engineState.baseFuel; tsOutputChannels->actualLastInjection = ENGINE(actualLastInjection); diff --git a/firmware/controllers/algo/aux_pid.cpp b/firmware/controllers/algo/aux_pid.cpp index 7ba5fbffe8..5875932c8f 100644 --- a/firmware/controllers/algo/aux_pid.cpp +++ b/firmware/controllers/algo/aux_pid.cpp @@ -76,7 +76,7 @@ static msg_t auxPidThread(int param) { float value = engine->triggerCentral.vvtPosition; // getVBatt(PASS_ENGINE_PARAMETER_F); // that's temporary float targetValue = fsioTable1.getValue(rpm, getEngineLoadT(PASS_ENGINE_PARAMETER_F)); - float pwm = auxPid.getValue(targetValue, value, 1); + float pwm = auxPid.getValue(targetValue, value); if (engineConfiguration->isVerboseAuxPid1) { scheduleMsg(logger, "aux duty: %f/value=%f/p=%f/i=%f/d=%f int=%f", pwm, value, auxPid.getP(), auxPid.getI(), auxPid.getD(), auxPid.getIntegration()); diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index c862050f29..bf0397a2be 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -170,6 +170,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) { sparkDwell = getSparkDwell(rpm PASS_ENGINE_PARAMETER); dwellAngle = sparkDwell / getOneDegreeTimeMs(rpm); + currentAfr = getAfr(PASS_ENGINE_PARAMETER_F); // todo: move this into slow callback, no reason for IAT corr to be here iatFuelCorrection = getIatCorrection(iat PASS_ENGINE_PARAMETER); @@ -179,7 +180,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) { cltFuelCorrection = 1; warmupAfrPid.reset(); } else { - cltFuelCorrection = warmupAfrPid.getValue(warmupTargetAfr, getAfr(PASS_ENGINE_PARAMETER_F), 1); + cltFuelCorrection = warmupAfrPid.getValue(warmupTargetAfr, currentAfr, 1); } #if ! EFI_UNIT_TEST || defined(__DOXYGEN__) if (engineConfiguration->debugMode == WARMUP_ENRICH) { diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 275086f197..e71169f3d9 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -148,6 +148,8 @@ public: float currentVE; float targetAFR; + float currentAfr; + /** * pre-calculated value from simple fuel lookup */ @@ -157,6 +159,11 @@ public: */ floatms_t baseFuel; + /** + * closed-loop fuel correction + */ + floatms_t fuelPidCorrection; + /** * Total fuel with CLT, IAT and TPS acceleration corrections per cycle, * as squirt duration. diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 216cee2ff1..851cbaf0b2 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -141,7 +141,7 @@ floatms_t getRunningFuel(floatms_t baseFuel, int rpm DECLARE_ENGINE_PARAMETER_S) float iatCorrection = ENGINE(engineState.iatFuelCorrection); float cltCorrection = ENGINE(engineState.cltFuelCorrection); - ENGINE(engineState.runningFuel) = baseFuel * iatCorrection * cltCorrection; + ENGINE(engineState.runningFuel) = baseFuel * iatCorrection * cltCorrection + ENGINE(engineState.fuelPidCorrection); return ENGINE(engineState.runningFuel); } diff --git a/firmware/controllers/alternatorController.cpp b/firmware/controllers/alternatorController.cpp index ccd6cd4adf..2dccfb3f38 100644 --- a/firmware/controllers/alternatorController.cpp +++ b/firmware/controllers/alternatorController.cpp @@ -85,7 +85,7 @@ static msg_t AltCtrlThread(int param) { } - currentAltDuty = altPid.getValue(targetVoltage, vBatt, 1); + currentAltDuty = altPid.getValue(targetVoltage, vBatt); if (boardConfiguration->isVerboseAlternator) { scheduleMsg(logger, "alt duty: %f/vbatt=%f/p=%f/i=%f/d=%f int=%f", currentAltDuty, vBatt, altPid.getP(), altPid.getI(), altPid.getD(), altPid.getIntegration()); diff --git a/firmware/controllers/electronic_throttle.cpp b/firmware/controllers/electronic_throttle.cpp index 7ee3c22b3e..fc93b10183 100644 --- a/firmware/controllers/electronic_throttle.cpp +++ b/firmware/controllers/electronic_throttle.cpp @@ -69,7 +69,7 @@ static msg_t etbThread(void *arg) { percent_t pedal = getPedalPosition(PASS_ENGINE_PARAMETER_F); percent_t tps = getTPS(); - currentEtbDuty = pid.getValue(pedal, getTPS(), 1); + currentEtbDuty = pid.getValue(pedal, getTPS()); etbPwmUp.setSimplePwmDutyCycle(currentEtbDuty / 100); diff --git a/firmware/controllers/math/pid.cpp b/firmware/controllers/math/pid.cpp index 13d5ec79e6..92a6eb5608 100644 --- a/firmware/controllers/math/pid.cpp +++ b/firmware/controllers/math/pid.cpp @@ -32,6 +32,10 @@ bool Pid::isSame(pid_s *pid) { this->pid->offset == pid->offset && this->pid->pFactor == pid->pFactor; } +float Pid::getValue(float target, float input) { + return getValue(target, input, 1); +} + float Pid::getValue(float target, float input, float dTime) { float error = target - input; diff --git a/firmware/controllers/math/pid.h b/firmware/controllers/math/pid.h index e5d1a8ea24..c6a0df0940 100644 --- a/firmware/controllers/math/pid.h +++ b/firmware/controllers/math/pid.h @@ -22,6 +22,7 @@ public: void init(pid_s *pid, float minResult, float maxResult); bool isSame(pid_s *pid); + float getValue(float target, float input); float getValue(float target, float input, float dTime); void updateFactors(float pFactor, float iFactor, float dFactor); void reset(void); diff --git a/firmware/controllers/sensors/ego.cpp b/firmware/controllers/sensors/ego.cpp index 0da955b3c0..12f07ed9be 100644 --- a/firmware/controllers/sensors/ego.cpp +++ b/firmware/controllers/sensors/ego.cpp @@ -13,7 +13,7 @@ bool hasAfrSensor(DECLARE_ENGINE_PARAMETER_F) { } float getAfr(DECLARE_ENGINE_PARAMETER_F) { - afr_sensor_s * sensor = &engineConfiguration->afr; + afr_sensor_s * sensor = &CONFIG(afr); float volts = getVoltageDivided("ego", sensor->hwChannel); diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 9b2356ed72..25586d716f 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -70,6 +70,7 @@ static Logging *logger; #if ! EFI_UNIT_TEST static pid_s *fuelPidS = &persistentState.persistentConfiguration.engineConfiguration.fuelClosedLoopPid; static Pid fuelPid(fuelPidS, -100, 100); +extern TunerStudioOutputChannels tsOutputChannels; #endif // todo: figure out if this even helps? @@ -381,6 +382,14 @@ static void fuelClosedLoopCorrection(DECLARE_ENGINE_PARAMETER_F) { return; } +#if ! EFI_UNIT_TEST + engine->engineState.fuelPidCorrection = fuelPid.getValue(ENGINE(engineState.targetAFR), ENGINE(engineState.currentAfr), 1); + if (engineConfiguration->debugMode == DBG_FUEL_PID_CORRECTION) { + tsOutputChannels.debugFloatField1 = engine->engineState.fuelPidCorrection; + fuelPid.postState(&tsOutputChannels); + } + +#endif } @@ -513,9 +522,6 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex D if (CONFIG(fuelClosedLoopCorrectionEnabled)) { fuelClosedLoopCorrection(PASS_ENGINE_PARAMETER_F); } - - - } efiAssertVoid(!CONFIG(useOnlyRisingEdgeForTrigger) || CONFIG(ignMathCalculateAtIndex) % 2 == 0, "invalid ignMathCalculateAtIndex"); diff --git a/firmware/tunerstudio/rusefi.ini b/firmware/tunerstudio/rusefi.ini index 77b3267f29..f4b1df5d42 100644 --- a/firmware/tunerstudio/rusefi.ini +++ b/firmware/tunerstudio/rusefi.ini @@ -42,7 +42,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jan 22 15:35:11 EST 2017 +; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jan 22 16:15:28 EST 2017 pageSize = 16376 page = 1 @@ -915,6 +915,7 @@ fileVersion = { 20161225 } debugFloatField6 = scalar, F32, 256, "val", 1, 0.0; debugFloatField7 = scalar, F32, 260, "val", 1, 0.0; firmwareVersion = scalar,U32, 264, "version_f", 1, 0 + fuelPidCorrection = scalar, F32, 268, "ms", 1, 0 egoCorrection = { 100 } time = { timeNow } @@ -1189,6 +1190,8 @@ fileVersion = { 20161225 } pulseWidthGauge = pulseWidth, "fuel final squirt, per injection", "mSec", 0, 25.5, 1.0, 1.2, 20, 25, 3, 1 baseFuelGauge = baseFuel, "fuel: base duration, before corr", "mSec", 0, 25.5, 1.0, 1.2, 20, 25, 3, 1 + fuelPidCorrectionGauge = fuelPidCorrection, "fuel: closed loop correction", "mSec", 0, 25.5, 1.0, 1.2, 20, 25, 3, 1 + crankingFuelGauge = crankingFuel, "fuel: crank Width", "mSec", 0, 25.5, 1.0, 1.2, 20, 25, 3, 1 iatCorrectionGauge = iatCorrection, "fuel: IAT correction", "mult", 0, 3, 0, 0, 3, 3, 2, 2 cltCorrectionGauge = cltCorrection, "fuel: CLT correction", "mult", 0, 3, 0, 0, 3, 3, 2, 2 @@ -1292,6 +1295,7 @@ fileVersion = { 20161225 } entry = pulseWidth, "fuel: pulse", float, "%.3f" entry = baseFuel, "fuel: base", float, "%.2f" + entry = fuelPidCorrection,"fuel: pid", float, "%.2f" entry = veValue, "fuel: VE", float, "%.3f" entry = injectorDutyCycle,"fuel: duty cyc",float,"%.3f" diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 3a5b6bab98..82dd81ea08 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -852,6 +852,7 @@ fileVersion = { 20161225 } debugFloatField6 = scalar, F32, 256, "val", 1, 0.0; debugFloatField7 = scalar, F32, 260, "val", 1, 0.0; firmwareVersion = scalar,U32, 264, "version_f", 1, 0 + fuelPidCorrection = scalar, F32, 268, "ms", 1, 0 egoCorrection = { 100 } time = { timeNow } @@ -1126,6 +1127,8 @@ fileVersion = { 20161225 } pulseWidthGauge = pulseWidth, "fuel final squirt, per injection", "mSec", 0, 25.5, 1.0, 1.2, 20, 25, 3, 1 baseFuelGauge = baseFuel, "fuel: base duration, before corr", "mSec", 0, 25.5, 1.0, 1.2, 20, 25, 3, 1 + fuelPidCorrectionGauge = fuelPidCorrection, "fuel: closed loop correction", "mSec", 0, 25.5, 1.0, 1.2, 20, 25, 3, 1 + crankingFuelGauge = crankingFuel, "fuel: crank Width", "mSec", 0, 25.5, 1.0, 1.2, 20, 25, 3, 1 iatCorrectionGauge = iatCorrection, "fuel: IAT correction", "mult", 0, 3, 0, 0, 3, 3, 2, 2 cltCorrectionGauge = cltCorrection, "fuel: CLT correction", "mult", 0, 3, 0, 0, 3, 3, 2, 2 @@ -1229,6 +1232,7 @@ fileVersion = { 20161225 } entry = pulseWidth, "fuel: pulse", float, "%.3f" entry = baseFuel, "fuel: base", float, "%.2f" + entry = fuelPidCorrection,"fuel: pid", float, "%.2f" entry = veValue, "fuel: VE", float, "%.3f" entry = injectorDutyCycle,"fuel: duty cyc",float,"%.3f" diff --git a/unit_tests/.cproject b/unit_tests/.cproject index 27a33e0b31..28daf7b94e 100644 --- a/unit_tests/.cproject +++ b/unit_tests/.cproject @@ -37,6 +37,7 @@ + @@ -58,6 +59,7 @@ +