From 8952633854ef23c3d43f95b5639181da0e157d2b Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 25 Sep 2024 00:16:53 -0700 Subject: [PATCH] int rpm -> float rpm --- firmware/console/status_loop.cpp | 6 +----- firmware/controllers/algo/antilag_system.cpp | 10 ++++------ firmware/controllers/algo/antilag_system.h | 8 ++++---- firmware/controllers/algo/engine.cpp | 2 +- .../engine_cycle/main_trigger_callback.cpp | 7 ++++--- .../controllers/engine_cycle/rpm_calculator.cpp | 2 +- .../controllers/engine_cycle/spark_logic.cpp | 16 +++++++--------- firmware/controllers/engine_cycle/spark_logic.h | 4 ++-- firmware/controllers/sensors/vr_pwm.cpp | 2 +- firmware/development/logic_analyzer.cpp | 2 +- .../test_ignition_scheduling.cpp | 4 ++-- 11 files changed, 28 insertions(+), 35 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index a80870a224..6e23a076ec 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -447,10 +447,6 @@ static void updateFuelInfo() { engine->outputChannels.veValue = engine->engineState.currentVe; } -static void updateIgnition(float rpm) { - engine->outputChannels.coilDutyCycle = getCoilDutyCycle(rpm); -} - static void updateFlags() { #if EFI_USB_SERIAL engine->outputChannels.isUsbConnected = is_usb_serial_ready(); @@ -508,7 +504,7 @@ void updateTunerStudioState() { updateSensors(); updateFuelInfo(); - updateIgnition(rpm); + engine->outputChannels.coilDutyCycle = getCoilDutyCycle(rpm); updateFlags(); // 104 diff --git a/firmware/controllers/algo/antilag_system.cpp b/firmware/controllers/algo/antilag_system.cpp index 21fdecf542..bd356d5b51 100644 --- a/firmware/controllers/algo/antilag_system.cpp +++ b/firmware/controllers/algo/antilag_system.cpp @@ -32,11 +32,11 @@ bool AntilagSystemBase::isInsideALSSwitchCondition() { } } -bool AntilagSystemBase::isALSMinRPMCondition(int rpm) const { +bool AntilagSystemBase::isALSMinRPMCondition(float rpm) const { return engineConfiguration->ALSMinRPM < rpm; } -bool AntilagSystemBase::isALSMaxRPMCondition(int rpm) const { +bool AntilagSystemBase::isALSMaxRPMCondition(float rpm) const { return engineConfiguration->ALSMaxRPM > rpm; } @@ -58,9 +58,7 @@ bool AntilagSystemBase::isALSMaxThrottleIntentCondition() const { return engineConfiguration->ALSMaxTPS > throttleIntent; } -bool AntilagSystemBase::isAntilagConditionMet(int rpm) { - - +bool AntilagSystemBase::isAntilagConditionMet(float rpm) { ALSMinRPMCondition = isALSMinRPMCondition(rpm); ALSMaxRPMCondition = isALSMaxRPMCondition(rpm); ALSMinCLTCondition = isALSMinCLTCondition(); @@ -77,7 +75,7 @@ bool AntilagSystemBase::isAntilagConditionMet(int rpm) { } void AntilagSystemBase::update() { - int rpm = Sensor::getOrZero(SensorType::Rpm); + float rpm = Sensor::getOrZero(SensorType::Rpm); isAntilagCondition = engineConfiguration->antiLagEnabled && isAntilagConditionMet(rpm); #if EFI_ANTILAG_SYSTEM diff --git a/firmware/controllers/algo/antilag_system.h b/firmware/controllers/algo/antilag_system.h index 179ec50174..30e2674413 100644 --- a/firmware/controllers/algo/antilag_system.h +++ b/firmware/controllers/algo/antilag_system.h @@ -16,12 +16,12 @@ class AntilagSystemBase : public antilag_system_state_s { public: void update(); - bool isALSMinRPMCondition(int rpm) const; - bool isALSMaxRPMCondition(int rpm) const; + bool isALSMinRPMCondition(float rpm) const; + bool isALSMaxRPMCondition(float rpm) const; bool isALSMinCLTCondition() const; bool isALSMaxCLTCondition() const; bool isALSMaxThrottleIntentCondition() const; bool isInsideALSSwitchCondition(); - /* enabled and all conditions above */ - bool isAntilagConditionMet(int rpm); + /* enabled and all conditions above */ + bool isAntilagConditionMet(float rpm); }; diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 3dc9d3b716..607df11222 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -168,7 +168,7 @@ void Engine::updateSlowSensors() { updateSwitchInputs(); #if EFI_SHAFT_POSITION_INPUT - int rpm = Sensor::getOrZero(SensorType::Rpm); + float rpm = Sensor::getOrZero(SensorType::Rpm); triggerCentral.isEngineSnifferEnabled = rpm < engineConfiguration->engineSnifferRpmThreshold; getEngineState()->sensorChartMode = rpm < engineConfiguration->sensorSnifferRpmThreshold ? engineConfiguration->sensorChartMode : SC_OFF; diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index 88250a5008..97824ba665 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -69,14 +69,15 @@ void mainTriggerCallback(uint32_t trgEventIndex, efitick_t edgeTimestamp, angle_ return; } - int rpm = engine->rpmCalculator.getCachedRpm(); + float rpm = engine->rpmCalculator.getCachedRpm(); if (rpm == 0) { // this happens while we just start cranking // todo: check for 'trigger->is_synchnonized?' return; } - if (rpm == NOISY_RPM || rpm > UNREALISTIC_RPM) { + + if (rpm == NOISY_RPM || !isValidRpm(rpm)) { warning(ObdCode::OBD_Crankshaft_Position_Sensor_A_Circuit_Malfunction, "noisy trigger"); return; } @@ -106,7 +107,7 @@ void mainTriggerCallback(uint32_t trgEventIndex, efitick_t edgeTimestamp, angle_ /** * For spark we schedule both start of coil charge and actual spark based on trigger angle */ - onTriggerEventSparkLogic(rpm, edgeTimestamp, currentPhase, nextPhase); + onTriggerEventSparkLogic(edgeTimestamp, currentPhase, nextPhase); } #endif /* EFI_ENGINE_CONTROL */ diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index 96414e4a9b..384c8a41f8 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -369,7 +369,7 @@ void tdcMarkCallback( // two instances of scheduling_s are needed to properly handle event overlap int revIndex2 = getRevolutionCounter() % 2; - int rpm = Sensor::getOrZero(SensorType::Rpm); + float rpm = Sensor::getOrZero(SensorType::Rpm); // todo: use tooth event-based scheduling, not just time-based scheduling if (isValidRpm(rpm)) { angle_t tdcPosition = tdcPosition(); diff --git a/firmware/controllers/engine_cycle/spark_logic.cpp b/firmware/controllers/engine_cycle/spark_logic.cpp index 0c6d15815c..845e617f2e 100644 --- a/firmware/controllers/engine_cycle/spark_logic.cpp +++ b/firmware/controllers/engine_cycle/spark_logic.cpp @@ -260,8 +260,7 @@ void turnSparkPinHigh(IgnitionEvent *event) { } } -static void scheduleSparkEvent(bool limitedSpark, IgnitionEvent *event, - int rpm, float dwellMs, float dwellAngle, float sparkAngle, efitick_t edgeTimestamp, float currentPhase, float nextPhase) { +static void scheduleSparkEvent(bool limitedSpark, IgnitionEvent *event, float dwellMs, float dwellAngle, float sparkAngle, efitick_t edgeTimestamp, float currentPhase, float nextPhase) { float angleOffset = dwellAngle - currentPhase; if (angleOffset < 0) { @@ -361,11 +360,10 @@ static void prepareIgnitionSchedule() { initializeIgnitionActions(); } -void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPhase, float nextPhase) { +void onTriggerEventSparkLogic(efitick_t edgeTimestamp, float currentPhase, float nextPhase) { ScopePerf perf(PE::OnTriggerEventSparkLogic); - if (!isValidRpm(rpm) || !engineConfiguration->isIgnitionEnabled) { - // this might happen for instance in case of a single trigger event after a pause + if (!engineConfiguration->isIgnitionEnabled) { return; } @@ -377,7 +375,7 @@ void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPha const floatms_t dwellMs = engine->ignitionState.sparkDwell; if (std::isnan(dwellMs) || dwellMs <= 0) { - warning(ObdCode::CUSTOM_DWELL, "invalid dwell to handle: %.2f at %d", dwellMs, rpm); + warning(ObdCode::CUSTOM_DWELL, "invalid dwell to handle: %.2f", dwellMs); return; } @@ -454,10 +452,10 @@ void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPha continue; } auto ALSSkipRatio = engineConfiguration->ALSSkipRatio; - engine->ALSsoftSparkLimiter.setTargetSkipRatio(ALSSkipRatio); + engine->ALSsoftSparkLimiter.setTargetSkipRatio(ALSSkipRatio); #endif // EFI_ANTILAG_SYSTEM - scheduleSparkEvent(limitedSpark, event, rpm, dwellMs, dwellAngle, sparkAngle, edgeTimestamp, currentPhase, nextPhase); + scheduleSparkEvent(limitedSpark, event, dwellMs, dwellAngle, sparkAngle, edgeTimestamp, currentPhase, nextPhase); } } } @@ -485,7 +483,7 @@ int getNumberOfSparks(ignition_mode_e mode) { /** * @see getInjectorDutyCycle */ -percent_t getCoilDutyCycle(int rpm) { +percent_t getCoilDutyCycle(float rpm) { floatms_t totalPerCycle = engine->ignitionState.sparkDwell * getNumberOfSparks(getCurrentIgnitionMode()); floatms_t engineCycleDuration = getCrankshaftRevolutionTimeMs(rpm) * (getEngineRotationState()->getOperationMode() == TWO_STROKE ? 1 : 2); return 100 * totalPerCycle / engineCycleDuration; diff --git a/firmware/controllers/engine_cycle/spark_logic.h b/firmware/controllers/engine_cycle/spark_logic.h index e8735d105c..08c387456a 100644 --- a/firmware/controllers/engine_cycle/spark_logic.h +++ b/firmware/controllers/engine_cycle/spark_logic.h @@ -7,9 +7,9 @@ #pragma once -void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPhase, float nextPhase); +void onTriggerEventSparkLogic(efitick_t edgeTimestamp, float currentPhase, float nextPhase); void turnSparkPinHigh(IgnitionEvent *event); void fireSparkAndPrepareNextSchedule(IgnitionEvent *event); int getNumberOfSparks(ignition_mode_e mode); -percent_t getCoilDutyCycle(int rpm); +percent_t getCoilDutyCycle(float rpm); void initializeIgnitionActions(); diff --git a/firmware/controllers/sensors/vr_pwm.cpp b/firmware/controllers/sensors/vr_pwm.cpp index b2610003c0..ffcdb46821 100644 --- a/firmware/controllers/sensors/vr_pwm.cpp +++ b/firmware/controllers/sensors/vr_pwm.cpp @@ -10,7 +10,7 @@ static SimplePwm pwms[VR_THRESHOLD_COUNT]; #define VR_SUPPLY_VOLTAGE 3.3f #endif -static void updateVrPwm(int rpm, size_t index) { +static void updateVrPwm(float rpm, size_t index) { auto& cfg = engineConfiguration->vrThreshold[index]; if (!isBrainPinValid(cfg.pin)) { diff --git a/firmware/development/logic_analyzer.cpp b/firmware/development/logic_analyzer.cpp index dc11dbe0a7..8d70a8f9af 100644 --- a/firmware/development/logic_analyzer.cpp +++ b/firmware/development/logic_analyzer.cpp @@ -212,7 +212,7 @@ static void reportWave(Logging *logging, int index) { logging->appendPrintf("%s", LOG_DELIMITER); efitimeus_t offsetUs = getWaveOffset(index); - int rpm = Sensor::getOrZero(SensorType::Rpm); + float rpm = Sensor::getOrZero(SensorType::Rpm); if (rpm != 0) { float oneDegreeUs = getOneDegreeTimeUs(rpm); diff --git a/unit_tests/tests/ignition_injection/test_ignition_scheduling.cpp b/unit_tests/tests/ignition_injection/test_ignition_scheduling.cpp index 3ee4f9eac8..28afc3d2d1 100644 --- a/unit_tests/tests/ignition_injection/test_ignition_scheduling.cpp +++ b/unit_tests/tests/ignition_injection/test_ignition_scheduling.cpp @@ -197,8 +197,8 @@ TEST(ignition, oddCylinderWastedSpark) { engineConfiguration->minimumIgnitionTiming = -25; // expect to schedule the on-phase dwell and spark (not the wasted spark copy) - onTriggerEventSparkLogic(1200, nowNt1, 10, 30); + onTriggerEventSparkLogic(nowNt1, 10, 30); // expect to schedule second events, the out-of-phase dwell and spark (the wasted spark copy) - onTriggerEventSparkLogic(1200, nowNt2, 360 + 10, 360 + 30); + onTriggerEventSparkLogic(nowNt2, 360 + 10, 360 + 30); }