From 70b239beab2b48cf02d2b569610e64366be0a033 Mon Sep 17 00:00:00 2001 From: Cobalt6700 <44681021+Cobalt6700@users.noreply.github.com> Date: Mon, 27 Apr 2026 10:56:08 +0100 Subject: [PATCH 1/7] Added 5 tick delay for CRSF telemetry to allow data to stabilise This is to prevent the first battery voltage reading being used to calculate fuel. When booting the value reported by INAV can lower than the actual pack voltage due to the inrush current. Adding a small delay (at around 50hz, so the delay is between 100ms and 250 ms) allows the values to settle and the pack voltage and fuel value to be calculated correctly. --- src/SCRIPTS/TELEMETRY/iNav/crsf.lua | 6 ++++++ src/SCRIPTS/TELEMETRY/iNav/reset.lua | 1 + 2 files changed, 7 insertions(+) diff --git a/src/SCRIPTS/TELEMETRY/iNav/crsf.lua b/src/SCRIPTS/TELEMETRY/iNav/crsf.lua index 7243fbca..f58ffa69 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/crsf.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/crsf.lua @@ -33,10 +33,16 @@ local function crsf(data) data.rssi = 0 data.tpwr = 0 data.telem = false + data.crsfReady = 0 return 0 end end end + + if data.crsfReady < 5 then + data.crsfReady = data.crsfReady + 1 + return 0 + end if data.rssi == 99 then data.rssi = 100 end data.tpwr = getValue(data.tpwr_id) diff --git a/src/SCRIPTS/TELEMETRY/iNav/reset.lua b/src/SCRIPTS/TELEMETRY/iNav/reset.lua index 57bcfcc0..4cf3b0e7 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/reset.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/reset.lua @@ -1,5 +1,6 @@ local data = ... +data.crsfReady = 0 data.armed = false data.startup = 1 data.timerStart = 0 From 4f0786ee7409079d6037d589959a1744e1c90838 Mon Sep 17 00:00:00 2001 From: Cobalt6700 <44681021+Cobalt6700@users.noreply.github.com> Date: Mon, 27 Apr 2026 12:37:00 +0100 Subject: [PATCH 2/7] Added CRSF data delay to config menu This gives the option to fine tune the crsf data delay, including setting to 0 which removes the delay. --- src/SCRIPTS/TELEMETRY/iNav/config.lua | 1 + src/SCRIPTS/TELEMETRY/iNav/crsf.lua | 2 +- src/SCRIPTS/TELEMETRY/iNav/menu.lua | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SCRIPTS/TELEMETRY/iNav/config.lua b/src/SCRIPTS/TELEMETRY/iNav/config.lua index 340bf51e..faac0b9d 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/config.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/config.lua @@ -37,6 +37,7 @@ local config = { { o = 26, c = 1, v = 0 }, -- Roll Scale - 33 { o = 34, c = 1, v = 0, l = {[0] = "?"}, x = -1 }, -- Review Log Date - 34 { o = 35, c = 1, v = 0 }, -- Greyscale toggle - 35 + { o = 36, c = 2, v = 5, x = 20 }, -- CRSF data delay - 36 } for i = 1, #config do diff --git a/src/SCRIPTS/TELEMETRY/iNav/crsf.lua b/src/SCRIPTS/TELEMETRY/iNav/crsf.lua index f58ffa69..720602f8 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/crsf.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/crsf.lua @@ -39,7 +39,7 @@ local function crsf(data) end end - if data.crsfReady < 5 then + if data.crsfReady < config[36].v then data.crsfReady = data.crsfReady + 1 return 0 end diff --git a/src/SCRIPTS/TELEMETRY/iNav/menu.lua b/src/SCRIPTS/TELEMETRY/iNav/menu.lua index 1d42c3de..3b0ade9a 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/menu.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/menu.lua @@ -45,6 +45,7 @@ local function view(data, config, units, lang, event, gpsDegMin, getTelemetryId, { t = "Roll Scale", l = 1 }, -- 33 { t = "Playback Log", l = config[34].l }, -- 34 { t = "Greyscale Gfx", l = {[0] = "On", "Off"} }, -- 35 + { t = "CRSF data delay", m = 0, a = " frames" }, -- 36 } -- Import language changes @@ -80,6 +81,8 @@ local function view(data, config, units, lang, event, gpsDegMin, getTelemetryId, config2[24].p = data.crsf and 1 or (config[7].v < 2 and 1 or nil) config2[27].p = (not data.crsf or config[23].v > 0) and 1 or nil config2[35].p = HORUS and 1 or nil + config2[36].p = not data.crsf and 1 or nil + if config2[17].p == nil then config2[17].p = (not data.showCurr or config[23].v ~= 0) and 1 or nil config2[18].p = config2[17].p From cb669ba875483f8059ce04248ca76d8eac800deb Mon Sep 17 00:00:00 2001 From: Cobalt6700 <44681021+Cobalt6700@users.noreply.github.com> Date: Mon, 27 Apr 2026 12:57:40 +0100 Subject: [PATCH 3/7] Update Configuration-Settings.md --- docs/Configuration-Settings.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/Configuration-Settings.md b/docs/Configuration-Settings.md index 3afce7a4..ffc3bfb8 100644 --- a/docs/Configuration-Settings.md +++ b/docs/Configuration-Settings.md @@ -89,6 +89,7 @@ Note also that on some of the smaller B&W radios (Boxer, Zorro, TX12) with a rol * **GPS** - GPS coordinates as decimal or degrees/minutes format (default: Decimal) * **Playback Log** - Playback telemetry log files (latest 5 logs from the last 2 weeks) **[[help](../Configuration-Settings/#playback-telemetry-log-files)]** * **Greyscale Gfx** - Turn on/off the use of greyscale display graphics (only for monochrome displays) + * **CRSF data delay** - Set the delay before CRSF telemetry values are used after the FC is initialised ### Suggested Battery Settings #### Voltage and Current Calibration From 582f7b5ac4fa848f4d70fa6980a94eb9deab1b7a Mon Sep 17 00:00:00 2001 From: Cobalt6700 <44681021+Cobalt6700@users.noreply.github.com> Date: Wed, 29 Apr 2026 16:34:24 +0100 Subject: [PATCH 4/7] Rewrite of CRSF fuel calculation to add a configurable timed delay. This performs consistently compared to the previous version. We now use a time delay and watch for a voltage increase. This is consistent with an FC seeing inrush current on startup with a slight voltage sag. Once the voltage has been stable for the time delay, the pack voltage is then used to calculate the fuel. Fuel reading to the user is shown as -1% whilst this delay is active to give obvious feedback that the fuel is not yet calculated. Debug options left in for testing, will be removed before merge. --- docs/Configuration-Settings.md | 2 +- src/SCRIPTS/TELEMETRY/iNav/config.lua | 2 +- src/SCRIPTS/TELEMETRY/iNav/crsf.lua | 54 ++++++++++++++++++++------- src/SCRIPTS/TELEMETRY/iNav/menu.lua | 2 +- src/SCRIPTS/TELEMETRY/iNav/reset.lua | 4 +- 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/docs/Configuration-Settings.md b/docs/Configuration-Settings.md index ffc3bfb8..d6a10a9b 100644 --- a/docs/Configuration-Settings.md +++ b/docs/Configuration-Settings.md @@ -89,7 +89,7 @@ Note also that on some of the smaller B&W radios (Boxer, Zorro, TX12) with a rol * **GPS** - GPS coordinates as decimal or degrees/minutes format (default: Decimal) * **Playback Log** - Playback telemetry log files (latest 5 logs from the last 2 weeks) **[[help](../Configuration-Settings/#playback-telemetry-log-files)]** * **Greyscale Gfx** - Turn on/off the use of greyscale display graphics (only for monochrome displays) - * **CRSF data delay** - Set the delay before CRSF telemetry values are used after the FC is initialised + * **CRSF Fuel Delay** - Set the delay before CRSF telemetry values are used for fuel calc, after the FC is initialised ### Suggested Battery Settings #### Voltage and Current Calibration diff --git a/src/SCRIPTS/TELEMETRY/iNav/config.lua b/src/SCRIPTS/TELEMETRY/iNav/config.lua index faac0b9d..1e0a3a25 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/config.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/config.lua @@ -37,7 +37,7 @@ local config = { { o = 26, c = 1, v = 0 }, -- Roll Scale - 33 { o = 34, c = 1, v = 0, l = {[0] = "?"}, x = -1 }, -- Review Log Date - 34 { o = 35, c = 1, v = 0 }, -- Greyscale toggle - 35 - { o = 36, c = 2, v = 5, x = 20 }, -- CRSF data delay - 36 + { o = 36, c = 2, v = 2.0, d = true, x = 5.0 }, -- CRSF Fuel Delay - 36 } for i = 1, #config do diff --git a/src/SCRIPTS/TELEMETRY/iNav/crsf.lua b/src/SCRIPTS/TELEMETRY/iNav/crsf.lua index 720602f8..78045e89 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/crsf.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/crsf.lua @@ -13,12 +13,23 @@ data.fpv_id = getTelemetryId("Hdg") data.tpwr = 0 data.rfmd = "--" data.fuelRaw = 0 + config[9].v = 0 config[14].v = 0 config[21].v = 2.5 config[22].v = 0 config[23].x = 1 +local counter = ... -- debug print +counter.loop = 0 -- debug print +setSerialBaudrate(115200) -- debug print + +local function debug_print_text(str) -- debug print + local full_str = string.format("Lo: %4d - %s", counter.loop, str) + print(full_str) + serialWrite(full_str .. "\r\n") +end + local function crsf(data) local vtest vtest = getValue(data.rssi_id) @@ -33,16 +44,10 @@ local function crsf(data) data.rssi = 0 data.tpwr = 0 data.telem = false - data.crsfReady = 0 return 0 end end end - - if data.crsfReady < config[36].v then - data.crsfReady = data.crsfReady + 1 - return 0 - end if data.rssi == 99 then data.rssi = 100 end data.tpwr = getValue(data.tpwr_id) @@ -58,16 +63,39 @@ local function crsf(data) data.heading = math.deg(getValue(data.hdg_id)) if data.fpv_id > -1 then data.fpv = getValue(data.fpv_id) * 10 end ]] + data.fuelRaw = data.fuel if data.showFuel and config[23].v == 0 then - if data.fuelEst == -1 and data.cell > 0 then - if data.fuel < 25 and config[29].v - data.cell >= 0.2 then - data.fuelEst = math.max(math.min(1 - (data.cell - config[2].v + 0.1) / (config[29].v - config[2].v), 1), 0) * config[27].v - else - data.fuelEst = 0 + if config[36].v == 0 and data.voltStab == false then data.voltStab = true end -- No voltstab timer set + if data.voltStab then + if data.fuelEst == -1 and data.cell > 0 then + if data.fuel < 25 and config[29].v - data.cell >= 0.2 then + data.fuelEst = math.max(math.min(1 - (data.cell - config[2].v + 0.1) / (config[29].v - config[2].v), 1), 0) * config[27].v + debug_print_text("fuelEst - Fuel Calculated") -- debug print + else + data.fuelEst = 0 + debug_print_text("fuelEst - Batt Full") -- debug print + end + end + data.fuel = math.max(math.min(math.floor((1 - (data.fuel + data.fuelEst) / config[27].v) * 100 + 0.5), 100), 0) + else + data.fuel = -1 -- fuel set to -1 for obvious feedback that fuel is not yet calculated + if data.cell_prev ~= data.cell then + debug_print_text("Cell change") + if data.cell > data.cell_prev then -- voltage is higher, start a timer + debug_print_text("fuelEst Reset") -- debug print + data.voltTimer = getTime() + end + data.cell_prev = data.cell + end + if data.voltTimer > 0 and ( data.voltTimer and (getTime() - data.voltTimer) >= (config[36].v * 100) ) then + -- if no voltage increase in the set time, the pack voltage reading is taken as stabilised. + debug_print_text("crsfStab") + data.voltStab = true + data.voltTimer = (getTime() - data.voltTimer) + debug_print_text(tostring(data.voltTimer)) -- debug print end end - data.fuel = math.max(math.min(math.floor((1 - (data.fuel + data.fuelEst) / config[27].v) * 100 + 0.5), 100), 0) end data.fm = getValue(data.fm_id) data.modePrev = data.mode @@ -124,7 +152,7 @@ local function crsf(data) data.mode = 40004 end end - + counter.loop = counter.loop + 1 -- debug print return 0 end diff --git a/src/SCRIPTS/TELEMETRY/iNav/menu.lua b/src/SCRIPTS/TELEMETRY/iNav/menu.lua index 3b0ade9a..0d0bea21 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/menu.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/menu.lua @@ -45,7 +45,7 @@ local function view(data, config, units, lang, event, gpsDegMin, getTelemetryId, { t = "Roll Scale", l = 1 }, -- 33 { t = "Playback Log", l = config[34].l }, -- 34 { t = "Greyscale Gfx", l = {[0] = "On", "Off"} }, -- 35 - { t = "CRSF data delay", m = 0, a = " frames" }, -- 36 + { t = "CRSF Fuel Delay", m = 0, i = 0.5, a = "S" }, -- 36 } -- Import language changes diff --git a/src/SCRIPTS/TELEMETRY/iNav/reset.lua b/src/SCRIPTS/TELEMETRY/iNav/reset.lua index 4cf3b0e7..77b8ac4f 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/reset.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/reset.lua @@ -1,6 +1,8 @@ local data = ... -data.crsfReady = 0 +data.voltTimer = 0 +data.voltStab = false +data.cell_prev = 0.0 data.armed = false data.startup = 1 data.timerStart = 0 From b29c3fd55413dbd49908c88bc17a4a4b16094342 Mon Sep 17 00:00:00 2001 From: Cobalt6700 <44681021+Cobalt6700@users.noreply.github.com> Date: Wed, 29 Apr 2026 16:59:41 +0100 Subject: [PATCH 5/7] Updated debug prints to provide voltage information --- src/SCRIPTS/TELEMETRY/iNav/crsf.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/SCRIPTS/TELEMETRY/iNav/crsf.lua b/src/SCRIPTS/TELEMETRY/iNav/crsf.lua index 78045e89..38b31161 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/crsf.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/crsf.lua @@ -71,7 +71,7 @@ local function crsf(data) if data.fuelEst == -1 and data.cell > 0 then if data.fuel < 25 and config[29].v - data.cell >= 0.2 then data.fuelEst = math.max(math.min(1 - (data.cell - config[2].v + 0.1) / (config[29].v - config[2].v), 1), 0) * config[27].v - debug_print_text("fuelEst - Fuel Calculated") -- debug print + debug_print_text(string.format("fuelEst - Fuel Calculated @ %d", data.fuelEst)) -- debug print else data.fuelEst = 0 debug_print_text("fuelEst - Batt Full") -- debug print @@ -81,7 +81,7 @@ local function crsf(data) else data.fuel = -1 -- fuel set to -1 for obvious feedback that fuel is not yet calculated if data.cell_prev ~= data.cell then - debug_print_text("Cell change") + debug_print_text(string.format("Cell change: %.2f -> %.2f", data.cell_prev, data.cell)) if data.cell > data.cell_prev then -- voltage is higher, start a timer debug_print_text("fuelEst Reset") -- debug print data.voltTimer = getTime() @@ -89,11 +89,10 @@ local function crsf(data) data.cell_prev = data.cell end if data.voltTimer > 0 and ( data.voltTimer and (getTime() - data.voltTimer) >= (config[36].v * 100) ) then - -- if no voltage increase in the set time, the pack voltage reading is taken as stabilised. - debug_print_text("crsfStab") + -- if no voltage increase in the set time, the pack voltage reading is taken as stabilised. data.voltStab = true data.voltTimer = (getTime() - data.voltTimer) - debug_print_text(tostring(data.voltTimer)) -- debug print + debug_print_text(string.format("voltStab - Time %.2f s", (data.voltTimer/100))) end end end From c61fe50a2e034f5ce62bbdd48873b7e94b81343e Mon Sep 17 00:00:00 2001 From: Cobalt6700 <44681021+Cobalt6700@users.noreply.github.com> Date: Tue, 5 May 2026 14:18:29 +0100 Subject: [PATCH 6/7] Code sanitised after functional testing Debug prints and loop counter removed. --- src/SCRIPTS/TELEMETRY/iNav/crsf.lua | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/src/SCRIPTS/TELEMETRY/iNav/crsf.lua b/src/SCRIPTS/TELEMETRY/iNav/crsf.lua index 38b31161..0454eaaa 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/crsf.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/crsf.lua @@ -20,16 +20,6 @@ config[21].v = 2.5 config[22].v = 0 config[23].x = 1 -local counter = ... -- debug print -counter.loop = 0 -- debug print -setSerialBaudrate(115200) -- debug print - -local function debug_print_text(str) -- debug print - local full_str = string.format("Lo: %4d - %s", counter.loop, str) - print(full_str) - serialWrite(full_str .. "\r\n") -end - local function crsf(data) local vtest vtest = getValue(data.rssi_id) @@ -66,24 +56,20 @@ local function crsf(data) data.fuelRaw = data.fuel if data.showFuel and config[23].v == 0 then - if config[36].v == 0 and data.voltStab == false then data.voltStab = true end -- No voltstab timer set + if config[36].v == 0 and data.voltStab == false then data.voltStab = true end if data.voltStab then if data.fuelEst == -1 and data.cell > 0 then if data.fuel < 25 and config[29].v - data.cell >= 0.2 then - data.fuelEst = math.max(math.min(1 - (data.cell - config[2].v + 0.1) / (config[29].v - config[2].v), 1), 0) * config[27].v - debug_print_text(string.format("fuelEst - Fuel Calculated @ %d", data.fuelEst)) -- debug print + data.fuelEst = math.max(math.min(1 - (data.cell - config[2].v + 0.1) / (config[29].v - config[2].v), 1), 0) * config[27].v else data.fuelEst = 0 - debug_print_text("fuelEst - Batt Full") -- debug print end end data.fuel = math.max(math.min(math.floor((1 - (data.fuel + data.fuelEst) / config[27].v) * 100 + 0.5), 100), 0) else data.fuel = -1 -- fuel set to -1 for obvious feedback that fuel is not yet calculated if data.cell_prev ~= data.cell then - debug_print_text(string.format("Cell change: %.2f -> %.2f", data.cell_prev, data.cell)) - if data.cell > data.cell_prev then -- voltage is higher, start a timer - debug_print_text("fuelEst Reset") -- debug print + if data.cell > data.cell_prev then data.voltTimer = getTime() end data.cell_prev = data.cell @@ -92,7 +78,6 @@ local function crsf(data) -- if no voltage increase in the set time, the pack voltage reading is taken as stabilised. data.voltStab = true data.voltTimer = (getTime() - data.voltTimer) - debug_print_text(string.format("voltStab - Time %.2f s", (data.voltTimer/100))) end end end @@ -151,7 +136,7 @@ local function crsf(data) data.mode = 40004 end end - counter.loop = counter.loop + 1 -- debug print + return 0 end From ace22250b9efe1e89a9001d26560b701ab557fe3 Mon Sep 17 00:00:00 2001 From: Cobalt6700 <44681021+Cobalt6700@users.noreply.github.com> Date: Tue, 5 May 2026 14:33:30 +0100 Subject: [PATCH 7/7] Updated config array ident --- src/SCRIPTS/TELEMETRY/iNav/config.lua | 3 ++- src/SCRIPTS/TELEMETRY/iNav/crsf.lua | 4 ++-- src/SCRIPTS/TELEMETRY/iNav/menu.lua | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/SCRIPTS/TELEMETRY/iNav/config.lua b/src/SCRIPTS/TELEMETRY/iNav/config.lua index 1e0a3a25..e800c6a1 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/config.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/config.lua @@ -37,7 +37,8 @@ local config = { { o = 26, c = 1, v = 0 }, -- Roll Scale - 33 { o = 34, c = 1, v = 0, l = {[0] = "?"}, x = -1 }, -- Review Log Date - 34 { o = 35, c = 1, v = 0 }, -- Greyscale toggle - 35 - { o = 36, c = 2, v = 2.0, d = true, x = 5.0 }, -- CRSF Fuel Delay - 36 + { o = 36, c = 1, v = 0 }, -- Horizon Mode - 36 + { o = 37, c = 2, v = 2.0, d = true, x = 5.0 }, -- CRSF Fuel Delay - 37 } for i = 1, #config do diff --git a/src/SCRIPTS/TELEMETRY/iNav/crsf.lua b/src/SCRIPTS/TELEMETRY/iNav/crsf.lua index 0454eaaa..0516ef16 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/crsf.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/crsf.lua @@ -56,7 +56,7 @@ local function crsf(data) data.fuelRaw = data.fuel if data.showFuel and config[23].v == 0 then - if config[36].v == 0 and data.voltStab == false then data.voltStab = true end + if config[37].v == 0 and data.voltStab == false then data.voltStab = true end if data.voltStab then if data.fuelEst == -1 and data.cell > 0 then if data.fuel < 25 and config[29].v - data.cell >= 0.2 then @@ -74,7 +74,7 @@ local function crsf(data) end data.cell_prev = data.cell end - if data.voltTimer > 0 and ( data.voltTimer and (getTime() - data.voltTimer) >= (config[36].v * 100) ) then + if data.voltTimer > 0 and ( data.voltTimer and (getTime() - data.voltTimer) >= (config[37].v * 100) ) then -- if no voltage increase in the set time, the pack voltage reading is taken as stabilised. data.voltStab = true data.voltTimer = (getTime() - data.voltTimer) diff --git a/src/SCRIPTS/TELEMETRY/iNav/menu.lua b/src/SCRIPTS/TELEMETRY/iNav/menu.lua index 0d0bea21..af4b8d54 100644 --- a/src/SCRIPTS/TELEMETRY/iNav/menu.lua +++ b/src/SCRIPTS/TELEMETRY/iNav/menu.lua @@ -45,7 +45,8 @@ local function view(data, config, units, lang, event, gpsDegMin, getTelemetryId, { t = "Roll Scale", l = 1 }, -- 33 { t = "Playback Log", l = config[34].l }, -- 34 { t = "Greyscale Gfx", l = {[0] = "On", "Off"} }, -- 35 - { t = "CRSF Fuel Delay", m = 0, i = 0.5, a = "S" }, -- 36 + { t = "Horizon Mode", l = {[0] = "Standard", "Fixed"} }, -- 36 + { t = "CRSF Fuel Delay", m = 0, i = 0.5, a = "s" }, -- 37 } -- Import language changes