Skip to content

Commit

Permalink
AP_Scripting: added bindings for VTOL motor loss
Browse files Browse the repository at this point in the history
this allows a script to take an action on loss of a VTOL motor
  • Loading branch information
tridge committed Jul 10, 2023
1 parent 1b3de3a commit e619273
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libraries/AP_Scripting/docs/docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,13 @@ function MotorsMatrix:add_motor_raw(motor_num, roll_factor, pitch_factor, yaw_fa
---@return boolean
function MotorsMatrix:init(expected_num_motors) end

-- desc get index (starting at 0) of lost motor
---@return integer
function MotorsMatrix:get_lost_motor() end

-- desc return true if we are in thrust boost due to possible lost motor
---@return boolean
function MotorsMatrix:get_thrust_boost() end

-- desc
---@class quadplane
Expand Down
27 changes: 27 additions & 0 deletions libraries/AP_Scripting/examples/motor_lost.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--[[
display motor lost number from MotorsMatrix for multirotors
--]]

local last_motor_lost = -1

function update()
local lost_index
if not MotorsMatrix:get_thrust_boost() then
-- when get_thrust_boost is false then we have not lost a motor
lost_index = -1
else
-- otherwise get the lost motor number
lost_index = MotorsMatrix:get_lost_motor()
end
if lost_index ~= last_motor_lost then
if lost_index == -1 then
gcs:send_text(0, string.format("Motors: recovered"))
else
gcs:send_text(0, string.format("Motors: lost motor %d", lost_index+1))
end
last_motor_lost = lost_index
end
return update, 100
end

return update, 100
2 changes: 2 additions & 0 deletions libraries/AP_Scripting/generator/description/bindings.desc
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ singleton AP_MotorsMatrix rename MotorsMatrix
singleton AP_MotorsMatrix method init boolean uint8_t 0 AP_MOTORS_MAX_NUM_MOTORS
singleton AP_MotorsMatrix method add_motor_raw void int8_t 0 (AP_MOTORS_MAX_NUM_MOTORS-1) float'skip_check float'skip_check float'skip_check uint8_t 0 AP_MOTORS_MAX_NUM_MOTORS
singleton AP_MotorsMatrix method set_throttle_factor boolean int8_t 0 (AP_MOTORS_MAX_NUM_MOTORS-1) float 0 FLT_MAX
singleton AP_MotorsMatrix method get_lost_motor uint8_t
singleton AP_MotorsMatrix method get_thrust_boost boolean

include AP_Frsky_Telem/AP_Frsky_SPort.h
singleton AP_Frsky_SPort rename frsky_sport
Expand Down

0 comments on commit e619273

Please sign in to comment.