Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script for monitoring battery resistance #27571

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libraries/AP_Scripting/docs/docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3147,6 +3147,11 @@ function battery:current_amps(instance) end
---@return number -- resting voltage
function battery:voltage_resting_estimate(instance) end

-- Returns the estimated internal battery resistance in Ohms
---@param instance integer -- battery instance
---@return number -- estimated internal resistance in Ohms
function battery:get_resistance(instance) end

-- Returns the voltage of the selected battery instance.
---@param instance integer -- battery instance
---@return number -- voltage
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--[[
script implementing pre-arm check that internal resistance is sensible
--]]

local MAX_RESISTANCE = 0.03 -- Ohms

local auth_id = assert(arming:get_aux_auth_id())

local warning_last_sent_ms = uint32_t() -- time we last sent a warning message to the user
warning_interval_ms = 10000

function update()
local num_batts = battery:num_instances()
local ok = true
for i=0,num_batts do
local resistance = battery:get_resistance(i)
failed = resistance > MAX_RESISTANCE
if failed then
msg = string.format("Batt[%u] high internal resistance %.5f Ohms", i+1, resistance)
if millis() - warning_last_sent_ms > warning_interval_ms then
gcs:send_text(0, msg)
warning_last_sent_ms = millis()
end
arming:set_aux_auth_failed(auth_id, msg)
ok = false
end
end

if ok then
arming:set_aux_auth_passed(auth_id)
end
return update, 500
end

return update()
1 change: 1 addition & 0 deletions libraries/AP_Scripting/generator/description/bindings.desc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ singleton AP_BattMonitor depends AP_BATTERY_ENABLED
singleton AP_BattMonitor method num_instances uint8_t
singleton AP_BattMonitor method healthy boolean uint8_t 0 ud->num_instances()
singleton AP_BattMonitor method voltage float uint8_t 0 ud->num_instances()
singleton AP_BattMonitor method get_resistance float uint8_t 0 ud->num_instances()
singleton AP_BattMonitor method voltage_resting_estimate float uint8_t 0 ud->num_instances()
singleton AP_BattMonitor method current_amps boolean float'Null uint8_t 0 ud->num_instances()
singleton AP_BattMonitor method consumed_mah boolean float'Null uint8_t 0 ud->num_instances()
Expand Down
Loading