trip odometer
This commit is contained in:
parent
219926356e
commit
c8ddbba529
|
@ -544,8 +544,10 @@ static void updateFuelCorrections() {
|
|||
}
|
||||
|
||||
static void updateFuelResults() {
|
||||
engine->outputChannels.fuelFlowRate = engine->engineState.fuelConsumption.getConsumptionGramPerSecond();
|
||||
engine->outputChannels.totalFuelConsumption = engine->engineState.fuelConsumption.getConsumedGrams();
|
||||
#if EFI_VEHICLE_SPEED
|
||||
engine->outputChannels.fuelFlowRate = engine->module<TripOdometer>()->getConsumptionGramPerSecond();
|
||||
engine->outputChannels.totalFuelConsumption = engine->module<TripOdometer>()->getConsumedGrams();
|
||||
#endif // EFI_VEHICLE_SPEED
|
||||
}
|
||||
|
||||
static void updateFuelInfo() {
|
||||
|
|
|
@ -25,7 +25,7 @@ CONTROLLERS_ALGO_SRC_CPP = $(PROJECT_DIR)/controllers/algo/advance_map.cpp \
|
|||
$(PROJECT_DIR)/controllers/algo/fuel/injector_model.cpp \
|
||||
$(PROJECT_DIR)/controllers/algo/fuel/dfco.cpp \
|
||||
$(PROJECT_DIR)/controllers/algo/nmea.cpp \
|
||||
$(PROJECT_DIR)/controllers/algo/odometer.cpp \
|
||||
$(PROJECT_DIR)/controllers/algo/trip_odometer.cpp \
|
||||
$(PROJECT_DIR)/controllers/algo/defaults/default_base_engine.cpp \
|
||||
$(PROJECT_DIR)/controllers/algo/defaults/default_cranking.cpp \
|
||||
$(PROJECT_DIR)/controllers/algo/defaults/default_fuel.cpp \
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#include "lambda_monitor.h"
|
||||
#include "efi_output.h"
|
||||
#include "vvt.h"
|
||||
#include "trip_odometer.h"
|
||||
|
||||
#ifndef EFI_UNIT_TEST
|
||||
#error EFI_UNIT_TEST must be defined!
|
||||
|
@ -154,6 +155,7 @@ public:
|
|||
Mockable<WallFuelController>,
|
||||
#if EFI_VEHICLE_SPEED
|
||||
GearDetector,
|
||||
TripOdometer,
|
||||
#endif // EFI_VEHICLE_SPEED
|
||||
KnockController,
|
||||
SensorChecker,
|
||||
|
|
|
@ -81,27 +81,6 @@ bool WarningCodeState::isWarningNow(ObdCode code) const {
|
|||
return !warn->LastTriggered.hasElapsedSec(maxI(3, engineConfiguration->warningPeriod));
|
||||
}
|
||||
|
||||
void FuelConsumptionState::consumeFuel(float grams, efitick_t nowNt) {
|
||||
m_consumedGrams += grams;
|
||||
|
||||
float elapsedSecond = m_timer.getElapsedSecondsAndReset(nowNt);
|
||||
|
||||
// If it's been a long time since last injection, ignore this pulse
|
||||
if (elapsedSecond > 0.2f) {
|
||||
m_rate = 0;
|
||||
} else {
|
||||
m_rate = grams / elapsedSecond;
|
||||
}
|
||||
}
|
||||
|
||||
float FuelConsumptionState::getConsumedGrams() const {
|
||||
return m_consumedGrams;
|
||||
}
|
||||
|
||||
float FuelConsumptionState::getConsumptionGramPerSecond() const {
|
||||
return m_rate;
|
||||
}
|
||||
|
||||
EngineState::EngineState() {
|
||||
timeSinceLastTChargeK = getTimeNowNt();
|
||||
}
|
||||
|
|
|
@ -24,20 +24,6 @@ struct SensorsState {
|
|||
Accelerometer accelerometer;
|
||||
};
|
||||
|
||||
class FuelConsumptionState {
|
||||
public:
|
||||
void consumeFuel(float grams, efitick_t nowNt);
|
||||
|
||||
float getConsumedGrams() const;
|
||||
float getConsumptionGramPerSecond() const;
|
||||
|
||||
private:
|
||||
float m_consumedGrams = 0;
|
||||
float m_rate = 0;
|
||||
|
||||
Timer m_timer;
|
||||
};
|
||||
|
||||
class TransmissionState {
|
||||
public:
|
||||
gear_e gearSelectorPosition;
|
||||
|
|
|
@ -32,8 +32,6 @@ public:
|
|||
// Per-injection fuel mass, including TPS accel enrich
|
||||
float injectionMass[MAX_CYLINDER_COUNT] = {0};
|
||||
|
||||
FuelConsumptionState fuelConsumption;
|
||||
|
||||
Timer crankingTimer;
|
||||
|
||||
WarningCodeState warnings;
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
#include "pch.h"
|
||||
|
||||
#include "odometer.h"
|
||||
|
||||
|
||||
//static odometer_state odometerCopies[2];
|
||||
|
||||
void setCrc(odometer_state *state) {
|
||||
state->crc = crc32(state, 4);
|
||||
}
|
||||
|
||||
void validate(odometer_state *state) {
|
||||
int crc = crc32(state, 4);
|
||||
if (state->crc != crc)
|
||||
state->totalMeters = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void initOdometer() {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
#include "pch.h"
|
||||
|
||||
void TripOdometer::reset() {
|
||||
m_consumedGrams = 0;
|
||||
m_consumedRemainder = 0;
|
||||
|
||||
m_distanceMeters = 0;
|
||||
m_distanceRemainder = 0;
|
||||
}
|
||||
|
||||
void TripOdometer::consumeFuel(float grams, efitick_t nowNt) {
|
||||
m_consumedRemainder += grams;
|
||||
|
||||
while (m_consumedRemainder > 1) {
|
||||
m_consumedRemainder--;
|
||||
m_consumedGrams++;
|
||||
}
|
||||
|
||||
m_consumedGrams += grams;
|
||||
|
||||
float elapsedSecond = m_timer.getElapsedSecondsAndReset(nowNt);
|
||||
|
||||
// If it's been a long time since last injection, ignore this pulse
|
||||
if (elapsedSecond > 0.2f) {
|
||||
m_rate = 0;
|
||||
} else {
|
||||
m_rate = grams / elapsedSecond;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t TripOdometer::getConsumedGrams() const {
|
||||
return m_consumedGrams;
|
||||
}
|
||||
|
||||
float TripOdometer::getConsumptionGramPerSecond() const {
|
||||
return m_rate;
|
||||
}
|
||||
|
||||
void TripOdometer::onSlowCallback() {
|
||||
float meterPerSecond = Sensor::getOrZero(SensorType::VehicleSpeed) / 3.6f;
|
||||
float metersThisTick = meterPerSecond * (SLOW_CALLBACK_PERIOD_MS / 1000.0f);
|
||||
|
||||
m_distanceRemainder += metersThisTick;
|
||||
while (m_distanceRemainder > 1.0f) {
|
||||
m_distanceMeters++;
|
||||
m_distanceRemainder--;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t TripOdometer::getDistanceMeters() const {
|
||||
return m_distanceMeters;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
class TripOdometer : public EngineModule {
|
||||
public:
|
||||
void onSlowCallback() override;
|
||||
void reset();
|
||||
|
||||
void consumeFuel(float grams, efitick_t nowNt);
|
||||
|
||||
uint32_t getConsumedGrams() const;
|
||||
float getConsumptionGramPerSecond() const;
|
||||
uint32_t getDistanceMeters() const;
|
||||
|
||||
private:
|
||||
uint32_t m_consumedGrams = 0;
|
||||
float m_consumedRemainder = 0;
|
||||
float m_rate = 0;
|
||||
|
||||
uint32_t m_distanceMeters = 0;
|
||||
float m_distanceRemainder = 0;
|
||||
|
||||
Timer m_timer;
|
||||
};
|
|
@ -153,8 +153,8 @@ struct Fueling2 {
|
|||
};
|
||||
|
||||
static void populateFrame(Fueling2& msg) {
|
||||
msg.fuelConsumedGram = engine->engineState.fuelConsumption.getConsumedGrams();
|
||||
msg.fuelFlowRate = engine->engineState.fuelConsumption.getConsumptionGramPerSecond();
|
||||
msg.fuelConsumedGram = engine->module<TripOdometer>()->getConsumedGrams();
|
||||
msg.fuelFlowRate = engine->module<TripOdometer>()->getConsumptionGramPerSecond();
|
||||
|
||||
for (size_t i = 0; i < 2; i++) {
|
||||
msg.fuelTrim[i] = 100.0f * (engine->stftCorrection[i] - 1.0f);
|
||||
|
|
|
@ -163,7 +163,7 @@ static void handleGetDataRequest(const CANRxFrame& rx, size_t busIndex) {
|
|||
obdSendPacket(1, pid, 4, scaled << 16, busIndex);
|
||||
break;
|
||||
} case PID_FUEL_RATE: {
|
||||
float gPerSecond = engine->engineState.fuelConsumption.getConsumptionGramPerSecond();
|
||||
float gPerSecond = engine->module<TripOdometer>()->getConsumptionGramPerSecond();
|
||||
float gPerHour = gPerSecond * 3600;
|
||||
float literPerHour = gPerHour * 0.00139f;
|
||||
obdSendValue(_1_MODE, pid, 2, literPerHour * 20.0f, busIndex); // L/h. (A*256+B)/20
|
||||
|
|
|
@ -100,7 +100,9 @@ void InjectionEvent::onTriggerTooth(int rpm, efitick_t nowNt, float currentPhase
|
|||
warning(ObdCode::CUSTOM_TOO_LONG_FUEL_INJECTION, "Too long fuel injection %.2fms", injectionDuration);
|
||||
}
|
||||
|
||||
getEngineState()->fuelConsumption.consumeFuel(injectionMassGrams * numberOfInjections, nowNt);
|
||||
#if EFI_VEHICLE_SPEED
|
||||
engine->module<TripOdometer>()->consumeFuel(injectionMassGrams * numberOfInjections, nowNt);
|
||||
#endif // EFI_VEHICLE_SPEED
|
||||
|
||||
if (this->cylinderNumber == 0) {
|
||||
engine->outputChannels.actualLastInjection = injectionDuration;
|
||||
|
|
Loading…
Reference in New Issue