# Consecutive commands in depth hold mode

**URL:** <https://discuss.bluerobotics.com/t/consecutive-commands-in-depth-hold-mode/2257>\
**Category:** Blue Robotics Software\
**Created:** [March 3, 2018, 10:15am UTC](https://discuss.bluerobotics.com/t/consecutive-commands-in-depth-hold-mode/2257 "2018-03-03T10:15:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![vatsal\_shah](https://avatars.discourse-cdn.com/v4/letter/v/0ea827/32.png) [@vatsal\_shah](https://discuss.bluerobotics.com/u/vatsal_shah)\
**Post date:** [March 3, 2018, 10:15am UTC](https://discuss.bluerobotics.com/t/consecutive-commands-in-depth-hold-mode/2257/1 "2018-03-03T10:15:20Z")

</div>

We are using depth hold mode while testing using a wifi connection.

```auto
import time
from pymavlink import mavutil

mavutil.set_dialect("ardupilotmega")

autopilot = mavutil.mavlink_connection('/dev/ttyACM0')

msg = None

# wait for autopilot connection
while msg is None:
		msg = autopilot.recv_msg()

#print msg

# The values of these heartbeat fields is not really important here
# I just used the same numbers that QGC uses
# It is standard practice for any system communicating via mavlink emit the HEARTBEAT message at 1Hz! Your autopilot may not behave the way you want otherwise!
autopilot.mav.heartbeat_send(
6, # type
8, # autopilot
192, # base_mode
0, # custom_mode
4, # system_status
3 # mavlink_version
)

autopilot.mav.command_long_send(
1, # autopilot system id
1, # autopilot component id
400, # command id, ARM/DISARM
0, # confirmation
1, # arm!
0,0,0,0,0,0 # unused parameters for this command
)
print 'this is arm'

autopilot.mav.manual_control_send(1, 0, 0, -50, 0, 0)
print 'this is down'
time.sleep(2)

#autopilot.set_mode(2)
#print 'Alt HOld'
autopilot.mav.command_long_send(1,1,176,0,2,0,0,0,0,0,0)
print 'Alt HOld'

time.sleep(2)

autopilot.mav.command_long_send(
1, # autopilot system id
1, # autopilot component id
400, # command id, ARM/DISARM
0, # confirmation
0, # disarm!
0,0,0,0,0,0 # unused parameters for this command
)
print 'disarm'

#time.sleep(1)

autopilot.mav.command_long_send(
1, # autopilot system id
1, # autopilot component id
400, # command id, ARM/DISARM
0, # confirmation
1, # arm!
0,0,0,0,0,0 # unused parameters for this command
)
print 'this is arm 2'

t=8
while(t):
	autopilot.mav.manual_control_send(1, 2000, 0, 500, 0, 0)
	print 'this is forward'
	time.sleep(2)
	t=t-1

autopilot.mav.manual_control_send(1, 0, 1500, 500, 0, 0)
print 'sway'
	
autopilot.mav.command_long_send(
1, # autopilot system id
1, # autopilot component id
400, # command id, ARM/DISARM
0, # confirmation
0, # disarm!
0,0,0,0,0,0 # unused parameters for this command
)
print 'disarm'

```

the bot performs the depth hold mode and after giving a command the bot performs the command and gets disarmed  
We cannot use more than one command after going into depth hold.  
please revert as soon as possible

---

<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:** [March 3, 2018, 10:28am UTC](https://discuss.bluerobotics.com/t/consecutive-commands-in-depth-hold-mode/2257/2 "2018-03-03T10:28:47Z")

</div>

@vatsal_shah,

We have some examples of how to use pymavlink with the ROV, please, take a look [here](https://www.ardusub.com/developers/pymavlink.html).

About your code, you need to connect via UDP to mavproxy, take a look in our [software components](https://www.ardusub.com/software/components.html) to see how the mavlink communication is handle.

---

<div class="post-metadata">

**Author:** ![jwalser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/jwalser/32/2234_2.png) [@jwalser](https://discuss.bluerobotics.com/u/jwalser)\
**Post date:** [March 3, 2018, 4:32pm UTC](https://discuss.bluerobotics.com/t/consecutive-commands-in-depth-hold-mode/2257/3 "2018-03-03T16:32:35Z")

</div>

You need to send the HEARTBEAT message to the autopilot at 1Hz. This is a safety mechanism.

---

<div class="post-metadata">

**Author:** ![vatsal\_shah](https://avatars.discourse-cdn.com/v4/letter/v/0ea827/32.png) [@vatsal\_shah](https://discuss.bluerobotics.com/u/vatsal_shah)\
**Post date:** [March 3, 2018, 5:22pm UTC](https://discuss.bluerobotics.com/t/consecutive-commands-in-depth-hold-mode/2257/4 "2018-03-03T17:22:08Z")

</div>

How do we send the heartbeat continuously at 1Hz through python script? so at the end, the above code works as intended.

Please help. It’s urgent.

---

<div class="post-metadata">

**Author:** ![jwalser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/jwalser/32/2234_2.png) [@jwalser](https://discuss.bluerobotics.com/u/jwalser)\
**Post date:** [March 3, 2018, 5:32pm UTC](https://discuss.bluerobotics.com/t/consecutive-commands-in-depth-hold-mode/2257/5 "2018-03-03T17:32:12Z")

</div>

```auto
while(True):
    send_heartbeat():
    time.sleep(1)

```

Or if you want to do other things:

```auto
lastHeartbeat_t = 0
while(True)
    t = time.time()
    if (t > lastHeartbeat_t + 1):
        send_heartbeat
        lastHeartbeat_t = t

    ...do other things...

```

---

<div class="post-metadata">

**Author:** ![vatsal\_shah](https://avatars.discourse-cdn.com/v4/letter/v/0ea827/32.png) [@vatsal\_shah](https://discuss.bluerobotics.com/u/vatsal_shah)\
**Post date:** [March 3, 2018, 5:46pm UTC](https://discuss.bluerobotics.com/t/consecutive-commands-in-depth-hold-mode/2257/6 "2018-03-03T17:46:17Z")

</div>

Thanks a lot.

And one more thing.

using the below python script,

connection.mav.manual\_control\_send(1,1000,0,0,0,0,0) #forward 1000

how to run only the front motors? We do not want the back thrusters to rotate.

---

<div class="post-metadata">

**Author:** ![jwalser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/jwalser/32/2234_2.png) [@jwalser](https://discuss.bluerobotics.com/u/jwalser)\
**Post date:** [March 3, 2018, 5:51pm UTC](https://discuss.bluerobotics.com/t/consecutive-commands-in-depth-hold-mode/2257/7 "2018-03-03T17:51:51Z")

</div>

This is not possible, why do you want to do this?

---

<div class="post-metadata">

**Author:** ![vatsal\_shah](https://avatars.discourse-cdn.com/v4/letter/v/0ea827/32.png) [@vatsal\_shah](https://discuss.bluerobotics.com/u/vatsal_shah)\
**Post date:** [March 3, 2018, 6:00pm UTC](https://discuss.bluerobotics.com/t/consecutive-commands-in-depth-hold-mode/2257/8 "2018-03-03T18:00:51Z")

</div>

Because one of our rear thruster’s has issues. It does not rotate at the same speed as others. And so the bot travels in a curved trajectory. And we do not have time to get the replacement. So please help.

---

<div class="post-metadata">

**Author:** ![jwalser](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/jwalser/32/2234_2.png) [@jwalser](https://discuss.bluerobotics.com/u/jwalser)\
**Post date:** [March 3, 2018, 6:07pm UTC](https://discuss.bluerobotics.com/t/consecutive-commands-in-depth-hold-mode/2257/9 "2018-03-03T18:07:40Z")

</div>

Unplug the two motors that you do not want to spin.
