From 9f8ccececd8fc60cee2d3da0e988b6778ad0b0a0 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sun, 26 Dec 2021 12:33:32 -0500 Subject: [PATCH] docs & refactoring --- firmware/controllers/actuators/electronic_throttle.cpp | 2 +- firmware/controllers/algo/airmass/airmass.cpp | 6 +++--- firmware/controllers/algo/airmass/maf_airmass.cpp | 6 +++--- firmware/controllers/algo/airmass/speed_density_base.cpp | 2 +- firmware/controllers/algo/airmass/speed_density_base.h | 5 ++++- firmware/controllers/algo/fuel/fuel_computer.h | 2 +- firmware/controllers/algo/rusefi_enums.h | 6 ------ firmware/controllers/algo/rusefi_types.h | 3 +++ 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index 715b537521..f3d56f2b17 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -307,7 +307,7 @@ expected EtbController::getSetpointEtb() const { engineConfiguration->useETBforIdleControl ? m_idlePosition : 0, 100 ); - percent_t etbIdleAddition = 0.01f * engineConfiguration->etbIdleThrottleRange * etbIdlePosition; + percent_t etbIdleAddition = PERCENT_DIV * engineConfiguration->etbIdleThrottleRange * etbIdlePosition; // Interpolate so that the idle adder just "compresses" the throttle's range upward. // [0, 100] -> [idle, 100] diff --git a/firmware/controllers/algo/airmass/airmass.cpp b/firmware/controllers/algo/airmass/airmass.cpp index 6706233faa..01fbf250ea 100644 --- a/firmware/controllers/algo/airmass/airmass.cpp +++ b/firmware/controllers/algo/airmass/airmass.cpp @@ -20,18 +20,18 @@ float AirmassVeModelBase::getVe(int rpm, float load) const { // Override the load value if necessary load = getVeLoadAxis(load); - float ve = m_veTable->getValue(rpm, load); + percent_t ve = m_veTable->getValue(rpm, load); auto tps = Sensor::get(SensorType::Tps1); // get VE from the separate table for Idle if idling if (engine->module().unmock().isIdlingOrTaper() && tps && engineConfiguration->useSeparateVeForIdle) { - float idleVe = interpolate2d(rpm, config->idleVeBins, config->idleVe); + percent_t idleVe = interpolate2d(rpm, config->idleVeBins, config->idleVe); // interpolate between idle table and normal (running) table using TPS threshold ve = interpolateClamped(0.0f, idleVe, engineConfiguration->idlePidDeactivationTpsThreshold, ve, tps.Value); } engine->engineState.currentVe = ve; engine->engineState.currentVeLoad = load; - return ve * 0.01f; + return ve * PERCENT_DIV; } diff --git a/firmware/controllers/algo/airmass/maf_airmass.cpp b/firmware/controllers/algo/airmass/maf_airmass.cpp index 85961e50c5..53051a5649 100644 --- a/firmware/controllers/algo/airmass/maf_airmass.cpp +++ b/firmware/controllers/algo/airmass/maf_airmass.cpp @@ -24,13 +24,13 @@ AirmassResult MafAirmass::getAirmassImpl(float massAirFlow, int rpm) const { float revsPerSecond = rpm / 60.0f; float airPerRevolution = gramPerSecond / revsPerSecond; - // Now we have to divide among cylinders - on a 4 stroke, half of the cylinders happen every rev - // This math is floating point to work properly on engines with odd cyl count + // Now we have to divide among cylinders - on a 4 stroke, half of the cylinders happen every revolution + // This math is floating point to work properly on engines with odd cylinder count float halfCylCount = engineConfiguration->specs.cylindersCount / 2.0f; float cylinderAirmass = airPerRevolution / halfCylCount; - //Create % load for fuel table using relative naturally aspiratedcylinder filling + //Create % load for fuel table using relative naturally aspirated cylinder filling float airChargeLoad = 100 * cylinderAirmass / engine->standardAirCharge; //Correct air mass by VE table diff --git a/firmware/controllers/algo/airmass/speed_density_base.cpp b/firmware/controllers/algo/airmass/speed_density_base.cpp index beb2997fb0..0794cf4d33 100644 --- a/firmware/controllers/algo/airmass/speed_density_base.cpp +++ b/firmware/controllers/algo/airmass/speed_density_base.cpp @@ -19,7 +19,7 @@ */ #define AIR_R 0.28705f -float idealGasLaw(float volume, float pressure, float temperature) { +mass_t idealGasLaw(float volume, float pressure, float temperature) { return volume * pressure / (AIR_R * temperature); } diff --git a/firmware/controllers/algo/airmass/speed_density_base.h b/firmware/controllers/algo/airmass/speed_density_base.h index 2a5322ee6a..235d258b9c 100644 --- a/firmware/controllers/algo/airmass/speed_density_base.h +++ b/firmware/controllers/algo/airmass/speed_density_base.h @@ -11,7 +11,10 @@ #include "airmass.h" -float idealGasLaw(float volume, float pressure, float temperature); +/** + * @returns mass of air in cylinder + */ +mass_t idealGasLaw(float volume, float pressure, float temperature); class SpeedDensityBase : public AirmassVeModelBase { protected: diff --git a/firmware/controllers/algo/fuel/fuel_computer.h b/firmware/controllers/algo/fuel/fuel_computer.h index 8ca70fe18f..92dd57f37a 100644 --- a/firmware/controllers/algo/fuel/fuel_computer.h +++ b/firmware/controllers/algo/fuel/fuel_computer.h @@ -2,7 +2,7 @@ class ValueProvider3D; -using mass_t = float; +#include "rusefi_types.h" struct IFuelComputer { virtual mass_t getCycleFuel(mass_t airmass, int rpm, float load) const = 0; diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index 82037d6a08..d717f8a16a 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -18,12 +18,6 @@ // https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename #include -// I believe that TunerStudio curve editor has a bug with F32 support -// because of that bug we cannot have '1.05' for 5% extra multiplier -/** - * *0.01 because of https://sourceforge.net/p/rusefi/tickets/153/ - */ - #define PERCENT_MULT 100.0f #define PERCENT_DIV 0.01f diff --git a/firmware/controllers/algo/rusefi_types.h b/firmware/controllers/algo/rusefi_types.h index d253d388b8..0ddc459e79 100644 --- a/firmware/controllers/algo/rusefi_types.h +++ b/firmware/controllers/algo/rusefi_types.h @@ -77,6 +77,9 @@ typedef efitime_t efitick_t; typedef float angle_t; +// mass in grams +typedef float mass_t; + // temperature, in Celsius typedef float temperature_t; typedef float floatms_t;