From 1e82319bfafc46c8fba505cd1d4bc895a33c1c45 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 May 2022 20:12:23 +1000 Subject: [PATCH] AP_EFI: added fuel usage integration for Lutan EFI allows for EFI_COEF1 and EFI_COEF2 to be set to get fuel consumption on GCS --- libraries/AP_EFI/AP_EFI_Serial_Lutan.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libraries/AP_EFI/AP_EFI_Serial_Lutan.cpp b/libraries/AP_EFI/AP_EFI_Serial_Lutan.cpp index 1d0141d6be..c9589b7c4e 100644 --- a/libraries/AP_EFI/AP_EFI_Serial_Lutan.cpp +++ b/libraries/AP_EFI/AP_EFI_Serial_Lutan.cpp @@ -21,6 +21,9 @@ #if HAL_EFI_ENABLED #include +// RPM Threshold for fuel consumption estimator +#define RPM_THRESHOLD 100 + extern const AP_HAL::HAL &hal; AP_EFI_Serial_Lutan::AP_EFI_Serial_Lutan(AP_EFI &_frontend): @@ -60,7 +63,6 @@ void AP_EFI_Serial_Lutan::update() const uint32_t crc2 = ~crc_crc32(~0U, &pkt[2], length); if (crc == crc2) { // valid data - internal_state.last_updated_ms = now; internal_state.spark_dwell_time_ms = int16_t(be16toh(data.dwell))*0.1; internal_state.cylinder_status[0].injection_time_ms = be16toh(data.pulseWidth1)*0.00666; internal_state.engine_speed_rpm = be16toh(data.rpm); @@ -71,6 +73,16 @@ void AP_EFI_Serial_Lutan::update() // CHT is in coolant field internal_state.cylinder_status[0].cylinder_head_temperature = internal_state.coolant_temperature; internal_state.throttle_position_percent = int16_t(be16toh(data.tps))*0.1; + + // integrate fuel consumption + if (internal_state.engine_speed_rpm > RPM_THRESHOLD) { + const float duty_cycle = (internal_state.cylinder_status[0].injection_time_ms * internal_state.engine_speed_rpm)/600.0f; + internal_state.fuel_consumption_rate_cm3pm = duty_cycle*get_coef1() - get_coef2(); + internal_state.estimated_consumed_fuel_volume_cm3 += internal_state.fuel_consumption_rate_cm3pm * (now - internal_state.last_updated_ms)/60000.0f; + } else { + internal_state.fuel_consumption_rate_cm3pm = 0; + } + internal_state.last_updated_ms = now; copy_to_frontend(); } pkt_nbytes = 0;