Set target depth in Pixhawk using Pymavlink

Hi,
I just started working on my AUV. I wanted to control it using python and pymavlink library.
How can make the rover stay at certain depth using the depth hold mode.
I can switch to “Stabilize” mode using pymavlink. But not in depth hold mode.

So, can anyone help to set the mode to “Depth Hold” and how to set the target depth

Hi Sakib,

You should be able to set “Depth Hold” mode, please check the ACK return to investigate the problem.
Also, you can check our pymavlink documentation for examples.

Depth hold requires an external pressure sensor like the Bar30 to be connected. If the sensor is not detected, or there is some problem with it, you will not be allowed to use depth hold.

Hi, Jacob.
Sorry for replying late.
We attached the Bar 30 and the depth hold mode is working fine. But we have another problem now. When the target depth is set, The ROV come around 2 feet above and then again goes down to that depth.
How can we hold the dept with maximum 5 inch error ?

There is some problems with depth hold mode. We are working on it:

https://github.com/ArduPilot/ardupilot/issues/9797

In that case can we try something different.
In stabilize mode, we take the reading of depth sensor and then from the pymavlink(We are using an Odroid to control our AUV) and the manually throttle down the AUV. So it stays at perfect depth.

Hi Adnan,

Yes, it’s possible to do the manual alt control via pymavlink and creating your personal algorithm.

The better approach would be to make better code for depth hold in the firmware. The pymavlink approach will introduce unnecessary and unwanted latency.

Is there a way I can see what the target depth/alt value is once I am in depth hold mode? I have it active on my AUV but am having a tough time tuning it without knowing what target depth its supposed to be holding.

In this comment (from a while ago) @williangalvani was discussing the possibility of using the SET_POSITION_TARGET_GLOBAL_INT or SET_POSITION_TARGET_GLOBAL_NED messages for setting the depth to hold. I’m not sure if support has been added for that in ArduSub, or if you’d need to add it yourself, but if you’re able to use it then you’d be able to retrieve the target value with POSITION_TARGET_GLOBAL_INT or POSITION_TARGET_GLOBAL_NED respectively.

Thank you @EliotBR. I just want to control for depth and yaw- am I correct in thinking that if I use SET_POSITION_TARGET_GLOBAL_INT I can set the type mask so that it ignores all the NED parameters?

@jwalser is SET_POSITION_TARGET_GLOBAL_INT supported in sub?

Hi @Coco ,

We have a special cased handled fot setting target depth alone. Check this gist.

Thank you @williangalvani . I need to control yaw as well, is that supported? The comment in that gist makes it look like it is not. For that reason I was trying to send set_target_attitude commands while in depth hold mode. Should that work?

Yes, I believe that should work. is it not? What version of ardusub are you on?