Shallow depth warning and avoidance using lua

I was looking through the Lua examples and noticed this, would this work for boat depth?, im not sure how rover handles altitude information. if it can then it should be able to work as shallow water avoidance without much modification by just setting loiter or hold if the water gets too shallow along with sending a warning back to the ground station.

Ok that didn’t work. What should I use instead altitude.

AP_Terrain is not available on Rover. So I dont see how that script will work for you without adding AP_Terrain to rover.

Someone could add AP_Terrain rover like sub has then if you had a rangefinder that script could work for you likely.

1 Like

is there a way of getting depth data in a lua script? it should just be a matter of swapping it in.

this looks like it works
local depth_under_boat = rangefinder:distance_cm_orient(25)

I have made this lua script to display a warning if the depth is under 2m but its not running correctly, if someone could take a look at it I would be grateful.I’m just copy and pasting, I’m pretty useless at code lol.

ideally, I would like it to display a warning along with the current depth.
depth.lua (369 Bytes)