Skip to content

Commit

Permalink
int rpm -> float rpm
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Sep 25, 2024
1 parent 20508c1 commit a329b3a
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion firmware/controllers/algo/advance_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ size_t getMultiSparkCount(int rpm);

class IgnitionState : public ignition_state_s {
public:
floatms_t getSparkDwell(int rpm);
floatms_t getSparkDwell(float rpm);
};
2 changes: 1 addition & 1 deletion firmware/controllers/algo/airmass/airmass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static float getVeLoadAxis(ve_override_e mode, float passedLoad) {
}
}

float AirmassVeModelBase::getVe(int rpm, float load, bool postState) const {
float AirmassVeModelBase::getVe(float rpm, float load, bool postState) const {
efiAssert(ObdCode::OBD_PCM_Processor_Fault, m_veTable != nullptr, "VE table null", 0);

// Override the load value if necessary
Expand Down
4 changes: 2 additions & 2 deletions firmware/controllers/algo/airmass/airmass.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ struct AirmassResult {
};

struct AirmassModelBase {
virtual AirmassResult getAirmass(int rpm, bool postState) = 0;
virtual AirmassResult getAirmass(float rpm, bool postState) = 0;
};

class AirmassVeModelBase : public AirmassModelBase {
public:
explicit AirmassVeModelBase(const ValueProvider3D& veTable);

// Retrieve the user-calibrated volumetric efficiency from the table
float getVe(int rpm, percent_t load, bool postState) const;
float getVe(float rpm, percent_t load, bool postState) const;

private:
const ValueProvider3D* const m_veTable;
Expand Down
2 changes: 1 addition & 1 deletion firmware/controllers/algo/airmass/alphan_airmass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "alphan_airmass.h"

AirmassResult AlphaNAirmass::getAirmass(int rpm, bool postState) {
AirmassResult AlphaNAirmass::getAirmass(float rpm, bool postState) {
auto tps = Sensor::get(SensorType::Tps1);

if (!tps.Valid) {
Expand Down
2 changes: 1 addition & 1 deletion firmware/controllers/algo/airmass/alphan_airmass.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class AlphaNAirmass : public SpeedDensityBase {
public:
explicit AlphaNAirmass(const ValueProvider3D& veTable) : SpeedDensityBase(veTable) {}

AirmassResult getAirmass(int rpm, bool postState) override;
AirmassResult getAirmass(float rpm, bool postState) override;
};
2 changes: 1 addition & 1 deletion firmware/controllers/algo/airmass/lua_airmass.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class LuaAirmass final : public AirmassModelBase {
public:
AirmassResult getAirmass(int /*rpm*/, bool /*postState*/) override {
AirmassResult getAirmass(float /*rpm*/, bool /*postState*/) override {
return m_airmass;
}

Expand Down
4 changes: 2 additions & 2 deletions firmware/controllers/algo/airmass/maf_airmass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ float MafAirmass::getMaf() const {
}
}

AirmassResult MafAirmass::getAirmass(int rpm, bool postState) {
AirmassResult MafAirmass::getAirmass(float rpm, bool postState) {
float maf = getMaf();

return getAirmassImpl(maf, rpm, postState);
Expand All @@ -41,7 +41,7 @@ AirmassResult MafAirmass::getAirmass(int rpm, bool postState) {
* Function block now works to create a standardised load from the cylinder filling as well as tune fuel via VE table.
* @return total duration of fuel injection per engine cycle, in milliseconds
*/
AirmassResult MafAirmass::getAirmassImpl(float massAirFlow, int rpm, bool postState) const {
AirmassResult MafAirmass::getAirmassImpl(float massAirFlow, float rpm, bool postState) const {
// If the engine is stopped, MAF is meaningless
if (rpm == 0) {
return {};
Expand Down
4 changes: 2 additions & 2 deletions firmware/controllers/algo/airmass/maf_airmass.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class MafAirmass final : public AirmassVeModelBase {
public:
explicit MafAirmass(const ValueProvider3D& veTable) : AirmassVeModelBase(veTable) {}

AirmassResult getAirmass(int rpm, bool postState) override;
AirmassResult getAirmass(float rpm, bool postState) override;

// Compute airmass based on flow & engine speed
AirmassResult getAirmassImpl(float massAirFlow, int rpm, bool postState) const;
AirmassResult getAirmassImpl(float massAirFlow, float rpm, bool postState) const;

private:
float getMaf() const;
Expand Down
4 changes: 2 additions & 2 deletions firmware/controllers/algo/airmass/speed_density_airmass.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "pch.h"
#include "speed_density_airmass.h"

AirmassResult SpeedDensityAirmass::getAirmass(int rpm, bool postState) {
AirmassResult SpeedDensityAirmass::getAirmass(float rpm, bool postState) {
ScopePerf perf(PE::GetSpeedDensityFuel);

auto map = getMap(rpm, postState);
Expand Down Expand Up @@ -47,7 +47,7 @@ float SpeedDensityAirmass::getAirflow(float rpm, float map, bool postState) {
return massPerCycle * rpm / 60;
}

float SpeedDensityAirmass::getMap(int rpm, bool postState) const {
float SpeedDensityAirmass::getMap(float rpm, bool postState) const {
float fallbackMap = m_mapEstimationTable->getValue(rpm, Sensor::getOrZero(SensorType::Tps1));

#if EFI_TUNER_STUDIO
Expand Down
4 changes: 2 additions & 2 deletions firmware/controllers/algo/airmass/speed_density_airmass.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class SpeedDensityAirmass : public SpeedDensityBase {
, m_mapEstimationTable(&mapEstimationTable)
{}

AirmassResult getAirmass(int rpm, bool postState) override;
AirmassResult getAirmass(float rpm, bool postState) override;
AirmassResult getAirmass(float rpm, float map, bool postState);
float getAirflow(float rpm, float map, bool postState);

float getMap(int rpm, bool postState) const;
float getMap(float rpm, bool postState) const;

private:
const ValueProvider3D* const m_mapEstimationTable;
Expand Down
2 changes: 1 addition & 1 deletion firmware/controllers/algo/engine2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void EngineState::periodicFastCallback() {

engine->fuelComputer.running.timeSinceCrankingInSecs = crankingTimer.getElapsedSeconds(nowNt);

int rpm = Sensor::getOrZero(SensorType::Rpm);
float rpm = Sensor::getOrZero(SensorType::Rpm);
engine->ignitionState.sparkDwell = engine->ignitionState.getSparkDwell(rpm);
engine->ignitionState.dwellAngle = std::isnan(rpm) ? NAN : engine->ignitionState.sparkDwell / getOneDegreeTimeMs(rpm);

Expand Down
4 changes: 2 additions & 2 deletions firmware/controllers/algo/fuel_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ float getMaxAirflowAtMap(float map) {
}

// Per-cylinder base fuel mass
static float getBaseFuelMass(int rpm) {
static float getBaseFuelMass(float rpm) {
ScopePerf perf(PE::GetBaseFuel);

// airmass modes - get airmass first, then convert to fuel
Expand Down Expand Up @@ -298,7 +298,7 @@ static float getCycleFuelMass(bool isCranking, float baseFuelMass) {
* @returns Mass of each individual fuel injection, in grams
* in case of single point injection mode the amount of fuel into all cylinders, otherwise the amount for one cylinder
*/
float getInjectionMass(int rpm) {
float getInjectionMass(float rpm) {
ScopePerf perf(PE::GetInjectionDuration);

#if EFI_SHAFT_POSITION_INPUT
Expand Down
2 changes: 1 addition & 1 deletion firmware/controllers/algo/fuel_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ float getCltFuelCorrection();
angle_t getCltTimingCorrection();
float getCrankingFuel(float baseFuel);
float getCrankingFuel3(float baseFuel, uint32_t revolutionCounterSinceStart);
float getInjectionMass(int rpm);
float getInjectionMass(float rpm);
percent_t getInjectorDutyCycle(int rpm);
percent_t getInjectorDutyCycleStage2(int rpm);
float getStage2InjectionFraction(int rpm, float fuelLoad);
Expand Down
4 changes: 2 additions & 2 deletions firmware/controllers/math/engine_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void setSingleCoilDwell() {
/**
* @return Spark dwell time, in milliseconds. 0 if tables are not ready.
*/
floatms_t IgnitionState::getSparkDwell(int rpm) {
floatms_t IgnitionState::getSparkDwell(float rpm) {
#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
float dwellMs;
if (engine->rpmCalculator.isCranking()) {
Expand All @@ -95,7 +95,7 @@ floatms_t IgnitionState::getSparkDwell(int rpm) {

if (std::isnan(dwellMs) || dwellMs <= 0) {
// this could happen during engine configuration reset
warning(ObdCode::CUSTOM_ERR_DWELL_DURATION, "invalid dwell: %.2f at rpm=%d", dwellMs, rpm);
warning(ObdCode::CUSTOM_ERR_DWELL_DURATION, "invalid dwell: %.2f at rpm=%.0f", dwellMs, rpm);
return 0;
}
return dwellMs;
Expand Down
2 changes: 0 additions & 2 deletions firmware/controllers/math/engine_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ floatms_t getEngineCycleDuration(int rpm);
float getFuelingLoad();
float getIgnitionLoad();

floatms_t getSparkDwell(int rpm);

ignition_mode_e getCurrentIgnitionMode();

size_t getCylinderId(size_t index);
Expand Down
2 changes: 1 addition & 1 deletion unit_tests/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class MockAirmass : public AirmassVeModelBase {

MockVp3d veTable;

MOCK_METHOD(AirmassResult, getAirmass, (int rpm, bool postState), (override));
MOCK_METHOD(AirmassResult, getAirmass, (float rpm, bool postState), (override));
};

class MockInjectorModel2 : public IInjectorModel {
Expand Down
2 changes: 1 addition & 1 deletion unit_tests/tests/ignition_injection/test_fuel_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ TEST(AirmassModes, VeOverride) {
struct DummyAirmassModel : public AirmassVeModelBase {
DummyAirmassModel(const ValueProvider3D& veTable) : AirmassVeModelBase(veTable) {}

AirmassResult getAirmass(int rpm, bool postState) override {
AirmassResult getAirmass(float rpm, bool postState) override {
// Default load value 10, will be overriden
getVe(rpm, 10.0f, postState);

Expand Down

0 comments on commit a329b3a

Please sign in to comment.