# Desired depth and heading commands in a manual mode (e.g. depth hold mode)

**URL:** <https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640>\
**Category:** Blue Robotics Software\
**Tags:** pymavlink\
**Created:** [July 26, 2019, 7:21pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640 "2019-07-26T19:21:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![supun](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@supun](https://discuss.bluerobotics.com/u/supun)\
**Post date:** [July 26, 2019, 7:21pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/1 "2019-07-26T19:21:55Z")

</div>

Hi - Is there anyway to send desired depth and heading commands while the ROV is in a manual mode such as DEPTH HOLD mode or STABILIZE mode via MAVProxy?

I am integrating a BlueROV2 with a larger ASV, and I would like to send depth and heading commands to the ROV from the ASV. I can do this in the GUIDED mode via mavlink\_msg\_set\_position\_target\_local\_ned message or mavlink\_msg\_command\_long (MAV\_CMD\_CONDITION\_YAW) message. But as soon as I put the ROV to the GUIDED mode (with a faked underwater GPS input) it does some weird movements and we can’t afford that when the ROV is attached to another robot. So I am wondering if we can send depth and heading set points when the ROV is in the DEPTH HOLD mode? Or do you have any other suggestions?

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [July 29, 2019, 12:21pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/2 "2019-07-29T12:21:30Z")

</div>

For depth hold, you can use `set_attitude_target` to select the desired attitude of the vehicle, for the depth, you’ll need to use `rc_channels_override_send` with thrust set points until you hit the desired position.

> [@supun](#):
>
> I can do this in the GUIDED mode via mavlink\_msg\_set\_position\_target\_local\_ned message or mavlink\_msg\_command\_long (MAV\_CMD\_CONDITION\_YAW) message. But as soon as I put the ROV to the GUIDED mode (with a faked underwater GPS input) it does some weird movements

This is probably because your GPS information is not a real system that can give position error information to the ROV, without a real position information (or something close to it), the vehicle will do weird things.

---

<div class="post-metadata">

**Author:** ![supun](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@supun](https://discuss.bluerobotics.com/u/supun)\
**Post date:** [July 30, 2019, 9:58pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/5 "2019-07-30T21:58:19Z")

</div>

Hi @patrickelectric -  
Thanks a lot for your response. I’m currently creating a MOOS interface app for BlueROV2.  
A couple of questions:

> For depth hold, you can use `set_attitude_target_no_gps` to select the desired attitude of the vehicle

1. How do you send `set_attitude_target_no_gps` commands? I can use below piece of code to send mavlink\_msg\_set\_attitude\_target messages, but it seems this only works for GUIDED MODE. How do you send `set_attitude_target_no_gps` commands?

> for the depth, you’ll need to use `rc_channels_override_send` with thrust set points until you hit the desired position.

1. It seems like I need to control individual thrusters if I use `mavlink_msg_rc_channels_override`. Can’t I use `mavlink_msg_manual_control` messages in DEPTH HOLD mode for this purpose? That way I just have to give a thrust in the z direction until it reaches the desired depth. See the below code:

> ```
> if(key == "ROV_THRUST_Z") {
> double m_rov_thrust_z = dval;
> uint16_t length2 = mavlink_msg_manual_control_pack(system_id,1,&m_mavlink_msg,target_system,0,0,m_rov_thrust_z,0,1);
> m_udp_client->send(&m_mavlink_msg);
> }
> 
> ```

Thanks,  
Supun.

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [July 31, 2019, 12:17pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/6 "2019-07-31T12:17:36Z")

</div>

> [@supun](#):
>
> How do you send `set_attitude_target` commands?

`set_attitude_target_no_gps` Is only possible in ALT HOLD mode.  
Your codes appears to be fine, the only problem is the mode that you are using.  
Take a look in the patch that add such [feature here](https://github.com/ArduPilot/ardupilot/commit/d3da8f2914adbda74a0c56947fb8ac83648b04e1), it’ll probably help.

> [@supun](#):
>
> Can’t I use `mavlink_msg_manual_control` messages in DEPTH HOLD mode for this purpose?

Yes, you can, both messages are valid.

---

<div class="post-metadata">

**Author:** ![supun](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@supun](https://discuss.bluerobotics.com/u/supun)\
**Post date:** [August 1, 2019, 4:49am UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/7 "2019-08-01T04:49:53Z")

</div>

Thanks @patrickelectric. I tried mavlink\_msg\_set\_attitude\_target message according to my above code in ALT HOLD mode, but the ROV did not respond.

My BlueROV-MOOS interface apps run in the ASV’s computer and ideal would be just sending desired depth and heading commands to the ROV. I can run a simple feedback controller in the topside (ASV) computer but sometimes data through the mavlink\_msg\_vfr\_hud message has a large delay (\>3 seconds). Is this usual?

---

<div class="post-metadata">

**Author:** ![williangalvani](https://avatars.discourse-cdn.com/v4/letter/w/6f9a4e/32.png) [@williangalvani](https://discuss.bluerobotics.com/u/williangalvani)\
**Post date:** [August 1, 2019, 11:57am UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/8 "2019-08-01T11:57:08Z")

</div>

Hello,

The SET\_ATTITUDE\_TARGET message is currently not supported in ArduSub Stable, only in Beta.

VFR\_HUD is the message used by QGC to show the ROV heading, this delay seems unusual.

---

<div class="post-metadata">

**Author:** ![Coco](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Coco](https://discuss.bluerobotics.com/u/Coco)\
**Post date:** [July 22, 2020, 8:12pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/9 "2020-07-22T20:12:33Z")

</div>

Hi @supun I wanted to use that mav\_set\_attitude\_no\_gps but can’t find the actual message anywhere. Would you be willing to provide it or direct me to where you found it? Thank you!

---

<div class="post-metadata">

**Author:** ![williangalvani](https://avatars.discourse-cdn.com/v4/letter/w/6f9a4e/32.png) [@williangalvani](https://discuss.bluerobotics.com/u/williangalvani)\
**Post date:** [July 22, 2020, 8:35pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/10 "2020-07-22T20:35:48Z")

</div>

Hi @Coco,

Try [this gist](https://gist.github.com/Williangalvani/6dac6849b26c83ec89756c03c95818b0).

---

<div class="post-metadata">

**Author:** ![Coco](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Coco](https://discuss.bluerobotics.com/u/Coco)\
**Post date:** [July 22, 2020, 8:54pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/11 "2020-07-22T20:54:09Z")

</div>

Thanks @williangalvani

Whenever I use the mav\_set\_attitude message though it appears to define the attitude of the flight controller itself because the compass and horizion line I can see in QGC go totally crazy- like its overriding the internal compass data. Any idea why I am getting this instead of the desired result?

---

<div class="post-metadata">

**Author:** ![williangalvani](https://avatars.discourse-cdn.com/v4/letter/w/6f9a4e/32.png) [@williangalvani](https://discuss.bluerobotics.com/u/williangalvani)\
**Post date:** [July 22, 2020, 9:34pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/12 "2020-07-22T21:34:14Z")

</div>

That is odd,  
What version of Ardusub are you running?

---

<div class="post-metadata">

**Author:** ![Coco](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Coco](https://discuss.bluerobotics.com/u/Coco)\
**Post date:** [July 22, 2020, 11:16pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/13 "2020-07-22T23:16:00Z")

</div>

@williangalvani 3.5.4

---

<div class="post-metadata">

**Author:** ![williangalvani](https://avatars.discourse-cdn.com/v4/letter/w/6f9a4e/32.png) [@williangalvani](https://discuss.bluerobotics.com/u/williangalvani)\
**Post date:** [July 23, 2020, 1:30am UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/14 "2020-07-23T01:30:32Z")

</div>

IIRC that was done properly after 3.5.4, try 4.0.1

---

<div class="post-metadata">

**Author:** ![Coco](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Coco](https://discuss.bluerobotics.com/u/Coco)\
**Post date:** [July 24, 2020, 3:21am UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/15 "2020-07-24T03:21:38Z")

</div>

Thanks @williangalvani

I have a couple mods that I made to ALT\_HOLD mode in 3.5 that for now I’d like to avoid moving the 4.0 (they aren’t what is causing it to freak out- it does the same thing in the stock version of 3.5). If I am trying to stick with 3.5 for now it sounds like I could use the msg\_manual\_control? For parameters like pitch that would effect the depth can I give null values somehow or does it not matter because ALT\_HOLD will override those?

---

<div class="post-metadata">

**Author:** ![williangalvani](https://avatars.discourse-cdn.com/v4/letter/w/6f9a4e/32.png) [@williangalvani](https://discuss.bluerobotics.com/u/williangalvani)\
**Post date:** [July 24, 2020, 12:51pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/16 "2020-07-24T12:51:05Z")

</div>

try cherry-picking this, then:

> <https://github.com/ArduPilot/ardupilot/commit/d3da8f2914adbda74a0c56947fb8ac83648b04e1>
>
> Allow ordinary attitude positions without a gps system
> 
> Signed-off-by: Patrick J…osé Pereira \<patrickelectric@gmail.com\>

---

<div class="post-metadata">

**Author:** ![Coco](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Coco](https://discuss.bluerobotics.com/u/Coco)\
**Post date:** [July 26, 2020, 8:02pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/17 "2020-07-26T20:02:26Z")

</div>

Hi @williangalvani

Just for kicks I tried sending the set\_attitude\_msg from an arduino on the latest version of Sub and still had the error where the horizon line and compass in QGC change every time the message is sent. Thoughts?

Is there any chance that the routing in my message is incorrect and that’s causing it to think that the message is coming from the IMU or something not a companion arduino?

---

<div class="post-metadata">

**Author:** ![williangalvani](https://avatars.discourse-cdn.com/v4/letter/w/6f9a4e/32.png) [@williangalvani](https://discuss.bluerobotics.com/u/williangalvani)\
**Post date:** [July 27, 2020, 2:38pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/18 "2020-07-27T14:38:11Z")

</div>

Does the rov respond at all? It does sound sound like you are are sending an [ATTITUDE](https://mavlink.io/en/messages/common.html#ATTITUDE) message to the GCS instead of a [SET\_ATTITUDE\_TARGET](https://mavlink.io/en/messages/common.html#SET_ATTITUDE_TARGET) message to the ROV

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [July 27, 2020, 4:08pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/19 "2020-07-27T16:08:08Z")

</div>

Hi,

Just a kind reminder that you’ll need to send `set_attitude_target` periodically in a shorter time interval than 5 seconds, otherwise the controller will use the joystick inputs again and forget about the attitude target message.

---

<div class="post-metadata">

**Author:** ![Coco](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Coco](https://discuss.bluerobotics.com/u/Coco)\
**Post date:** [August 1, 2020, 6:50pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/21 "2020-08-01T18:50:05Z")

</div>

@williangalvani @patrickelectric do either of you know if I could use the mavlink\_msg\_set\_roll\_pitch\_yaw\_thrust message to set a yaw target? If so can I just use 0 as a null value for the other values I don’t care to control?

I know set\_attitude\_target is what is recommended but it isn’t in the message list for the arduino library and manual control won’t stay on a target heading it only reacts to direct input.

---

<div class="post-metadata">

**Author:** ![williangalvani](https://avatars.discourse-cdn.com/v4/letter/w/6f9a4e/32.png) [@williangalvani](https://discuss.bluerobotics.com/u/williangalvani)\
**Post date:** [August 3, 2020, 2:25pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/22 "2020-08-03T14:25:40Z")

</div>

Hi @Coco,

> [@Coco](#):
>
> if I could use the mavlink\_msg\_set\_roll\_pitch\_yaw\_thrust message to set a yaw target?

That message doesn’t seem to be supported by Ardupilot at all.

> [@Coco](#):
>
> it isn’t in the message list for the arduino library

Being in the “common” dialect, set\_attitude\_target should be available for you with arduino. Any thoughts @patrickelectric?

---

<div class="post-metadata">

**Author:** ![patrickelectric](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/patrickelectric/32/2162_2.png) [@patrickelectric](https://discuss.bluerobotics.com/u/patrickelectric)\
**Post date:** [August 3, 2020, 4:40pm UTC](https://discuss.bluerobotics.com/t/desired-depth-and-heading-commands-in-a-manual-mode-e-g-depth-hold-mode/5640/23 "2020-08-03T16:40:51Z")

</div>

Hi @Coco,

Sorry if you are having problems with it, but is a bit weird, can you explain a minimal example and the error message ?  
You can try my arduino minimal example here: [GitHub - patrickelectric/minimal-arduino-mavlink-example: A simple and minimal MAVLink arduino example](https://github.com/patrickelectric/minimal-arduino-mavlink-example)

Remember to start and update the git submodule after cloning it.
