auto-sync

This commit is contained in:
rusEfi 2016-02-06 12:02:24 -05:00
parent 2828e1faca
commit 9dd88a1dc1
7 changed files with 63 additions and 26 deletions

View File

@ -261,7 +261,7 @@ static void printState(void) {
debugFloat(&logger, "fuel_base", baseFuel, 2);
// debugFloat(&logger, "fuel_iat", getIatCorrection(getIntakeAirTemperature()), 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, "timing", engine->engineState.timingAdvance, 2);
@ -418,7 +418,7 @@ static void showFuelInfo2(float rpm, float engineLoad) {
if (engine->rpmCalculator.isRunning()) {
float iatCorrection = engine->engineState.iatFuelCorrection;
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, "baseFuel=%f", baseFuelMs);
@ -603,7 +603,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
tsOutputChannels->injectorDutyCycle = getInjectorDutyCycle(rpm PASS_ENGINE_PARAMETER);
tsOutputChannels->runningFuel = ENGINE(engineState.runningFuel);
tsOutputChannels->injectorLagMs = ENGINE(injectorLagMs);
tsOutputChannels->injectorLagMs = ENGINE(engineState.injectorLag);
if (engineConfiguration->debugMode == TPS_ACCEL) {
tsOutputChannels->debugIntField1 = engine->tpsAccelEnrichment.cb.getSize();

View File

@ -33,7 +33,6 @@ extern engine_pins_s enginePins;
extern fuel_Map3D_t veMap;
extern fuel_Map3D_t afrMap;
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;
injectorLagMs = getInjectorLag(vBatt PASS_ENGINE_PARAMETER);
engineState.injectorLag = getInjectorLag(vBatt PASS_ENGINE_PARAMETER);
}
void Engine::onTriggerEvent(efitick_t nowNt) {
@ -92,6 +91,7 @@ void Engine::addConfigurationListener(configuration_callback_t callback) {
Engine::Engine(persistent_config_s *config) {
init(config);
engineState.warmupAfrPid.init(&config->engineConfiguration.warmupAfrPid, 0.1, 10);
isEngineChartEnabled = false;
sensorChartMode = SC_OFF;
/**
@ -119,7 +119,7 @@ Engine::Engine(persistent_config_s *config) {
timeOfLastKnockEvent = 0;
injectorLagMs = fuelMs = 0;
fuelMs = 0;
clutchDownState = clutchUpState = false;
memset(&m, 0, sizeof(m));
@ -129,6 +129,7 @@ Engine::Engine(persistent_config_s *config) {
EngineState::EngineState() {
dwellAngle = 0;
engineNoiseHipLevel = 0;
injectorLag = 0;
}
void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) {
@ -138,7 +139,11 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) {
dwellAngle = sparkDwell / getOneDegreeTimeMs(rpm);
iatFuelCorrection = getIatCorrection(iat PASS_ENGINE_PARAMETER);
cltFuelCorrection = getCltCorrection(clt PASS_ENGINE_PARAMETER);
if (boardConfiguration->useWarmupPidAfr && clt < 80) {
} else {
cltFuelCorrection = getCltCorrection(clt PASS_ENGINE_PARAMETER);
}
engineNoiseHipLevel = interpolate2d(rpm, engineConfiguration->knockNoiseRpmBins,
engineConfiguration->knockNoise, ENGINE_NOISE_CURVE_SIZE);

View File

@ -7,11 +7,11 @@
#ifndef ENGINE_H_
#define ENGINE_H_
#include "global.h"
#include "main.h"
#include "pid.h"
#include "engine_configuration.h"
#include "rpm_calculator.h"
#include "global.h"
#include "engine_configuration.h"
#include "event_registry.h"
#include "trigger_structure.h"
@ -102,9 +102,12 @@ public:
void periodicFastCallback(DECLARE_ENGINE_PARAMETER_F);
/**
* WIP: accessing these values here would be a performance optimization since log() function needed for
* thermistor logic is relatively heavy
* Performance optimization:
* 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.
*
* values are in Celsius
*/
float iat;
float clt;
@ -139,7 +142,15 @@ public:
// fuel-related;
float iatFuelCorrection;
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;
@ -329,13 +340,6 @@ public:
EngineState engineState;
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

View File

@ -128,7 +128,7 @@ floatms_t getFuelMs(int rpm DECLARE_ENGINE_PARAMETER_S) {
theoreticalInjectionLength = fuelPerCycle
/ 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) {

View File

@ -72,12 +72,7 @@ static msg_t AltCtrlThread(int param) {
#if ! EFI_UNIT_TEST || defined(__DOXYGEN__)
if (engineConfiguration->debugMode == ALTERNATOR) {
tsOutputChannels.debugFloatField1 = currentAltDuty;
tsOutputChannels.debugFloatField2 = altPid.getIntegration();
tsOutputChannels.debugFloatField3 = altPid.getPrevError();
tsOutputChannels.debugFloatField4 = altPid.getI();
tsOutputChannels.debugFloatField5 = altPid.getD();
tsOutputChannels.debugIntField1 = altPid.getP();
tsOutputChannels.debugIntField2 = engineConfiguration->alternatorControl.offset;
altPid.postState(&tsOutputChannels);
}
#endif

View File

@ -8,8 +8,17 @@
*/
#include "pid.h"
#include "math.h"
Pid::Pid() {
init(NULL, NAN, NAN);
}
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->minResult = minResult;
this->maxResult = maxResult;
@ -70,4 +79,17 @@ float Pid::getD(void) {
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

View File

@ -8,20 +8,31 @@
#ifndef PID_H_
#define PID_H_
#include "global.h"
#include "engine_configuration_generated_structures.h"
#if EFI_PROD_CODE || EFI_SIMULATOR
#include "tunerstudio_configuration.h"
#endif
class Pid {
public:
Pid();
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);
void updateFactors(float pFactor, float iFactor, float dFactor);
void reset(void);
float getP(void);
float getI(void);
float getD(void);
float getOffset(void);
float getIntegration(void);
float getPrevError(void);
#if EFI_PROD_CODE || EFI_SIMULATOR
void postState(TunerStudioOutputChannels *tsOutputChannels);
#endif
private:
pid_s *pid;
float minResult;