move target computation (#2091)

This commit is contained in:
Matthew Kennedy 2020-12-17 14:46:51 -08:00 committed by GitHub
parent 1838beadfa
commit aeea50ada2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 13 deletions

View File

@ -193,6 +193,14 @@ void setManualIdleValvePosition(int positionPercent) {
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */
int IdleController::getTargetRpm(float clt) const {
// TODO: bump target rpm based on AC and/or fan(s)?
float fsioBump = engine->fsioState.fsioIdleTargetRPMAdjustment;
return fsioBump + interpolate2d("cltRpm", clt, CONFIG(cltIdleRpmBins), CONFIG(cltIdleRpm));
}
static percent_t manualIdleController(float cltCorrection DECLARE_ENGINE_PARAMETER_SUFFIX) { static percent_t manualIdleController(float cltCorrection DECLARE_ENGINE_PARAMETER_SUFFIX) {
percent_t correctedPosition = cltCorrection * CONFIG(manIdlePosition); percent_t correctedPosition = cltCorrection * CONFIG(manIdlePosition);
@ -269,7 +277,7 @@ static percent_t automaticIdleController(float tpsPos DECLARE_ENGINE_PARAMETER_S
industrialWithOverrideIdlePid.derivativeFilterLoss = engineConfiguration->idle_derivativeFilterLoss; industrialWithOverrideIdlePid.derivativeFilterLoss = engineConfiguration->idle_derivativeFilterLoss;
// get Target RPM for Auto-PID from a separate table // get Target RPM for Auto-PID from a separate table
int targetRpm = getTargetRpmForIdleCorrection(PASS_ENGINE_PARAMETER_SIGNATURE); int targetRpm = ENGINE(idleController)->getTargetRpm(Sensor::get(SensorType::Clt).value_or(0));
efitick_t nowNt = getTimeNowNt(); efitick_t nowNt = getTimeNowNt();
efitimeus_t nowUs = getTimeNowUs(); efitimeus_t nowUs = getTimeNowUs();
@ -580,6 +588,8 @@ void startIdleThread(Logging*sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
INJECT_ENGINE_REFERENCE(&idleControllerInstance); INJECT_ENGINE_REFERENCE(&idleControllerInstance);
INJECT_ENGINE_REFERENCE(&industrialWithOverrideIdlePid); INJECT_ENGINE_REFERENCE(&industrialWithOverrideIdlePid);
ENGINE(idleController) = &idleControllerInstance;
getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->initPidClass(&engineConfiguration->idleRpmPid); getIdlePid(PASS_ENGINE_PARAMETER_SIGNATURE)->initPidClass(&engineConfiguration->idleRpmPid);
#if ! EFI_UNIT_TEST #if ! EFI_UNIT_TEST

View File

@ -12,15 +12,23 @@
#include "rusefi_types.h" #include "rusefi_types.h"
#include "periodic_task.h" #include "periodic_task.h"
struct IIdleController {
virtual int getTargetRpm(float clt) const = 0;
};
class Logging; class Logging;
class Pid; class Pid;
class IdleController {
class IdleController : public IIdleController {
public: public:
DECLARE_ENGINE_PTR; DECLARE_ENGINE_PTR;
float getIdlePosition(); float getIdlePosition();
void update(); void update();
// TARGET DETERMINATION
int getTargetRpm(float clt) const override;
}; };
void updateIdleControl(); void updateIdleControl();

View File

@ -128,7 +128,7 @@ angle_t getAdvanceCorrections(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
// PID Ignition Advance angle correction // PID Ignition Advance angle correction
float pidTimingCorrection = 0.0f; float pidTimingCorrection = 0.0f;
if (CONFIG(useIdleTimingPidControl)) { if (CONFIG(useIdleTimingPidControl)) {
int targetRpm = getTargetRpmForIdleCorrection(PASS_ENGINE_PARAMETER_SIGNATURE); int targetRpm = ENGINE(idleController)->getTargetRpm(Sensor::get(SensorType::Clt).value_or(0));
int rpmDelta = absI(rpm - targetRpm); int rpmDelta = absI(rpm - targetRpm);
auto [valid, tps] = Sensor::get(SensorType::Tps1); auto [valid, tps] = Sensor::get(SensorType::Tps1);

View File

@ -54,6 +54,7 @@ class AirmassModelBase;
class IEtbController; class IEtbController;
struct IFuelComputer; struct IFuelComputer;
struct IInjectorModel; struct IInjectorModel;
struct IIdleController;
class PrimaryTriggerConfiguration final : public TriggerConfiguration { class PrimaryTriggerConfiguration final : public TriggerConfiguration {
public: public:
@ -85,6 +86,7 @@ public:
IEtbController *etbControllers[ETB_COUNT] = {nullptr}; IEtbController *etbControllers[ETB_COUNT] = {nullptr};
IFuelComputer *fuelComputer = nullptr; IFuelComputer *fuelComputer = nullptr;
IInjectorModel *injectorModel = nullptr; IInjectorModel *injectorModel = nullptr;
IIdleController* idleController = nullptr;
cyclic_buffer<int> triggerErrorDetection; cyclic_buffer<int> triggerErrorDetection;

View File

@ -583,15 +583,6 @@ void setTargetRpmCurve(int rpm DECLARE_CONFIG_PARAMETER_SUFFIX) {
setLinearCurve(engineConfiguration->cltIdleRpm, rpm, rpm, 10); setLinearCurve(engineConfiguration->cltIdleRpm, rpm, rpm, 10);
} }
int getTargetRpmForIdleCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// error is already reported, let's take the value at 0C since that should be a nice high idle
float clt = Sensor::get(SensorType::Clt).value_or(0);
int targetRpm = interpolate2d("cltRpm", clt, CONFIG(cltIdleRpmBins), CONFIG(cltIdleRpm));
return targetRpm + engine->fsioState.fsioIdleTargetRPMAdjustment;
}
void setDefaultMultisparkParameters(DECLARE_ENGINE_PARAMETER_SIGNATURE) { void setDefaultMultisparkParameters(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// 1ms spark + 2ms dwell // 1ms spark + 2ms dwell
engineConfiguration->multisparkSparkDuration = 1000; engineConfiguration->multisparkSparkDuration = 1000;

View File

@ -26,7 +26,6 @@ void setOperationMode(engine_configuration_s *engineConfiguration, operation_mod
void prepareVoidConfiguration(engine_configuration_s *activeConfiguration); void prepareVoidConfiguration(engine_configuration_s *activeConfiguration);
void setTargetRpmCurve(int rpm DECLARE_CONFIG_PARAMETER_SUFFIX); void setTargetRpmCurve(int rpm DECLARE_CONFIG_PARAMETER_SUFFIX);
int getTargetRpmForIdleCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void setLambdaMap(lambda_table_t table, float value); void setLambdaMap(lambda_table_t table, float value);
/** /**
* See also setLinearCurve() * See also setLinearCurve()

View File

@ -130,3 +130,17 @@ TEST(idle, timingPid) {
ASSERT_FLOAT_EQ(-5.0f, corr) << "getAdvanceCorrections#7"; ASSERT_FLOAT_EQ(-5.0f, corr) << "getAdvanceCorrections#7";
} }
TEST(idle_v2, testTargetRpm) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
IdleController dut;
INJECT_ENGINE_REFERENCE(&dut);
for (size_t i = 0; i < efi::size(engineConfiguration->cltIdleRpmBins); i++) {
CONFIG(cltIdleRpmBins)[i] = i * 10;
CONFIG(cltIdleRpm)[i] = i * 100;
}
EXPECT_FLOAT_EQ(100, dut.getTargetRpm(10));
EXPECT_FLOAT_EQ(500, dut.getTargetRpm(50));
}