-
Notifications
You must be signed in to change notification settings - Fork 17.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AP_Scripting: example script to release gripper on thrust loss
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
libraries/AP_Scripting/examples/copter-release-gripper-thrust-loss.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--[[ | ||
This script should only be used on multicopters | ||
The gripper is released when thrust loss is detected | ||
Note that thrust loss false positives are common meaning the gripper may be released unnecessarily | ||
--]] | ||
|
||
local MAV_SEVERITY = {EMERGENCY=0, ALERT=1, CRITICAL=2, ERROR=3, WARNING=4, NOTICE=5, INFO=6, DEBUG=7} | ||
|
||
local update_interval_ms = 100 | ||
local thrust_loss_counter = 0 | ||
|
||
function update() | ||
|
||
-- return immediately if not armed | ||
if not arming:is_armed() then | ||
thrust_loss_counter = 0 | ||
return update, update_interval_ms | ||
end | ||
|
||
-- return if no thrust loss | ||
if not MotorsMatrix:get_thrust_boost() then | ||
thrust_loss_counter = 0 | ||
return update, update_interval_ms | ||
end | ||
|
||
-- return if vehicle is not descending (or cannot retrieve climb rate) | ||
local vel_NED = ahrs:get_velocity_NED() | ||
if vel_NED == nil or vel_NED:z() <= 0 then | ||
thrust_loss_counter = 0 | ||
return update, update_interval_ms | ||
end | ||
|
||
-- vehicle is descending and thrust loss is detected | ||
thrust_loss_counter = thrust_loss_counter + 1 | ||
if thrust_loss_counter < 10 then | ||
return update, update_interval_ms | ||
end | ||
|
||
-- release gripper and warn user | ||
if not gripper:released() then | ||
gripper:release() | ||
gcs:send_text(MAV_SEVERITY.WARNING, "Thrust loss, gripper released!") | ||
end | ||
|
||
return update, update_interval_ms | ||
end | ||
|
||
return update, update_interval_ms |