Skip to content

Commit

Permalink
LUA : disable esc telem warnings when safety disengage
Browse files Browse the repository at this point in the history
  • Loading branch information
Pradeep-Carbonix committed Dec 30, 2024
1 parent 3885a97 commit c704876
Showing 1 changed file with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
local cx_msg = require("msg")
local aircraft_type = require("aircraft")

safety_state = { SAFETY_NONE = 0, SAFETY_DISARMED = 1, SAFETY_ARMED = 2 }

local ESC = {
name = "ESC",

number_of_esc = 5,

-- CONSTANTS
Expand All @@ -17,7 +19,9 @@ local ESC = {
srv_prv_telem_ms = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
srv_telem_in_err_status = {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},
srv_rpm_in_err_status = {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false},


prev_safe = safety_state.SAFETY_NONE,

-- Counters to debounce nil checks on esc rpm and servo output, this is a
-- workaround to avoid giving the pilot a critical warning for an unexplained
-- one-loop dropout we saw recently
Expand Down Expand Up @@ -62,7 +66,7 @@ function ESC:init()
self.esc_warmup_end_time[i] = nil
self.srv_prv_telem_ms[i] = 0
end
cx_msg:send(cx_msg.MAV_SEVERITY.INFO, "ESC init (" .. aircraft_type .. ": " .. self.number_of_esc .. " ESCs)")
cx_msg:send(cx_msg.MAV_SEVERITY.INFO, "ESC init (" .. aircraft_type .. ": " .. self.number_of_esc .. " ESCs)")
end


Expand All @@ -79,6 +83,25 @@ function ESC:esc_is_stopped(i)
end

function ESC:update()
-- When the safety is engaged, the ESCs do not output telemetry
local safe = SRV_Channels:get_safety_state()
if safe ~= safety_state.SAFETY_DISARMED then
self.prev_safe = safe
return
else
if self.prev_safe ~= safety_state.SAFETY_DISARMED then
-- Reset all counters and error flags when safety is disarmed
for i = 1, self.number_of_esc do
self.esc_warmup_end_time[i] = nil
self.srv_prv_telem_ms[i] = 0
self.srv_telem_in_err_status[i] = false
self.srv_rpm_in_err_status[i] = false
self.esc_rpm_nil_counter[i] = 0
self.servo_out_nil_counter[i] = 0
end
self.prev_safe = safety_state.SAFETY_DISARMED
end
end
for i = 1, self.number_of_esc do
local esc_last_telem_data_ms = esc_telem:get_last_telem_data_ms(i-1):toint()
local esc_rpm = esc_telem:get_rpm(i-1)
Expand Down Expand Up @@ -137,7 +160,7 @@ function ESC:update()
end
end
end
else
else
self:esc_is_stopped(i)
end
end
Expand All @@ -150,7 +173,7 @@ end

-- Return error messages
function ESC:check_for_errors()
for _, status in ipairs(self.srv_telem_in_err_status) do
for _, status in ipairs(self.srv_telem_in_err_status) do
if status then
return {"ESC Telemetry Lost"}
end
Expand Down

0 comments on commit c704876

Please sign in to comment.