rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
speed_density.cpp
Go to the documentation of this file.
1/**
2 * @file speed_density.cpp
3 *
4 * See http://rusefi.com/wiki/index.php?title=Manual:Software:Fuel_Control#Speed_Density for details
5 *
6 * @date May 29, 2014
7 * @author Andrey Belomutskiy, (c) 2012-2020
8 */
9
10#include "pch.h"
11
12#if defined(HAS_OS_ACCESS)
13#error "Unexpected OS ACCESS HERE"
14#endif
15
16#define rpmMin 500
17#define rpmMax 8000
18
20
21#define tpMin 0
22#define tpMax 100
23
24float IFuelComputer::getTChargeCoefficient(float rpm, float tps) {
25 // First, do TPS mode since it doesn't need any of the airflow math.
26 if (engineConfiguration->tChargeMode == TCHARGE_MODE_RPM_TPS) {
27 float minRpmKcurrentTPS = interpolateMsg("minRpm", tpMin,
30 float maxRpmKcurrentTPS = interpolateMsg("maxRpm", tpMin,
33
34 return interpolateMsg("Kcurr", rpmMin, minRpmKcurrentTPS, rpmMax, maxRpmKcurrentTPS, rpm);
35 }
36
37 constexpr floatms_t gramsPerMsToKgPerHour = (3600.0f * 1000.0f) / 1000.0f;
38 // We're actually using an 'old' airMass calculated for the previous cycle, but it's ok, we're not having any self-excitaton issues
40 // airMass is in grams per 1 cycle for 1 cyl. Convert it to airFlow in kg/h for the engine.
41 // And if the engine is stopped (0 rpm), then airFlow is also zero (avoiding NaN division)
42 floatms_t airFlow = (rpm == 0) ? 0 : airMassForEngine * gramsPerMsToKgPerHour / getEngineCycleDuration(rpm);
43
44 if (engineConfiguration->tChargeMode == TCHARGE_MODE_AIR_INTERP) {
45 // just interpolate between user-specified min and max coefs, based on the max airFlow value
46 return interpolateClamped(
49 airFlow
50 );
51 } else if (engineConfiguration->tChargeMode == TCHARGE_MODE_AIR_INTERP_TABLE) {
52 return interpolate2d(
53 airFlow,
56 );
57 } else {
58 criticalError("Unexpected tChargeMode: %d", engineConfiguration->tChargeMode);
59 return 0;
60 }
61}
62
63// http://rusefi.com/math/t_charge.html
64/***panel:Charge Temperature*/
66 const auto clt = Sensor::get(SensorType::Clt);
67 const auto iat = Sensor::get(SensorType::Iat);
68
69 float airTemp;
70
71 // Without either valid, return 0C. It's wrong, but it'll pretend to be nice and dense, so at least you won't go lean.
72 if (!iat && !clt) {
73 return 0;
74 } else if (!clt && iat) {
75 // Intake temperature will almost always be colder (richer) than CLT - use that
76 return iat.Value;
77 } else if (!iat && clt) {
78 // Without valid intake temperature, assume intake temp is 0C, and interpolate anyway
79 airTemp = 0;
80 } else {
81 // All is well - use real air temp
82 airTemp = iat.Value;
83 }
84
85 float coolantTemp = clt.Value;
86
88
89 if (std::isnan(sdTcharge_coff)) {
90 warning(ObdCode::CUSTOM_ERR_T2_CHARGE, "t2-getTCharge NaN");
91 return coolantTemp;
92 }
93
94 // Interpolate between CLT and IAT:
95 // 0.0 coefficient -> use CLT (full heat transfer)
96 // 1.0 coefficient -> use IAT (no heat transfer)
97 float Tcharge = interpolateClamped(0.0f, coolantTemp, 1.0f, airTemp, sdTcharge_coff);
98
99 if (std::isnan(Tcharge)) {
100 // we can probably end up here while resetting engine state - interpolation would fail
102 return coolantTemp;
103 }
104
105 return Tcharge;
106}
107
void initTable(TValueInit(&table)[TRowNum][TColNum], const TXColumnInit(&columnBins)[TColNum], const TRowInit(&rowBins)[TRowNum])
virtual SensorResult get() const =0
float interpolateMsg(const char *msg, float x1, float y1, float x2, float y2, float x)
Linear interpolation by two points.
float interpolateClamped(float x1, float y1, float x2, float y2, float x)
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
floatms_t getEngineCycleDuration(float rpm)
bool warning(ObdCode code, const char *fmt,...)
static CCM_OPTIONAL FunctionalSensor iat(SensorType::Iat, MS2NT(10))
static CCM_OPTIONAL FunctionalSensor clt(SensorType::Clt, MS2NT(10))
@ CUSTOM_ERR_TCHARGE_NOT_READY
@ CUSTOM_ERR_T2_CHARGE
ve_Map3D_t veMap
void initSpeedDensity()
temperature_t getTCharge(float rpm, float tps)
float getTChargeCoefficient(float rpm, float tps)
scaled_channel< uint16_t, 10, 1 > veTable[VE_LOAD_COUNT][VE_RPM_COUNT]