Skip to content

Commit

Permalink
Lua scripting: EFI monitor addition
Browse files Browse the repository at this point in the history
SW-61
  • Loading branch information
loki077 committed Feb 5, 2024
1 parent 4435edf commit 5b0e581
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function init_param()
return 0
end

function actuator_telemetry_check()
function all_telemetry_check()
local escs = {M1, M2, M3, M4, M5}

if aircraft_type == UNKNOWN then
Expand All @@ -143,17 +143,26 @@ function actuator_telemetry_check()
local current_ts = tostring(esc_telem:get_last_telem_data_ms(escs[i]))
current_ts = tonumber(current_ts)
if (i < 5 or aircraft_type == VOLANTI) and (current_ts == 0 or current_ts == esc_prev_ts[i]) then
esc_prev_ts[i] = current_ts
return i
end
if i == 5 and aircraft_type == OTTANO then
current_ts = tostring(efi.get_last_update_ms())
current_ts = tonumber(current_ts)
if current_ts == 0 or current_ts == esc_prev_ts[i] then
return i
end
end
esc_prev_ts[i] = current_ts
end
return 0
end

function pre_arm_check()
if pre_arm_init then
local act_return = actuator_telemetry_check()
if act_return ~= 0 then
local act_return = all_telemetry_check()
if act_return == 5 and aircraft_type == OTTANO then
arming:set_aux_auth_failed(auth_id, "EFI Not Responding")
elseif act_return ~= 0 then
arming:set_aux_auth_failed(auth_id, "ESC " .. act_return .. " Not Responding")
else
arming:set_aux_auth_passed(auth_id)
Expand Down Expand Up @@ -187,18 +196,24 @@ local last_msg_time = 0
local esc_telem_failure = false

function during_arm_check()
local act_return = actuator_telemetry_check()
local act_return = all_telemetry_check()
local current_time = get_time_sec()

if act_return ~= 0 then
if act_return == 5 and aircraft_type == OTTANO then
if current_time - last_msg_time >= 15 then
gcs_msg(MSG_NORMAL, MAV_SEVERITY_CRITICAL, "EFI Telemetry Not Responding")
last_msg_time = current_time
end

else if act_return ~= 0 then
if current_time - last_msg_time >= 15 then
gcs_msg(MSG_NORMAL, MAV_SEVERITY_CRITICAL, "ESC " .. act_return .. " Telemetry Not Responding")
last_msg_time = current_time
esc_telem_failure = true
end
else
if esc_telem_failure then
gcs_msg(MSG_NORMAL, MAV_SEVERITY_CRITICAL, "ESC Telemetry Recovered")
gcs_msg(MSG_NORMAL, MAV_SEVERITY_CRITICAL, "Telemetry Recovered")
clear_msg_sent = false
end
end
Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_Scripting/generator/description/bindings.desc
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,9 @@ ap_object AP_EFI_Backend method handle_scripting boolean EFI_State
singleton AP_EFI depends (AP_EFI_SCRIPTING_ENABLED == 1)
singleton AP_EFI rename efi
singleton AP_EFI method get_backend AP_EFI_Backend uint8_t 0 UINT8_MAX
singleton AP_EFI method get_last_update_ms uint32_t



-- ----END EFI Library----

Expand Down

0 comments on commit 5b0e581

Please sign in to comment.