# Vehicle isn't executing target depth command correctly

**URL:** <https://discuss.bluerobotics.com/t/vehicle-isnt-executing-target-depth-command-correctly/10539>\
**Category:** ArduSub\
**Tags:** pymavlink\
**Created:** [September 5, 2021, 3:16pm UTC](https://discuss.bluerobotics.com/t/vehicle-isnt-executing-target-depth-command-correctly/10539 "2021-09-05T15:16:06Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![ROVenjoyer](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@ROVenjoyer](https://discuss.bluerobotics.com/u/ROVenjoyer)\
**Post date:** [February 27, 2023, 5:18pm UTC](https://discuss.bluerobotics.com/t/vehicle-isnt-executing-target-depth-command-correctly/10539/6 "2023-02-27T17:18:36Z")

</div>

Hi guys,  
my problem might be related to this topic.

I encountered a problem, when using the _depth hold mode_ in combination with _‘set\_position\_target\_global\_int\_send()’_

**My setup:**  
I am using the _SITL_ provided here: [SITL · GitBook](https://www.ardusub.com/developers/sitl.html)  
I am running it natively on Windows using Cygwin.

I am doing the following steps:  
Setting up SITL

1. Open QGroundControl
2. Open the Cygwin64 Terminal
3. Navigate to _‘~/ardupilot/tools/autotest’_
4. Execute _‘python3.7 sim\_vehicle.py -v ArduSub -L RATBeach --out=udp:0.0.0.0:14550 --map --console’_
5. MAVProxy opens
6. Execute _‘output add 127.0.0.1:14551’_  
Run my Code
7. Run Set Target Depth/Attitude Example: [Pymavlink · GitBook](https://www.ardusub.com/developers/pymavlink.html#set-target-depthattitude)  
This is [my script](https://github.com/Bronnnn/pyArdusubExamples/blob/master/main.py).  
I basically copy and pasted the example. I only changed the target depth from -0.5m to -10m and the udpin from ‘udpin:0.0.0.0:14550’ to the in step 5) added ‘udpin:127.0.0.1:14551’

**My problem**  
I am watching the state of the sub on QGroundControl, where it displays an unexpected behaviour. It either does not hold the specified depth or it does not even dive to the specified depth in the first place.

**My approach to solve this problem**  
I tried a bunch of stuff, like looping _‘set\_position\_target\_global\_int\_send()’_ until it actually reaches the desired depth. Although Eliot stated in this post:

> [@Regarding: pwm signal delays, setting target depth, type\_masks and NED system, setting target attitude, heartbeat message](https://discuss.bluerobotics.com/t/regarding-pwm-signal-delays-setting-target-depth-type-masks-and-ned-system-setting-target-attitude-heartbeat-message/10492/3):
>
> This depends a lot on the code you’re using, the particular operations you need to do, and the hardware you’re running it on. It’s very difficult to comment in a meaningful way without access to that information, although I understand that since this is for a competition you may not be willing/able to share those details. As with every optimisation task, I’d suggest a good starting point is to profile your code, and see where the most time is being spent. As a general principle for Python appl…

it should be set only once.  
But my sub dived to the specified depth, only if i looped it.

But once i start rotating, the sub starts to raise to the surface again, eventhough it is in depth hold mode and i did not change the target depth. All i did, was to use the _‘set\_attitude\_target\_send()’_ function, with the _‘ATTITUDE\_TARGET\_TYPEMASK\_THROTTLE\_IGNORE’_ as used in the previously mentioned example.

I do not know how to debug this either. For example i tried to request the message for _‘POSITION\_TARGET\_GLOBAL\_INT’_ to check if the target depth is actually set, but i received no answer. But i can receive other messages like _‘GLOBAL\_POSITION\_INT’_.  
This is my [current project](https://github.com/Bronnnn/pyArdusub/blob/master/src/ExampleSequences/Testsequence.py) where i tried to use the workaround by looping _‘set\_position\_target\_global\_int\_send()’_ in _Testsequence\_SurfaceComputerToAutopilot\_w\_set\_target\_position()_. It is quite messy though and i do not expect anyone to solve this for me.

**What i am ultimately trying to achieve**  
I am trying to autonomously dive to a specified depth, rotate and make some pictures. That should be an easy task, but i am having a hard time, even with the provided examples.  
I can not test it on the actual submarine for now, thats why i tried to make it work in the _SITL_ first.

I found a bunch of forum entries, that are related to the topic, unfortunately most of them are a dead end to me.

---

_[View the full topic](https://discuss.bluerobotics.com/t/vehicle-isnt-executing-target-depth-command-correctly/10539)._
