PID - fix dTime usages #776

This commit is contained in:
rusefi 2019-04-25 21:31:33 -04:00
parent 1123eb99ff
commit f04732830f
9 changed files with 11 additions and 7 deletions

View File

@ -232,7 +232,7 @@ private:
}
*/
currentEtbDuty = feedForward +
pid.getOutput(targetPosition, actualThrottlePosition, engineConfiguration->etb.periodMs / 1000.0);
pid.getOutput(targetPosition, actualThrottlePosition);
etb1.dcMotor.Set(PERCENT_TO_DUTY(currentEtbDuty));
/*

View File

@ -223,7 +223,7 @@ static percent_t automaticIdleController() {
// If errorAmpCoef > 1.0, then PID thinks that RPM is lower than it is, and controls IAC more aggressively
idlePid.setErrorAmplification(errorAmpCoef);
percent_t newValue = idlePid.getOutput(targetRpm, rpm, engineConfiguration->idleRpmPid.periodMs);
percent_t newValue = idlePid.getOutput(targetRpm, rpm);
idleState = PID_VALUE;
// the state of PID has been changed, so we might reset it now, but only when needed (see idlePidDeactivationTpsThreshold)

View File

@ -137,7 +137,8 @@ angle_t getAdvanceCorrections(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
shouldResetTimingPid = false;
}
// get PID value (this is not an actual Advance Angle, but just a additive correction!)
percent_t timingRawCorr = idleTimingPid.getOutput(targetRpm, rpm, engineConfiguration->idleTimingPid.periodMs);
percent_t timingRawCorr = idleTimingPid.getOutput(targetRpm, rpm,
/* is this the right dTime? this period is not exactly the period at which this code is invoked*/engineConfiguration->idleTimingPid.periodMs);
// tps idle-running falloff
pidTimingCorrection = interpolateClamped(0.0f, timingRawCorr, CONFIGB(idlePidDeactivationTpsThreshold), 0.0f, tps);
// rpm falloff

View File

@ -43,6 +43,7 @@ public:
};
#define MAX_INJECTION_OUTPUT_COUNT INJECTION_PIN_COUNT
#define FAST_CALLBACK_PERIOD_MS 20
/**
* This class knows about when to inject fuel

View File

@ -153,7 +153,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
cltFuelCorrection = 1;
warmupAfrPid.reset();
} else {
cltFuelCorrection = warmupAfrPid.getOutput(warmupTargetAfr, engine->sensors.currentAfr, 1);
cltFuelCorrection = warmupAfrPid.getOutput(warmupTargetAfr, engine->sensors.currentAfr, MS2SEC(FAST_CALLBACK_PERIOD_MS));
}
if (engineConfiguration->debugMode == DBG_WARMUP_ENRICH) {
#if EFI_TUNER_STUDIO

View File

@ -231,7 +231,7 @@ static void periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
* not many reasons why we use ChibiOS timer and not say a dedicated thread here
* the only down-side of a dedicated thread is the cost of thread stack
*/
chVTSetAny(&periodicFastTimer, TIME_MS2I(20), (vtfunc_t) &periodicFastCallback, engine);
chVTSetAny(&periodicFastTimer, TIME_MS2I(FAST_CALLBACK_PERIOD_MS), (vtfunc_t) &periodicFastCallback, engine);
}
static void resetAccel(void) {

View File

@ -353,7 +353,7 @@ static void fuelClosedLoopCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return;
}
engine->engineState.fuelPidCorrection = fuelPid.getOutput(ENGINE(engineState.targetAFR), ENGINE(sensors.currentAfr), 1);
engine->engineState.fuelPidCorrection = fuelPid.getOutput(ENGINE(engineState.targetAFR), ENGINE(sensors.currentAfr), NOT_TIME_BASED_PID);
if (engineConfiguration->debugMode == DBG_FUEL_PID_CORRECTION) {
#if EFI_TUNER_STUDIO
tsOutputChannels.debugFloatField1 = engine->engineState.fuelPidCorrection;

View File

@ -425,7 +425,7 @@ static bool cj125periodic(CJ125 *instance DECLARE_ENGINE_PARAMETER_SUFFIX) {
* error value as the difference of (target - input). and if we swap them we'll just get a sign inversion. If target=vUrCal, and input=vUr, then error=vUrCal-vUr, i.e. if vUr<vUrCal then the error will cause the heater to increase it's duty cycle. But it's not exactly what we want! Lesser vUr means HOTTER cell. That's why we even have this safety check for overheating: (vUr < CJ125_UR_OVERHEAT_THR)...
* So the simple trick is to inverse the error by swapping the target and input values.
*/
float duty = globalInstance.heaterPid.getOutput(globalInstance.vUr, globalInstance.vUrCal);
float duty = globalInstance.heaterPid.getOutput(globalInstance.vUr, globalInstance.vUrCal, MS2SEC(CJ125_TICK_DELAY));
globalInstance.heaterPid.showPidStatus(logger, "cj");
instance->SetHeater(duty PASS_ENGINE_PARAMETER_SUFFIX);
cjPrintData();

View File

@ -19,6 +19,8 @@
#define PID_AVG_BUF_SIZE_SHIFT 5
#define PID_AVG_BUF_SIZE (1<<PID_AVG_BUF_SIZE_SHIFT) // 32*sizeof(float)
#define NOT_TIME_BASED_PID 1
// minimal period 5m meaning maximum control frequency 200Hz
#define PID_MINIMAL_PERIOD_MS 5