From a2421c4146c5feb6b1dc21ccfa55844132c05f4c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 17 May 2024 10:01:48 +1000 Subject: [PATCH] AP_Scripting: added throttle and ignition control for INF_INject allows full control over serial --- libraries/AP_Scripting/drivers/INF_Inject.lua | 118 +++++++++++++++++- 1 file changed, 116 insertions(+), 2 deletions(-) diff --git a/libraries/AP_Scripting/drivers/INF_Inject.lua b/libraries/AP_Scripting/drivers/INF_Inject.lua index f1296d4946631a..ef9fa609b1a5d7 100644 --- a/libraries/AP_Scripting/drivers/INF_Inject.lua +++ b/libraries/AP_Scripting/drivers/INF_Inject.lua @@ -9,6 +9,15 @@ local PARAM_TABLE_PREFIX = "EFI_INF_" local MAV_SEVERITY = {EMERGENCY=0, ALERT=1, CRITICAL=2, ERROR=3, WARNING=4, NOTICE=5, INFO=6, DEBUG=7} +local CMD_CDI1 = 1 +local CMD_CDI2 = 2 +local CMD_OIL_PUMP = 3 +-- local CMD_SHUTDOWN = 4 +-- local CMD_PRE_INJECTION = 5 +local CMD_THROTTLE = 6 + +local K_THROTTLE = 70 + -- bind a parameter to a variable given local function bind_param(name) local p = Parameter() @@ -43,6 +52,24 @@ EFI_INF_ENABLE = bind_add_param("ENABLE", 1, 1) --]] EFI_INF_OPTIONS = bind_add_param("OPTIONS", 2, 0) +--[[ + // @Param: EFI_INF_THR_HZ + // @DisplayName: EFI INF-Inject throttle rate + // @Description: EFI INF throttle output rate + // @Range: 0 50 + // @Units: Hz + // @User: Standard +--]] +EFI_INF_THR_HZ = bind_add_param("THR_HZ", 3, 0) + +--[[ + // @Param: EFI_INF_IGN_AUX + // @DisplayName: EFI INF-Inject ignition aux function + // @Description: EFI INF throttle ignition aux function + // @User: Standard +--]] +EFI_INF_IGN_AUX = bind_add_param("IGN_AUX", 4, 300) + local OPTION_LOGGING = (1<<0) --[[ @@ -86,7 +113,12 @@ state.chk0 = 0 state.chk1 = 0 state.total_fuel_g = 0.0 +local last_throttle_send_ms = uint32_t(0) +local last_ignition_send_ms = uint32_t(0) +local last_ign_sw_pos = -1 + local file_handle = nil +local efi_device_id = nil --[[ log a set of bytes @@ -163,7 +195,7 @@ local function check_input() end -- look for basic data table 2 - local _, _, dtype, num, _, ack = string.unpack("= 1 then + command = 1 + end + if sw_pos ~= last_ign_sw_pos then + onoff = "OFF" + if command == 1 then + onoff = "ON" + end + gcs:send_text(MAV_SEVERITY.INFO, string.format("EFI_INF: ignition %s", onoff)) + end + last_ign_sw_pos = sw_pos + send_packet(CMD_CDI1, command) + send_packet(CMD_CDI2, command) + send_packet(CMD_OIL_PUMP, command) +end + --[[ main update function @@ -282,7 +395,8 @@ local function update() if check_input() then update_EFI() end - + update_throttle() + update_ignition() return update, 10 end