log per-cylinder map sampling

This commit is contained in:
Matthew Kennedy 2024-08-05 22:08:48 -07:00
parent 87147174ca
commit 36c45a0e57
4 changed files with 16 additions and 9 deletions

View File

@ -370,5 +370,7 @@ float mapFast
uint16_t mapAveragingSamples uint16_t mapAveragingSamples
uint8_t[114 iterate] unusedAtTheEnd;;"",1, 0, 0, 0, 0 uint8_t[12 iterate] mapPerCylinder;;"kPa", 1, 0, 0, 0, 0
uint8_t[106 iterate] unusedAtTheEnd;;"",1, 0, 0, 0, 0
end_struct end_struct

View File

@ -54,6 +54,7 @@ static int averagedMapBufIdx = 0;
struct sampler { struct sampler {
scheduling_s startTimer; scheduling_s startTimer;
scheduling_s endTimer; scheduling_s endTimer;
uint8_t cylinderIndex;
}; };
static CCM_OPTIONAL sampler samplers[MAX_CYLINDER_COUNT][2]; static CCM_OPTIONAL sampler samplers[MAX_CYLINDER_COUNT][2];
@ -73,7 +74,7 @@ static void startAveraging(sampler* s) {
// TODO: set currentMapAverager based on cylinder bank // TODO: set currentMapAverager based on cylinder bank
auto& averager = getMapAvg(currentMapAverager); auto& averager = getMapAvg(currentMapAverager);
averager.start(); averager.start(s->cylinderIndex);
mapAveragingPin.setHigh(); mapAveragingPin.setHigh();
@ -81,12 +82,13 @@ static void startAveraging(sampler* s) {
{ endAveraging, &averager }); { endAveraging, &averager });
} }
void MapAverager::start() { void MapAverager::start(uint8_t cylinderIndex) {
chibios_rt::CriticalSectionLocker csl; chibios_rt::CriticalSectionLocker csl;
m_counter = 0; m_counter = 0;
m_sum = 0; m_sum = 0;
m_isAveraging = true; m_isAveraging = true;
m_cylinderIndex = cylinderIndex;
} }
SensorResult MapAverager::submit(float volts) { SensorResult MapAverager::submit(float volts) {
@ -124,6 +126,9 @@ void MapAverager::stop() {
minPressure = averagedMapRunningBuffer[i]; minPressure = averagedMapRunningBuffer[i];
} }
if (m_cylinderIndex < efi::size(engine->outputChannels.mapPerCylinder)) {
engine->outputChannels.mapPerCylinder[m_cylinderIndex] = minPressure;
}
setValidValue(minPressure, getTimeNowNt()); setValidValue(minPressure, getTimeNowNt());
} else { } else {
#if EFI_PROD_CODE #if EFI_PROD_CODE
@ -181,6 +186,7 @@ void refreshMapAveragingPreCalc() {
angle_t start = interpolate2d(rpm, c->samplingAngleBins, c->samplingAngle); angle_t start = interpolate2d(rpm, c->samplingAngleBins, c->samplingAngle);
angle_t duration = interpolate2d(rpm, c->samplingWindowBins, c->samplingWindow); angle_t duration = interpolate2d(rpm, c->samplingWindowBins, c->samplingWindow);
efiAssertVoid(ObdCode::CUSTOM_ERR_MAP_START_ASSERT, !std::isnan(start), "start"); efiAssertVoid(ObdCode::CUSTOM_ERR_MAP_START_ASSERT, !std::isnan(start), "start");
assertAngleRange(duration, "samplingDuration", ObdCode::CUSTOM_ERR_6563);
angle_t offsetAngle = engine->triggerCentral.triggerFormDetails.eventAngles[engineConfiguration->mapAveragingSchedulingAtIndex]; angle_t offsetAngle = engine->triggerCentral.triggerFormDetails.eventAngles[engineConfiguration->mapAveragingSchedulingAtIndex];
efiAssertVoid(ObdCode::CUSTOM_ERR_MAP_AVG_OFFSET, !std::isnan(offsetAngle), "offsetAngle"); efiAssertVoid(ObdCode::CUSTOM_ERR_MAP_AVG_OFFSET, !std::isnan(offsetAngle), "offsetAngle");
@ -228,15 +234,12 @@ void mapAveragingTriggerCallback(
applyMapMinBufferLength(); applyMapMinBufferLength();
} }
// todo: this could be pre-calculated
int samplingCount = engineConfiguration->measureMapOnlyInOneCylinder ? 1 : engineConfiguration->cylindersCount; int samplingCount = engineConfiguration->measureMapOnlyInOneCylinder ? 1 : engineConfiguration->cylindersCount;
for (int i = 0; i < samplingCount; i++) { for (int i = 0; i < samplingCount; i++) {
angle_t samplingStart = engine->engineState.mapAveragingStart[i]; angle_t samplingStart = engine->engineState.mapAveragingStart[i];
angle_t samplingDuration = engine->engineState.mapAveragingDuration; angle_t samplingDuration = engine->engineState.mapAveragingDuration;
// todo: this assertion could be moved out of trigger handler
assertAngleRange(samplingDuration, "samplingDuration", ObdCode::CUSTOM_ERR_6563);
if (samplingDuration <= 0) { if (samplingDuration <= 0) {
warning(ObdCode::CUSTOM_MAP_ANGLE_PARAM, "map sampling angle should be positive"); warning(ObdCode::CUSTOM_MAP_ANGLE_PARAM, "map sampling angle should be positive");
return; return;
@ -256,6 +259,7 @@ void mapAveragingTriggerCallback(
int structIndex = getRevolutionCounter() % 2; int structIndex = getRevolutionCounter() % 2;
sampler* s = &samplers[i][structIndex]; sampler* s = &samplers[i][structIndex];
s->cylinderIndex = i;
// at the moment we schedule based on time prediction based on current RPM and angle // at the moment we schedule based on time prediction based on current RPM and angle
// we are loosing precision in case of changing RPM - the further away is the event the worse is precision // we are loosing precision in case of changing RPM - the further away is the event the worse is precision

View File

@ -37,7 +37,7 @@ public:
{ {
} }
void start(); void start(uint8_t cylinderIndex);
void stop(); void stop();
SensorResult submit(float sensorVolts); SensorResult submit(float sensorVolts);
@ -55,6 +55,7 @@ private:
size_t m_counter = 0; size_t m_counter = 0;
size_t m_lastCounter = 0; size_t m_lastCounter = 0;
float m_sum = 0; float m_sum = 0;
uint8_t m_cylinderIndex = 0;
}; };
MapAverager& getMapAvg(size_t idx); MapAverager& getMapAvg(size_t idx);

View File

@ -3159,7 +3159,7 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@@@ts_command_e_TS_
field = "High value threshold", mapErrorDetectionTooHigh field = "High value threshold", mapErrorDetectionTooHigh
field = "" field = ""
field = "Measure Map Only In One Cylinder", measureMapOnlyInOneCylinder field = "Measure Map Only In One Cylinder", measureMapOnlyInOneCylinder
field = "Cylinder count to sample MAP", mapMinBufferLength field = "Cylinder count to sample MAP", mapMinBufferLength
dialog = mapSettings, "", yAxis dialog = mapSettings, "", yAxis
panel = mapCommon panel = mapCommon