Autoscale all the things! (#3713)

* Map3D accepts any scaled_channel type

* consistency

* reinstate test

* fix ratio

* throttle, boost, gppwm

* scale ignition and VE

* tests
This commit is contained in:
Matthew Kennedy 2021-12-22 05:09:41 -08:00 committed by GitHub
parent 40a9a72693
commit a4871c703c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 27 additions and 34 deletions

View File

@ -62,7 +62,7 @@ expected<float> BoostController::getSetpoint() {
return unexpected;
}
return m_closedLoopTargetMap->getValue(rpm / RPM_1_BYTE_PACKING_MULT, tps.Value / TPS_1_BYTE_PACKING_MULT);
return m_closedLoopTargetMap->getValue(rpm, tps.Value);
}
expected<percent_t> BoostController::getOpenLoop(float target) {
@ -82,7 +82,7 @@ expected<percent_t> BoostController::getOpenLoop(float target) {
return unexpected;
}
percent_t openLoop = m_openLoopMap->getValue(rpm / RPM_1_BYTE_PACKING_MULT, tps.Value / TPS_1_BYTE_PACKING_MULT);
percent_t openLoop = m_openLoopMap->getValue(rpm, tps.Value);
#if EFI_TUNER_STUDIO
if (engineConfiguration->debugMode == DBG_BOOST) {
@ -180,13 +180,13 @@ void setDefaultBoostParameters() {
engineConfiguration->boostControlPin = GPIO_UNASSIGNED;
engineConfiguration->boostControlPinMode = OM_DEFAULT;
setLinearCurve(config->boostRpmBins, 0, 8000 / RPM_1_BYTE_PACKING_MULT, 1);
setLinearCurve(config->boostTpsBins, 0, 100 / TPS_1_BYTE_PACKING_MULT, 1);
setLinearCurve(config->boostRpmBins, 0, 8000, 1);
setLinearCurve(config->boostTpsBins, 0, 100, 1);
for (int loadIndex = 0; loadIndex < BOOST_LOAD_COUNT; loadIndex++) {
for (int rpmIndex = 0; rpmIndex < BOOST_RPM_COUNT; rpmIndex++) {
config->boostTableOpenLoop[loadIndex][rpmIndex] = config->boostTpsBins[loadIndex];
config->boostTableClosedLoop[loadIndex][rpmIndex] = config->boostTpsBins[loadIndex];
config->boostTableOpenLoop[loadIndex][rpmIndex] = (float)config->boostTpsBins[loadIndex];
config->boostTableClosedLoop[loadIndex][rpmIndex] = (float)config->boostTpsBins[loadIndex];
}
}

View File

@ -299,7 +299,7 @@ expected<percent_t> EtbController::getSetpointEtb() const {
float sanitizedPedal = clampF(0, pedalPosition.value_or(0), 100);
float rpm = GET_RPM();
float targetFromTable = m_pedalMap->getValue(rpm / RPM_1_BYTE_PACKING_MULT, sanitizedPedal);
float targetFromTable = m_pedalMap->getValue(rpm, sanitizedPedal);
engine->engineState.targetFromTable = targetFromTable;
percent_t etbIdlePosition = clampF(
@ -826,7 +826,7 @@ void setDefaultEtbParameters() {
engineConfiguration->etbIdleThrottleRange = 5;
setLinearCurve(config->pedalToTpsPedalBins, /*from*/0, /*to*/100, 1);
setLinearCurve(config->pedalToTpsRpmBins, /*from*/0, /*to*/8000 / RPM_1_BYTE_PACKING_MULT, 1);
setLinearCurve(config->pedalToTpsRpmBins, /*from*/0, /*to*/8000, 1);
for (int pedalIndex = 0;pedalIndex<PEDAL_TO_TPS_SIZE;pedalIndex++) {
for (int rpmIndex = 0;rpmIndex<PEDAL_TO_TPS_SIZE;rpmIndex++) {

View File

@ -80,7 +80,7 @@ percent_t GppwmChannel::getOutput() const {
float rpm = GET_RPM();
float result = m_table->getValue(rpm / RPM_1_BYTE_PACKING_MULT, loadAxisValue.Value);
float result = m_table->getValue(rpm, loadAxisValue.Value);
if (cisnan(result)) {
return m_config->dutyIfError;

View File

@ -42,7 +42,7 @@ static void setDefaultIatTimingCorrection() {
// Set each row of the table to the same value (no rpm dependence by default)
for (size_t i = 0; i < efi::size(defaultIatCorr); i++) {
setArrayValues(config->ignitionIatCorrTable[i], (float)defaultIatCorr[i]);
setArrayValues(config->ignitionIatCorrTable[i], defaultIatCorr[i]);
}
#else
setLinearCurve(config->ignitionIatCorrLoadBins, /*from*/0, 6000, 1);

View File

@ -390,7 +390,7 @@ void setDefaultGppwmParameters() {
}
for (size_t j = 0; j < efi::size(cfg.rpmBins); j++) {
cfg.rpmBins[j] = 1000 * j / RPM_1_BYTE_PACKING_MULT;
cfg.rpmBins[j] = 1000 * j;
}
}
}

View File

@ -70,7 +70,7 @@
! Any time an incompatible change is made to the configuration format stored in flash,
! update this string to the current date! It is required to also update TS_SIGNATURE above
! when this happens.
#define FLASH_DATA_VERSION 10005
#define FLASH_DATA_VERSION 10006
#define LOG_DELIMITER "`"
@ -213,9 +213,7 @@ struct_no_prefix engine_configuration_s
#define PACK_MULT_ANGLE 50
#define PACK_MULT_VOLTAGE 1000
#define PACK_MULT_MASS_FLOW 10
#define TPS_1_BYTE_PACKING_MULT 2
#define TPS_2_BYTE_PACKING_MULT 100
#define LOAD_1_BYTE_PACKING_MULT 2
#define PACK_MULT_AFR_CFG 10
#define PACK_MULT_LAMBDA_CFG 147
#define PACK_MULT_FUEL_MASS 100
@ -357,7 +355,7 @@ struct gppwm_channel
uint8_t alignmentFill_map;;"unit", 1, 0, 0, 100, 0
uint8_t[GPPWM_LOAD_COUNT] loadBins;;"load", 1, 0, 0, 250, 0
uint8_t[GPPWM_RPM_COUNT] rpmBins;;"RPM", @@RPM_1_BYTE_PACKING_MULT@@, 0, 0, 12000, 0
uint8_t[GPPWM_RPM_COUNT] autoscale rpmBins;;"RPM", @@RPM_1_BYTE_PACKING_MULT@@, 0, 0, 12000, 0
uint8_t[GPPWM_RPM_COUNT x GPPWM_LOAD_COUNT] table;;"duty", 1, 0, 0, 100, 0
end_struct
@ -1500,18 +1498,15 @@ float[AFTERSTART_HOLD_CURVE_SIZE] afterstartHoldTime;;"Seconds", 1, 0, 0, 100, 1
float[AFTERSTART_ENRICH_CURVE_SIZE] afterstartEnrich;;"%", 1, 0, 0, 600, 1
float[AFTERSTART_DECAY_CURVE_SIZE] afterstartDecayTime;;"Seconds", 1, 0, 0, 100, 1
! TODO: use autoscale
uint8_t[BOOST_RPM_COUNT x BOOST_LOAD_COUNT] boostTableOpenLoop;;"", @@LOAD_1_BYTE_PACKING_MULT@@, 0 , 0, 100, 0
uint8_t[BOOST_RPM_COUNT] boostRpmBins;;"RPM", @@RPM_1_BYTE_PACKING_MULT@@, 0, 0, 12000, 0
uint8_t[BOOST_RPM_COUNT x BOOST_LOAD_COUNT] autoscale boostTableOpenLoop;;"", {1/2}, 0 , 0, 100, 1
uint8_t[BOOST_RPM_COUNT] autoscale boostRpmBins;;"RPM", @@RPM_1_BYTE_PACKING_MULT@@, 0, 0, 12000, 0
! TODO: use autoscale
uint8_t[BOOST_RPM_COUNT x BOOST_LOAD_COUNT] boostTableClosedLoop;;"", @@LOAD_1_BYTE_PACKING_MULT@@, 0 , 0, 3000, 0
uint8_t[BOOST_LOAD_COUNT] boostTpsBins;;"%", @@TPS_1_BYTE_PACKING_MULT@@, 0, 0, 100, 2
uint8_t[BOOST_RPM_COUNT x BOOST_LOAD_COUNT] autoscale boostTableClosedLoop;;"", 2, 0 , 0, 3000, 0
uint8_t[BOOST_LOAD_COUNT] autoscale boostTpsBins;;"%", 1, 0, 0, 100, 0
uint8_t[PEDAL_TO_TPS_SIZE x PEDAL_TO_TPS_SIZE] pedalToTpsTable;;"%", 1, 0, 0, 100, 0
uint8_t[PEDAL_TO_TPS_SIZE] pedalToTpsPedalBins;;"%", 1, 0, 0, 120, 0
! it's not serious to use one byte for RPM but let me try that just to try it
uint8_t[PEDAL_TO_TPS_SIZE] pedalToTpsRpmBins;;"RPM", @@RPM_1_BYTE_PACKING_MULT@@, 0, 0, 12000, 0
uint8_t[PEDAL_TO_TPS_SIZE] autoscale pedalToTpsRpmBins;;"RPM", @@RPM_1_BYTE_PACKING_MULT@@, 0, 0, 12000, 0
float[CLT_CRANKING_CURVE_SIZE] cltCrankingCorrBins;CLT-based cranking position multiplier for simple manual idle controller;"C", 1, 0, -100, 250, 2
float[CLT_CRANKING_CURVE_SIZE] cltCrankingCorr ;CLT-based cranking position multiplier for simple manual idle controller;"%", 1, 0, 0, 500, 2
@ -1543,11 +1538,11 @@ float[CLT_CURVE_SIZE] cltIdleCorr; CLT-based idle position multiplier for sim
float[MAF_DECODING_COUNT] mafDecoding;Also known as MAF transfer function.\nkg/hour value.\nBy the way 2.081989116 kg/h = 1 ft3/m;"kg/hour", 1, 0, -500, 4000, 2
float[MAF_DECODING_COUNT] mafDecodingBins;;"V", 1, 0, -5, 150, 2
float[IGN_RPM_COUNT x IGN_LOAD_COUNT] ignitionIatCorrTable;;"deg", 1, 0, -720, 720, 1
int16_t[IGN_RPM_COUNT x IGN_LOAD_COUNT] autoscale ignitionIatCorrTable;;"deg", 0.1, 0, -720, 720, 1
float[IGN_LOAD_COUNT] ignitionIatCorrLoadBins;;"Temperature", 1, 0, 0, 500, 0
uint16_t[IGN_RPM_COUNT] ignitionIatCorrRpmBins;;"RPM", 1, 0, 0, 18000, 0
float[IGN_RPM_COUNT x IGN_LOAD_COUNT] injectionPhase;;"deg", 1, 0, -720, 720, 0
int16_t[IGN_RPM_COUNT x IGN_LOAD_COUNT] injectionPhase;;"deg", 1, 0, -720, 720, 0
uint16_t[FUEL_LOAD_COUNT] injPhaseLoadBins;;"Load", 1, 0, 0, 500, 0
uint16_t[FUEL_RPM_COUNT] injPhaseRpmBins;;"RPM", 1, 0, 0, 18000, 0
@ -1567,11 +1562,11 @@ uint8_t[SCRIPT_TABLE_8 x SCRIPT_TABLE_8] vvtTable2;;"value", 1, 0, 0, 255, 0
uint16_t[SCRIPT_TABLE_8] vvtTable2LoadBins;;"L", 1, 0, 0, 255, 0
uint16_t[SCRIPT_TABLE_8] vvtTable2RpmBins;;"RPM", 1, 0, 0, 18000, 0
float[IGN_RPM_COUNT x IGN_LOAD_COUNT] ignitionTable;;"deg", 1, 0, -20, 90, 1
int16_t[IGN_RPM_COUNT x IGN_LOAD_COUNT] autoscale ignitionTable;;"deg", 0.1, 0, -20, 90, 1
uint16_t[IGN_LOAD_COUNT] ignitionLoadBins;;"Load", 1, 0, 0, 500, 0
uint16_t[IGN_RPM_COUNT] ignitionRpmBins;;"RPM", 1, 0, 0, 18000, 0
float[FUEL_RPM_COUNT x FUEL_LOAD_COUNT] veTable;;"%", 1, 0, 0, 999, 1
uint16_t[FUEL_RPM_COUNT x FUEL_LOAD_COUNT] autoscale veTable;;"%", 0.1, 0, 0, 999, 1
uint16_t[FUEL_LOAD_COUNT] veLoadBins;;"kPa", 1, 0, 0, 400, 0
uint16_t[FUEL_RPM_COUNT] veRpmBins;;"RPM", 1, 0, 0, 18000, 0

View File

@ -118,7 +118,7 @@ private:
};
typedef Map3D<FUEL_RPM_COUNT, FUEL_LOAD_COUNT, uint8_t, uint16_t, uint16_t> lambda_Map3D_t;
typedef Map3D<FUEL_RPM_COUNT, FUEL_LOAD_COUNT, float, uint16_t, uint16_t> fuel_Map3D_t;
typedef Map3D<FUEL_RPM_COUNT, FUEL_LOAD_COUNT, uint16_t, uint16_t, uint16_t> fuel_Map3D_t;
typedef Map3D<BARO_CORR_SIZE, BARO_CORR_SIZE, float, float, float> baroCorr_Map3D_t;
typedef Map3D<PEDAL_TO_TPS_SIZE, PEDAL_TO_TPS_SIZE, uint8_t, uint8_t, uint8_t> pedal2tps_t;
typedef Map3D<BOOST_RPM_COUNT, BOOST_LOAD_COUNT, uint8_t, uint8_t, uint8_t> boostOpenLoop_Map3D_t;
@ -142,7 +142,7 @@ void setLinearCurve(TValue (&array)[TSize], float from, float to, float precisio
}
template<typename TValue, int TSize>
void setArrayValues(TValue (&array)[TSize], TValue value) {
void setArrayValues(TValue (&array)[TSize], float value) {
for (int i = 0; i < TSize; i++) {
array[i] = value;
}

View File

@ -10,7 +10,7 @@ TEST(BoostControl, Setpoint) {
// Just pass TPS input to output
EXPECT_CALL(targetMap, getValue(_, _))
.WillRepeatedly([](float xRpm, float tps) { return tps * 2; });
.WillRepeatedly([](float xRpm, float tps) { return tps; });
EngineTestHelper eth(TEST_ENGINE);
engineConfiguration->boostType = CLOSED_LOOP;
@ -51,7 +51,7 @@ TEST(BoostControl, OpenLoop) {
// Just pass MAP input to output
EXPECT_CALL(openMap, getValue(_, _))
.WillRepeatedly([](float xRpm, float tps) { return tps * 2; });
.WillRepeatedly([](float xRpm, float tps) { return tps; });
EngineTestHelper eth(TEST_ENGINE);

View File

@ -84,7 +84,7 @@ TEST(GpPwm, GetOutput) {
MockVp3d table;
engine->rpmCalculator.mockRpm = 1200;
EXPECT_CALL(table, getValue(1200 / RPM_1_BYTE_PACKING_MULT, 35.0f))
EXPECT_CALL(table, getValue(1200, 35.0f))
.WillRepeatedly([](float x, float tps) {
return tps;
});

View File

@ -533,8 +533,6 @@ TEST(misc, testTriggerDecoder) {
testTriggerDecoder2("vw ABA", VW_ABA, 0, 0.51666, 0.0);
}
extern fuel_Map3D_t fuelMap;
static void assertInjectionEventBase(const char *msg, InjectionEvent *ev, int injectorIndex, int eventIndex, angle_t angleOffset) {
ASSERT_EQ(injectorIndex, ev->outputs[0]->injectorIndex) << msg << "inj index";
assertEqualsM4(msg, " event index", eventIndex, ev->injectionStart.triggerEventIndex);