rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
trip_odometer.cpp
Go to the documentation of this file.
1#include "pch.h"
2
14
15void TripOdometer::consumeFuel(float grams, efitick_t nowNt) {
16// we have some drama with simulator busy loop in reality :(
17#if EFI_PROD_CODE || EFI_UNIT_TEST
18 m_consumedRemainder += grams;
19
20 // 1000grams of fuel between invocations of TripOdometer logic means something very wrong, we do not control cruise ship engines yet!
21 if (m_consumedRemainder > 1000) {
22 firmwareError(ObdCode::OBD_PCM_Processor_Fault, "m_consumedRemainder busy loop %f %f", m_consumedRemainder, grams);
23 return;
24 }
25 // A racecar with a very large fuel tank might consume 60kg of fuel on a single run of the ECU
26 // we use integers to gain dynamic range of about 10^9 which is more than float would give us
27 // optimized for lots of small pulses
28 while (m_consumedRemainder >= 1) {
31 }
32
33 float elapsedSecond = m_timer.getElapsedSecondsAndReset(nowNt);
34
35 // If it's been a long time since last injection, ignore this pulse
36 if (elapsedSecond > 0.2f) {
37 m_rate = 0;
38 } else {
39 m_rate = grams / elapsedSecond;
40 }
41#endif // EFI_PROD_CODE || EFI_UNIT_TEST
42}
43
45 return m_consumedGrams;
46}
47
51
53 float meterPerSecond = Sensor::getOrZero(SensorType::VehicleSpeed) / 3.6f;
54 float metersThisTick = meterPerSecond * (SLOW_CALLBACK_PERIOD_MS / 1000.0f);
55
56 m_distanceRemainder += metersThisTick;
57 while (m_distanceRemainder > 1.0f) {
60 }
61
62 constexpr float slowCallbackPerSecond = 1000 / SLOW_CALLBACK_PERIOD_MS;
64 if (m_slowCallbackCounter == slowCallbackPerSecond) {
66
68
69#if EFI_SHAFT_POSITION_INPUT
72 }
73#endif // EFI_SHAFT_POSITION_INPUT
74 }
75}
76
78 return m_distanceMeters;
79}
80
83}
84
RpmCalculator rpmCalculator
Definition engine.h:306
bool isRunning() const
static float getOrZero(SensorType type)
Definition sensor.h:83
uint32_t getEngineRunTime() const
uint32_t getDistanceMeters() const
uint32_t m_slowCallbackCounter
uint32_t getIgnitionOnTime() const
float m_distanceRemainder
float m_consumedRemainder
void onSlowCallback() override
uint32_t m_consumedGrams
float getConsumptionGramPerSecond() const
void consumeFuel(float grams, efitick_t nowNt)
uint32_t m_ignitionOnSeconds
uint32_t getConsumedGrams() const
uint32_t m_engineRunningSeconds
uint32_t m_distanceMeters
static EngineAccessor engine
Definition engine.h:413
void firmwareError(ObdCode code, const char *fmt,...)
@ OBD_PCM_Processor_Fault