auto-sync
This commit is contained in:
parent
2828e1faca
commit
9dd88a1dc1
|
@ -261,7 +261,7 @@ static void printState(void) {
|
||||||
debugFloat(&logger, "fuel_base", baseFuel, 2);
|
debugFloat(&logger, "fuel_base", baseFuel, 2);
|
||||||
// debugFloat(&logger, "fuel_iat", getIatCorrection(getIntakeAirTemperature()), 2);
|
// debugFloat(&logger, "fuel_iat", getIatCorrection(getIntakeAirTemperature()), 2);
|
||||||
// debugFloat(&logger, "fuel_clt", getCltCorrection(getCoolantTemperature()), 2);
|
// debugFloat(&logger, "fuel_clt", getCltCorrection(getCoolantTemperature()), 2);
|
||||||
debugFloat(&logger, "fuel_lag", engine->injectorLagMs, 2);
|
debugFloat(&logger, "fuel_lag", engine->engineState.injectorLag, 2);
|
||||||
debugFloat(&logger, "fuel", ENGINE(actualLastInjection), 2);
|
debugFloat(&logger, "fuel", ENGINE(actualLastInjection), 2);
|
||||||
|
|
||||||
debugFloat(&logger, "timing", engine->engineState.timingAdvance, 2);
|
debugFloat(&logger, "timing", engine->engineState.timingAdvance, 2);
|
||||||
|
@ -418,7 +418,7 @@ static void showFuelInfo2(float rpm, float engineLoad) {
|
||||||
if (engine->rpmCalculator.isRunning()) {
|
if (engine->rpmCalculator.isRunning()) {
|
||||||
float iatCorrection = engine->engineState.iatFuelCorrection;
|
float iatCorrection = engine->engineState.iatFuelCorrection;
|
||||||
float cltCorrection = engine->engineState.cltFuelCorrection;
|
float cltCorrection = engine->engineState.cltFuelCorrection;
|
||||||
float injectorLag = engine->injectorLagMs;
|
floatms_t injectorLag = engine->engineState.injectorLag;
|
||||||
scheduleMsg(&logger2, "rpm=%f engineLoad=%f", rpm, engineLoad);
|
scheduleMsg(&logger2, "rpm=%f engineLoad=%f", rpm, engineLoad);
|
||||||
scheduleMsg(&logger2, "baseFuel=%f", baseFuelMs);
|
scheduleMsg(&logger2, "baseFuel=%f", baseFuelMs);
|
||||||
|
|
||||||
|
@ -603,7 +603,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
|
||||||
|
|
||||||
tsOutputChannels->injectorDutyCycle = getInjectorDutyCycle(rpm PASS_ENGINE_PARAMETER);
|
tsOutputChannels->injectorDutyCycle = getInjectorDutyCycle(rpm PASS_ENGINE_PARAMETER);
|
||||||
tsOutputChannels->runningFuel = ENGINE(engineState.runningFuel);
|
tsOutputChannels->runningFuel = ENGINE(engineState.runningFuel);
|
||||||
tsOutputChannels->injectorLagMs = ENGINE(injectorLagMs);
|
tsOutputChannels->injectorLagMs = ENGINE(engineState.injectorLag);
|
||||||
|
|
||||||
if (engineConfiguration->debugMode == TPS_ACCEL) {
|
if (engineConfiguration->debugMode == TPS_ACCEL) {
|
||||||
tsOutputChannels->debugIntField1 = engine->tpsAccelEnrichment.cb.getSize();
|
tsOutputChannels->debugIntField1 = engine->tpsAccelEnrichment.cb.getSize();
|
||||||
|
|
|
@ -33,7 +33,6 @@ extern engine_pins_s enginePins;
|
||||||
extern fuel_Map3D_t veMap;
|
extern fuel_Map3D_t veMap;
|
||||||
extern fuel_Map3D_t afrMap;
|
extern fuel_Map3D_t afrMap;
|
||||||
|
|
||||||
|
|
||||||
EXTERN_ENGINE
|
EXTERN_ENGINE
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -74,7 +73,7 @@ void Engine::updateSlowSensors(DECLARE_ENGINE_PARAMETER_F) {
|
||||||
}
|
}
|
||||||
float vBatt = hasVBatt(PASS_ENGINE_PARAMETER_F) ? getVBatt(PASS_ENGINE_PARAMETER_F) : 12;
|
float vBatt = hasVBatt(PASS_ENGINE_PARAMETER_F) ? getVBatt(PASS_ENGINE_PARAMETER_F) : 12;
|
||||||
|
|
||||||
injectorLagMs = getInjectorLag(vBatt PASS_ENGINE_PARAMETER);
|
engineState.injectorLag = getInjectorLag(vBatt PASS_ENGINE_PARAMETER);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::onTriggerEvent(efitick_t nowNt) {
|
void Engine::onTriggerEvent(efitick_t nowNt) {
|
||||||
|
@ -92,6 +91,7 @@ void Engine::addConfigurationListener(configuration_callback_t callback) {
|
||||||
|
|
||||||
Engine::Engine(persistent_config_s *config) {
|
Engine::Engine(persistent_config_s *config) {
|
||||||
init(config);
|
init(config);
|
||||||
|
engineState.warmupAfrPid.init(&config->engineConfiguration.warmupAfrPid, 0.1, 10);
|
||||||
isEngineChartEnabled = false;
|
isEngineChartEnabled = false;
|
||||||
sensorChartMode = SC_OFF;
|
sensorChartMode = SC_OFF;
|
||||||
/**
|
/**
|
||||||
|
@ -119,7 +119,7 @@ Engine::Engine(persistent_config_s *config) {
|
||||||
|
|
||||||
|
|
||||||
timeOfLastKnockEvent = 0;
|
timeOfLastKnockEvent = 0;
|
||||||
injectorLagMs = fuelMs = 0;
|
fuelMs = 0;
|
||||||
clutchDownState = clutchUpState = false;
|
clutchDownState = clutchUpState = false;
|
||||||
memset(&m, 0, sizeof(m));
|
memset(&m, 0, sizeof(m));
|
||||||
|
|
||||||
|
@ -129,6 +129,7 @@ Engine::Engine(persistent_config_s *config) {
|
||||||
EngineState::EngineState() {
|
EngineState::EngineState() {
|
||||||
dwellAngle = 0;
|
dwellAngle = 0;
|
||||||
engineNoiseHipLevel = 0;
|
engineNoiseHipLevel = 0;
|
||||||
|
injectorLag = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) {
|
void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) {
|
||||||
|
@ -138,7 +139,11 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) {
|
||||||
dwellAngle = sparkDwell / getOneDegreeTimeMs(rpm);
|
dwellAngle = sparkDwell / getOneDegreeTimeMs(rpm);
|
||||||
|
|
||||||
iatFuelCorrection = getIatCorrection(iat PASS_ENGINE_PARAMETER);
|
iatFuelCorrection = getIatCorrection(iat PASS_ENGINE_PARAMETER);
|
||||||
|
if (boardConfiguration->useWarmupPidAfr && clt < 80) {
|
||||||
|
|
||||||
|
} else {
|
||||||
cltFuelCorrection = getCltCorrection(clt PASS_ENGINE_PARAMETER);
|
cltFuelCorrection = getCltCorrection(clt PASS_ENGINE_PARAMETER);
|
||||||
|
}
|
||||||
|
|
||||||
engineNoiseHipLevel = interpolate2d(rpm, engineConfiguration->knockNoiseRpmBins,
|
engineNoiseHipLevel = interpolate2d(rpm, engineConfiguration->knockNoiseRpmBins,
|
||||||
engineConfiguration->knockNoise, ENGINE_NOISE_CURVE_SIZE);
|
engineConfiguration->knockNoise, ENGINE_NOISE_CURVE_SIZE);
|
||||||
|
|
|
@ -7,11 +7,11 @@
|
||||||
#ifndef ENGINE_H_
|
#ifndef ENGINE_H_
|
||||||
#define ENGINE_H_
|
#define ENGINE_H_
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "pid.h"
|
||||||
#include "engine_configuration.h"
|
#include "engine_configuration.h"
|
||||||
#include "rpm_calculator.h"
|
#include "rpm_calculator.h"
|
||||||
|
|
||||||
#include "global.h"
|
|
||||||
#include "engine_configuration.h"
|
#include "engine_configuration.h"
|
||||||
#include "event_registry.h"
|
#include "event_registry.h"
|
||||||
#include "trigger_structure.h"
|
#include "trigger_structure.h"
|
||||||
|
@ -102,9 +102,12 @@ public:
|
||||||
void periodicFastCallback(DECLARE_ENGINE_PARAMETER_F);
|
void periodicFastCallback(DECLARE_ENGINE_PARAMETER_F);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WIP: accessing these values here would be a performance optimization since log() function needed for
|
* Performance optimization:
|
||||||
* thermistor logic is relatively heavy
|
* log() function needed for thermistor logic is relatively heavy, to avoid it we have these
|
||||||
|
* pre-calculated values
|
||||||
* Access to these two fields is not synchronized in any way - that should work since float read/write are atomic.
|
* Access to these two fields is not synchronized in any way - that should work since float read/write are atomic.
|
||||||
|
*
|
||||||
|
* values are in Celsius
|
||||||
*/
|
*/
|
||||||
float iat;
|
float iat;
|
||||||
float clt;
|
float clt;
|
||||||
|
@ -139,7 +142,15 @@ public:
|
||||||
// fuel-related;
|
// fuel-related;
|
||||||
float iatFuelCorrection;
|
float iatFuelCorrection;
|
||||||
float cltFuelCorrection;
|
float cltFuelCorrection;
|
||||||
float injectorLag;
|
/**
|
||||||
|
* Global injector lag + injectorLag(VBatt)
|
||||||
|
*
|
||||||
|
* this value depends on a slow-changing VBatt value, so
|
||||||
|
* we update it once in a while
|
||||||
|
*/
|
||||||
|
floatms_t injectorLag;
|
||||||
|
|
||||||
|
Pid warmupAfrPid;
|
||||||
|
|
||||||
float baroCorrection;
|
float baroCorrection;
|
||||||
|
|
||||||
|
@ -329,13 +340,6 @@ public:
|
||||||
EngineState engineState;
|
EngineState engineState;
|
||||||
efitick_t lastTriggerEventTimeNt;
|
efitick_t lastTriggerEventTimeNt;
|
||||||
|
|
||||||
/**
|
|
||||||
* Global injector lag + injectorLag(VBatt)
|
|
||||||
*
|
|
||||||
* this value depends on a slow-changing VBatt value, so
|
|
||||||
* we update it once in a while
|
|
||||||
*/
|
|
||||||
float injectorLagMs;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This coefficient translates ADC value directly into voltage adjusted according to
|
* This coefficient translates ADC value directly into voltage adjusted according to
|
||||||
|
|
|
@ -128,7 +128,7 @@ floatms_t getFuelMs(int rpm DECLARE_ENGINE_PARAMETER_S) {
|
||||||
theoreticalInjectionLength = fuelPerCycle
|
theoreticalInjectionLength = fuelPerCycle
|
||||||
/ getNumberOfInjections(engineConfiguration->injectionMode PASS_ENGINE_PARAMETER);
|
/ getNumberOfInjections(engineConfiguration->injectionMode PASS_ENGINE_PARAMETER);
|
||||||
}
|
}
|
||||||
return theoreticalInjectionLength + ENGINE(injectorLagMs);
|
return theoreticalInjectionLength + ENGINE(engineState.injectorLag);
|
||||||
}
|
}
|
||||||
|
|
||||||
floatms_t getRunningFuel(floatms_t baseFuel, int rpm DECLARE_ENGINE_PARAMETER_S) {
|
floatms_t getRunningFuel(floatms_t baseFuel, int rpm DECLARE_ENGINE_PARAMETER_S) {
|
||||||
|
|
|
@ -72,12 +72,7 @@ static msg_t AltCtrlThread(int param) {
|
||||||
#if ! EFI_UNIT_TEST || defined(__DOXYGEN__)
|
#if ! EFI_UNIT_TEST || defined(__DOXYGEN__)
|
||||||
if (engineConfiguration->debugMode == ALTERNATOR) {
|
if (engineConfiguration->debugMode == ALTERNATOR) {
|
||||||
tsOutputChannels.debugFloatField1 = currentAltDuty;
|
tsOutputChannels.debugFloatField1 = currentAltDuty;
|
||||||
tsOutputChannels.debugFloatField2 = altPid.getIntegration();
|
altPid.postState(&tsOutputChannels);
|
||||||
tsOutputChannels.debugFloatField3 = altPid.getPrevError();
|
|
||||||
tsOutputChannels.debugFloatField4 = altPid.getI();
|
|
||||||
tsOutputChannels.debugFloatField5 = altPid.getD();
|
|
||||||
tsOutputChannels.debugIntField1 = altPid.getP();
|
|
||||||
tsOutputChannels.debugIntField2 = engineConfiguration->alternatorControl.offset;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "pid.h"
|
#include "pid.h"
|
||||||
|
#include "math.h"
|
||||||
|
|
||||||
|
Pid::Pid() {
|
||||||
|
init(NULL, NAN, NAN);
|
||||||
|
}
|
||||||
|
|
||||||
Pid::Pid(pid_s *pid, float minResult, float maxResult) {
|
Pid::Pid(pid_s *pid, float minResult, float maxResult) {
|
||||||
|
init(pid, minResult, maxResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Pid::init(pid_s *pid, float minResult, float maxResult) {
|
||||||
this->pid = pid;
|
this->pid = pid;
|
||||||
this->minResult = minResult;
|
this->minResult = minResult;
|
||||||
this->maxResult = maxResult;
|
this->maxResult = maxResult;
|
||||||
|
@ -70,4 +79,17 @@ float Pid::getD(void) {
|
||||||
return pid->dFactor;
|
return pid->dFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Pid::getOffset(void) {
|
||||||
|
return pid->offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if EFI_PROD_CODE || EFI_SIMULATOR
|
||||||
|
void Pid::postState(TunerStudioOutputChannels *tsOutputChannels) {
|
||||||
|
tsOutputChannels->debugFloatField2 = getIntegration();
|
||||||
|
tsOutputChannels->debugFloatField3 = getPrevError();
|
||||||
|
tsOutputChannels->debugFloatField4 = getI();
|
||||||
|
tsOutputChannels->debugFloatField5 = getD();
|
||||||
|
tsOutputChannels->debugIntField1 = getP();
|
||||||
|
tsOutputChannels->debugIntField2 = getOffset();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -8,20 +8,31 @@
|
||||||
#ifndef PID_H_
|
#ifndef PID_H_
|
||||||
#define PID_H_
|
#define PID_H_
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
#include "engine_configuration_generated_structures.h"
|
#include "engine_configuration_generated_structures.h"
|
||||||
|
#if EFI_PROD_CODE || EFI_SIMULATOR
|
||||||
|
#include "tunerstudio_configuration.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
class Pid {
|
class Pid {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Pid();
|
||||||
Pid(pid_s *pid, float minResult, float maxResult);
|
Pid(pid_s *pid, float minResult, float maxResult);
|
||||||
|
void init(pid_s *pid, float minResult, float maxResult);
|
||||||
|
|
||||||
float getValue(float target, float input, float dTime);
|
float getValue(float target, float input, float dTime);
|
||||||
void updateFactors(float pFactor, float iFactor, float dFactor);
|
void updateFactors(float pFactor, float iFactor, float dFactor);
|
||||||
void reset(void);
|
void reset(void);
|
||||||
float getP(void);
|
float getP(void);
|
||||||
float getI(void);
|
float getI(void);
|
||||||
float getD(void);
|
float getD(void);
|
||||||
|
float getOffset(void);
|
||||||
float getIntegration(void);
|
float getIntegration(void);
|
||||||
float getPrevError(void);
|
float getPrevError(void);
|
||||||
|
#if EFI_PROD_CODE || EFI_SIMULATOR
|
||||||
|
void postState(TunerStudioOutputChannels *tsOutputChannels);
|
||||||
|
#endif
|
||||||
private:
|
private:
|
||||||
pid_s *pid;
|
pid_s *pid;
|
||||||
float minResult;
|
float minResult;
|
||||||
|
|
Loading…
Reference in New Issue