From c0bc696b86ceffafb9d04f70bba8de7dbe4f4b32 Mon Sep 17 00:00:00 2001 From: Randy Mackay Date: Wed, 12 Feb 2020 13:51:14 +0900 Subject: [PATCH] AP_Scripting: add arming-check-batt-temp example script --- .../examples/arming-check-batt-temp .lua | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 libraries/AP_Scripting/examples/arming-check-batt-temp .lua diff --git a/libraries/AP_Scripting/examples/arming-check-batt-temp .lua b/libraries/AP_Scripting/examples/arming-check-batt-temp .lua new file mode 100644 index 0000000000..7cc0e62e6c --- /dev/null +++ b/libraries/AP_Scripting/examples/arming-check-batt-temp .lua @@ -0,0 +1,21 @@ +-- This script runs a custom arming check of the battery temperature + +auth_id = arming:get_aux_auth_id() +batt_temp_max = 35 + +function update() -- this is the loop which periodically runs + if auth_id then + now = millis() + batt_temp = battery:get_temperature(0) + if not batt_temp then + arming:set_aux_auth_failed(auth_id, "Could not retrieve battery temperature") + elseif (batt_temp >= batt_temp_max) then + arming:set_aux_auth_failed(auth_id, "Batt temp too high (" .. tostring(batt_temp) .. "C > " .. tostring(batt_temp_max) .. "C)") + else + arming:set_aux_auth_passed(auth_id) + end + end + return update, 5000 -- reschedules the loop in 5 seconds +end + +return update() -- run immediately before starting to reschedule