totalFuel and totalIgnition correction gauges in Tunerstudio #4955

This commit is contained in:
Andrey 2023-01-14 23:00:28 -05:00
parent f7f1ca6809
commit df2b073c49
9 changed files with 40 additions and 34 deletions

View File

@ -94,6 +94,11 @@ const engine_state_s* getLiveData(size_t) {
return &engine->engineState; return &engine->engineState;
} }
template<>
const timing_state_s* getLiveData(size_t) {
return &engine->timingState;
}
template<> template<>
const tps_accel_state_s* getLiveData(size_t) { const tps_accel_state_s* getLiveData(size_t) {
return &engine->tpsAccelEnrichment; return &engine->tpsAccelEnrichment;

View File

@ -109,9 +109,9 @@ static angle_t getAdvanceCorrections(float engineLoad) {
auto iat = Sensor::get(SensorType::Iat); auto iat = Sensor::get(SensorType::Iat);
if (!iat) { if (!iat) {
engine->engineState.timingIatCorrection = 0; engine->timingState.timingIatCorrection = 0;
} else { } else {
engine->engineState.timingIatCorrection = interpolate3d( engine->timingState.timingIatCorrection = interpolate3d(
config->ignitionIatCorrTable, config->ignitionIatCorrTable,
config->ignitionIatCorrLoadBins, engineLoad, config->ignitionIatCorrLoadBins, engineLoad,
config->ignitionIatCorrTempBins, iat.Value config->ignitionIatCorrTempBins, iat.Value
@ -121,16 +121,16 @@ static angle_t getAdvanceCorrections(float engineLoad) {
#if EFI_SHAFT_POSITION_INPUT && EFI_IDLE_CONTROL #if EFI_SHAFT_POSITION_INPUT && EFI_IDLE_CONTROL
float instantRpm = engine->triggerCentral.instantRpm.getInstantRpm(); float instantRpm = engine->triggerCentral.instantRpm.getInstantRpm();
engine->engineState.timingPidCorrection = engine->module<IdleController>()->getIdleTimingAdjustment(instantRpm); engine->timingState.timingPidCorrection = engine->module<IdleController>()->getIdleTimingAdjustment(instantRpm);
#endif // EFI_SHAFT_POSITION_INPUT && EFI_IDLE_CONTROL #endif // EFI_SHAFT_POSITION_INPUT && EFI_IDLE_CONTROL
#if EFI_TUNER_STUDIO #if EFI_TUNER_STUDIO
engine->outputChannels.multiSparkCounter = engine->engineState.multispark.count; engine->outputChannels.multiSparkCounter = engine->engineState.multispark.count;
#endif /* EFI_TUNER_STUDIO */ #endif /* EFI_TUNER_STUDIO */
return engine->engineState.timingIatCorrection return engine->timingState.timingIatCorrection
+ engine->engineState.cltTimingCorrection + engine->timingState.cltTimingCorrection
+ engine->engineState.timingPidCorrection; + engine->timingState.timingPidCorrection;
} }
/** /**

View File

@ -10,6 +10,7 @@
#include "global_shared.h" #include "global_shared.h"
#include "engine_module.h" #include "engine_module.h"
#include "engine_state.h" #include "engine_state.h"
#include "timing_state_generated.h"
#include "rpm_calculator.h" #include "rpm_calculator.h"
#include "event_registry.h" #include "event_registry.h"
#include "table_helper.h" #include "table_helper.h"
@ -270,6 +271,7 @@ public:
void resetEngineSnifferIfInTestMode(); void resetEngineSnifferIfInTestMode();
EngineState engineState; EngineState engineState;
timing_state_s timingState;
/** /**
* idle blip is a development tool: alternator PID research for instance have benefited from a repetitive change of RPM * idle blip is a development tool: alternator PID research for instance have benefited from a repetitive change of RPM
*/ */

View File

@ -127,8 +127,8 @@ void EngineState::periodicFastCallback() {
recalculateAuxValveTiming(); recalculateAuxValveTiming();
int rpm = Sensor::getOrZero(SensorType::Rpm); int rpm = Sensor::getOrZero(SensorType::Rpm);
sparkDwell = engine->ignitionState.getSparkDwell(rpm); engine->timingState.sparkDwell = engine->ignitionState.getSparkDwell(rpm);
dwellAngle = cisnan(rpm) ? NAN : sparkDwell / getOneDegreeTimeMs(rpm); engine->timingState.dwellAngle = cisnan(rpm) ? NAN : engine->timingState.sparkDwell / getOneDegreeTimeMs(rpm);
// todo: move this into slow callback, no reason for IAT corr to be here // todo: move this into slow callback, no reason for IAT corr to be here
engine->fuelComputer.running.intakeTemperatureCoefficient = getIatFuelCorrection(); engine->fuelComputer.running.intakeTemperatureCoefficient = getIatFuelCorrection();
@ -147,7 +147,7 @@ void EngineState::periodicFastCallback() {
engine->fuelComputer.running.postCrankingFuelCorrection = 1.0f; engine->fuelComputer.running.postCrankingFuelCorrection = 1.0f;
} }
cltTimingCorrection = getCltTimingCorrection(); engine->timingState.cltTimingCorrection = getCltTimingCorrection();
baroCorrection = getBaroCorrection(); baroCorrection = getBaroCorrection();

View File

@ -63,13 +63,6 @@ cranking_fuel_s crankingFuel
custom percent_t 4 scalar, F32, @OFFSET@, "", 1, 0, 0, 100, 2 custom percent_t 4 scalar, F32, @OFFSET@, "", 1, 0, 0, 100, 2
! spark-related
floatms_t sparkDwell;ignition dwell duration in ms\nSee also dwellAngle
angle_t dwellAngle;ignition dwell duration\nas crankshaft angle\nNAN if engine is stopped\nSee also sparkDwell
int16_t autoscale cltTimingCorrection;;"deg",{1/@@PACK_MULT_PERCENT@@}, 0, -20, 20, 2
int16_t autoscale timingIatCorrection;;"deg",{1/@@PACK_MULT_PERCENT@@}, 0, -20, 20, 2
int16_t autoscale timingPidCorrection;;"deg",{1/@@PACK_MULT_PERCENT@@}, 0, -20, 20, 2
int16_t hellenBoardId;Detected Board ID;"id", 1, 0, 0, 3000, 0 int16_t hellenBoardId;Detected Board ID;"id", 1, 0, 0, 3000, 0
bit clutchUpState;@@INDICATOR_NAME_CLUTCH_UP@@ bit clutchUpState;@@INDICATOR_NAME_CLUTCH_UP@@

View File

@ -1,6 +1,6 @@
struct_no_prefix timing_state_s struct_no_prefix timing_state_s
! spark-related ! spark-related
floatms_t sparkDwell;ignition dwell duration in ms\nSee also dwellAngle floatms_t sparkDwell;@@GAUGE_COIL_DWELL_TIME@@
angle_t dwellAngle;ignition dwell duration\nas crankshaft angle\nNAN if engine is stopped\nSee also sparkDwell angle_t dwellAngle;ignition dwell duration\nas crankshaft angle\nNAN if engine is stopped\nSee also sparkDwell
int16_t autoscale cltTimingCorrection;;"deg",{1/@@PACK_MULT_PERCENT@@}, 0, -20, 20, 2 int16_t autoscale cltTimingCorrection;;"deg",{1/@@PACK_MULT_PERCENT@@}, 0, -20, 20, 2
int16_t autoscale timingIatCorrection;;"deg",{1/@@PACK_MULT_PERCENT@@}, 0, -20, 20, 2 int16_t autoscale timingIatCorrection;;"deg",{1/@@PACK_MULT_PERCENT@@}, 0, -20, 20, 2

View File

@ -221,8 +221,8 @@ if (engineConfiguration->debugMode == DBG_DWELL_METRIC) {
#endif /* EFI_UNIT_TEST */ #endif /* EFI_UNIT_TEST */
// now that we've just fired a coil let's prepare the new schedule for the next engine revolution // now that we've just fired a coil let's prepare the new schedule for the next engine revolution
angle_t dwellAngleDuration = engine->engineState.dwellAngle; angle_t dwellAngleDuration = engine->timingState.dwellAngle;
floatms_t sparkDwell = engine->engineState.sparkDwell; floatms_t sparkDwell = engine->timingState.sparkDwell;
if (cisnan(dwellAngleDuration) || cisnan(sparkDwell)) { if (cisnan(dwellAngleDuration) || cisnan(sparkDwell)) {
// we are here if engine has just stopped // we are here if engine has just stopped
return; return;
@ -321,7 +321,7 @@ static void scheduleSparkEvent(bool limitedSpark, IgnitionEvent *event,
int rpm, efitick_t edgeTimestamp, float currentPhase, float nextPhase) { int rpm, efitick_t edgeTimestamp, float currentPhase, float nextPhase) {
angle_t sparkAngle = event->sparkAngle; angle_t sparkAngle = event->sparkAngle;
const floatms_t dwellMs = engine->engineState.sparkDwell; const floatms_t dwellMs = engine->timingState.sparkDwell;
if (cisnan(dwellMs) || dwellMs <= 0) { if (cisnan(dwellMs) || dwellMs <= 0) {
warning(CUSTOM_DWELL, "invalid dwell to handle: %.2f at %d", dwellMs, rpm); warning(CUSTOM_DWELL, "invalid dwell to handle: %.2f at %d", dwellMs, rpm);
return; return;
@ -406,8 +406,8 @@ static void scheduleSparkEvent(bool limitedSpark, IgnitionEvent *event,
void initializeIgnitionActions() { void initializeIgnitionActions() {
IgnitionEventList *list = &engine->ignitionEvents; IgnitionEventList *list = &engine->ignitionEvents;
angle_t dwellAngle = engine->engineState.dwellAngle; angle_t dwellAngle = engine->timingState.dwellAngle;
floatms_t sparkDwell = engine->engineState.sparkDwell; floatms_t sparkDwell = engine->timingState.sparkDwell;
if (cisnan(engine->engineState.timingAdvance[0]) || cisnan(dwellAngle)) { if (cisnan(engine->engineState.timingAdvance[0]) || cisnan(dwellAngle)) {
// error should already be reported // error should already be reported
// need to invalidate previous ignition schedule // need to invalidate previous ignition schedule
@ -440,11 +440,11 @@ static void prepareIgnitionSchedule() {
maxAllowedDwellAngle = getEngineCycle(operationMode) / engineConfiguration->specs.cylindersCount / 1.1; maxAllowedDwellAngle = getEngineCycle(operationMode) / engineConfiguration->specs.cylindersCount / 1.1;
} }
if (engine->engineState.dwellAngle == 0) { if (engine->timingState.dwellAngle == 0) {
warning(CUSTOM_ZERO_DWELL, "dwell is zero?"); warning(CUSTOM_ZERO_DWELL, "dwell is zero?");
} }
if (engine->engineState.dwellAngle > maxAllowedDwellAngle) { if (engine->timingState.dwellAngle > maxAllowedDwellAngle) {
warning(CUSTOM_DWELL_TOO_LONG, "dwell angle too long: %.2f", engine->engineState.dwellAngle); warning(CUSTOM_DWELL_TOO_LONG, "dwell angle too long: %.2f", engine->timingState.dwellAngle);
} }
// todo: add some check for dwell overflow? like 4 times 6 ms while engine cycle is less then that // todo: add some check for dwell overflow? like 4 times 6 ms while engine cycle is less then that
@ -536,7 +536,7 @@ int getNumberOfSparks(ignition_mode_e mode) {
* @see getInjectorDutyCycle * @see getInjectorDutyCycle
*/ */
percent_t getCoilDutyCycle(int rpm) { percent_t getCoilDutyCycle(int rpm) {
floatms_t totalPerCycle = engine->engineState.sparkDwell * getNumberOfSparks(getCurrentIgnitionMode()); floatms_t totalPerCycle = engine->timingState.sparkDwell * getNumberOfSparks(getCurrentIgnitionMode());
floatms_t engineCycleDuration = getCrankshaftRevolutionTimeMs(rpm) * (getEngineRotationState()->getOperationMode() == TWO_STROKE ? 1 : 2); floatms_t engineCycleDuration = getCrankshaftRevolutionTimeMs(rpm) * (getEngineRotationState()->getOperationMode() == TWO_STROKE ? 1 : 2);
return 100 * totalPerCycle / engineCycleDuration; return 100 * totalPerCycle / engineCycleDuration;
} }

View File

@ -13,6 +13,18 @@
# todo: what is sequence of events in terms of 'live_data_e' code generation? # todo: what is sequence of events in terms of 'live_data_e' code generation?
# #
Usages: Usages:
- name: fuel_computer
java: FuelComputer.java
folder: controllers/algo/fuel
prepend: integration/rusefi_config.txt
constexpr: "engine->fuelComputer"
- name: timing_state
java: TimingState.java
folder: controllers/algo
prepend: integration/rusefi_config.txt
constexpr: "engine->timingState"
- name: output_channels - name: output_channels
java: TsOutputs.java java: TsOutputs.java
folder: console/binary folder: console/binary
@ -33,12 +45,6 @@ Usages:
java: InjectorModel.java java: InjectorModel.java
folder: controllers/algo/fuel folder: controllers/algo/fuel
- name: fuel_computer
java: FuelComputer.java
folder: controllers/algo/fuel
prepend: integration/rusefi_config.txt
constexpr: "engine->fuelComputer"
- name: launch_control_state - name: launch_control_state
java: LaunchControl.java java: LaunchControl.java
folder: controllers/algo folder: controllers/algo

View File

@ -247,7 +247,7 @@ TEST(misc, testRpmCalculator) {
eth.firePrimaryTriggerRise(); eth.firePrimaryTriggerRise();
ASSERT_EQ(1500, Sensor::getOrZero(SensorType::Rpm)); ASSERT_EQ(1500, Sensor::getOrZero(SensorType::Rpm));
assertEqualsM("dwell", 4.5, engine->engineState.dwellAngle); assertEqualsM("dwell", 4.5, engine->timingState.dwellAngle);
assertEqualsM("fuel #2", 4.5450, engine->engineState.injectionDuration); assertEqualsM("fuel #2", 4.5450, engine->engineState.injectionDuration);
assertEqualsM("one degree", 111.1111, engine->rpmCalculator.oneDegreeUs); assertEqualsM("one degree", 111.1111, engine->rpmCalculator.oneDegreeUs);
ASSERT_EQ( 1, ilist->isReady) << "size #2"; ASSERT_EQ( 1, ilist->isReady) << "size #2";
@ -296,7 +296,7 @@ TEST(misc, testRpmCalculator) {
eth.fireRise(5); eth.fireRise(5);
ASSERT_EQ( 4, engine->executor.size()) << "queue size 4.3"; ASSERT_EQ( 4, engine->executor.size()) << "queue size 4.3";
assertEqualsM("dwell", 4.5, eth.engine.engineState.dwellAngle); assertEqualsM("dwell", 4.5, eth.engine.timingState.dwellAngle);
assertEqualsM("fuel #3", 4.5450, eth.engine.engineState.injectionDuration); assertEqualsM("fuel #3", 4.5450, eth.engine.engineState.injectionDuration);
ASSERT_EQ(1500, Sensor::getOrZero(SensorType::Rpm)); ASSERT_EQ(1500, Sensor::getOrZero(SensorType::Rpm));