# Guided mode with pymavlink

**URL:** <https://discuss.bluerobotics.com/t/guided-mode-with-pymavlink/21516>\
**Category:** ArduSub\
**Tags:** pymavlink, dvl\
**Created:** [September 3, 2025, 4:55pm UTC](https://discuss.bluerobotics.com/t/guided-mode-with-pymavlink/21516 "2025-09-03T16:55:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Herman](https://avatars.discourse-cdn.com/v4/letter/h/eada6e/32.png) [@Herman](https://discuss.bluerobotics.com/u/Herman)\
**Post date:** [September 3, 2025, 4:55pm UTC](https://discuss.bluerobotics.com/t/guided-mode-with-pymavlink/21516/1 "2025-09-03T16:55:19Z")

</div>

Hi!

We have a BlueROV2 with a Nortek Nucleus 1000 DVL and are running ArduSub v4.5.3 and BlueOS v1.4.2. We are aiming to use pymavlink to reach goal positions in guided mode. The set control parameters are set following [Norteks guide](https://github.com/NortekSupport/nucleus_driver/tree/main/blueos_extension). We are able to set the ROV to guided mode. However, we are not able to get the ROV to react to the `set_position_target_local_ned` and `set_attitude_target` messages we are sending. In manual/stabilize/alt\_hold mode, however, we are able to control the ROV with RC channels override messages.

Perhaps someone can shed a light on what we are doing wrong?

Code excerpts:

```python

# Called regularly
def goal_callback(self, msg):
    self.master.mav.set_position_target_local_ned_send(
        int(1e3 * (time.time() - self.boot_time)),
        self.master.target_system, self.master.target_component,
        mavutil.mavlink.MAV_FRAME_LOCAL_NED,
        mavutil.mavlink.POSITION_TARGET_TYPEMASK_VX_IGNORE |
        mavutil.mavlink.POSITION_TARGET_TYPEMASK_VY_IGNORE |
        mavutil.mavlink.POSITION_TARGET_TYPEMASK_VZ_IGNORE |
        mavutil.mavlink.POSITION_TARGET_TYPEMASK_AX_IGNORE |
        mavutil.mavlink.POSITION_TARGET_TYPEMASK_AY_IGNORE |
        mavutil.mavlink.POSITION_TARGET_TYPEMASK_AZ_IGNORE |
        mavutil.mavlink.POSITION_TARGET_TYPEMASK_YAW_IGNORE |
        mavutil.mavlink.POSITION_TARGET_TYPEMASK_YAW_RATE_IGNORE,
        msg.pose.position.x, msg.pose.position.y, msg.pose.position.z,
        0, 0, 0, # vx, vy, vz
        0, 0, 0, # ax, ay, az
        0, 0 # yaw, yaw_rate
    )

    self.master.mav.set_attitude_target_send(
        int(1e3 * (time.time() - self.boot_time)),
        self.master.target_system, self.master.target_component,
        mavutil.mavlink.ATTITUDE_TARGET_TYPEMASK_THROTTLE_IGNORE,
        [msg.pose.orientation.w, msg.pose.orientation.x, msg.pose.orientation.y, msg.pose.orientation.z], 
        0, 0, 0, 0 # roll rate, pitch rate, yaw rate, thrust
    )

# Also sending RC channels override at 10 Hz
def send_rc_channels(self):
    if self.mode == "GUIDED":
        rc_channels = [65535 for _ in range(18)] # Ignore all channels
        self.master.mav.rc_channels_override_send(
            self.master.target_system, self.master.target_component,
            *rc_channels
        )
    else: 
        # Other logic implemented for other modes

```

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [September 5, 2025, 3:32am UTC](https://discuss.bluerobotics.com/t/guided-mode-with-pymavlink/21516/2 "2025-09-05T03:32:22Z")

</div>

Hi @Herman,

A couple of questions:

1. Does guided mode work as expected when not using programmatic control?
2. Assuming you don’t have a GNSS system integrated as well, are you [setting the GNSS origin](https://github.com/NortekSupport/nucleus_driver/tree/main/blueos_extension#gnss-origin-and-map:~:text=the%20user%20must%20send%20a%20SET_GPS_GLOBAL_ORIGIN%20command%20to%20the%20ROV%20through%20MavLink%20in%20order%20to%20provide%20the%20ROV%20with%20an%20initial%20condition%20before%20they%20can%20use%20the%20AUTO%20and%20GUIDED%20modes) before trying to use guided mode?

---

<div class="post-metadata">

**Author:** ![Herman](https://avatars.discourse-cdn.com/v4/letter/h/eada6e/32.png) [@Herman](https://discuss.bluerobotics.com/u/Herman)\
**Post date:** [September 5, 2025, 8:44am UTC](https://discuss.bluerobotics.com/t/guided-mode-with-pymavlink/21516/3 "2025-09-05T08:44:56Z")

</div>

We found the culprit. We were not sending `set_position_target_local_ned` fast enough. By streaming at a higher rate (25 Hz in our case), the ROV responded as intended.

We also dropped sending rc\_channels during guided mode, as we suspected that this might interfere. This, however, caused the ROV to quickly disarm even if we were streaming `set_position_target_local_ned` at 25 Hz. We then resorted to disabling `FS_PILOT_TIMEOUT`during guided mode. Though probably not the best solution, this solved our problem for now.

We have not yet tested guided mode with QGC, but aim to do this. Yes, we are setting the GNSS origin.

---

<div class="post-metadata">

**Author:** ![Flatline](https://avatars.discourse-cdn.com/v4/letter/f/b9bd4f/32.png) [@Flatline](https://discuss.bluerobotics.com/u/Flatline)\
**Post date:** [January 7, 2026, 3:48pm UTC](https://discuss.bluerobotics.com/t/guided-mode-with-pymavlink/21516/4 "2026-01-07T15:48:32Z")

</div>

Hi, we are trying to achieve the same goal where we wanted to control the rov with dvl with python code using pymavlink. We were able to change modes to guided and pos\_hold in blueos cockpit. but we werent able to do it with pymavlink. for achieving guided or pos\_hold do we need to inject dvl’s positional data through pymavlink simultenously? if so how can we do that?

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [January 7, 2026, 9:15pm UTC](https://discuss.bluerobotics.com/t/guided-mode-with-pymavlink/21516/5 "2026-01-07T21:15:24Z")

</div>

Hi @Flatline, welcome to the forum 🙂

> [@Flatline](#):
>
> for achieving guided or pos\_hold do we need to inject dvl’s positional data through pymavlink simultenously?

Cockpit doesn’t do this, so if it can enable position holding then you should be able to with Pymavlink as well, as long as you’re setting the origin (as discussed above), and either sending regular [heartbeats](https://mavlink.io/en/messages/common.html#HEARTBEAT) and pilot inputs (via [`MANUAL_CONTROL`](https://mavlink.io/en/messages/common.html#MANUAL_CONTROL) or [`RC_CHANNELS_OVERRIDE`](https://mavlink.io/en/messages/common.html#RC_CHANNELS_OVERRIDE) messages), or have disabled the [both](https://ardupilot.org/sub/docs/gcs-failsafe.html) relevant [failsafes](https://ardupilot.org/sub/docs/pilot-control-failsafe.html).

What kind of behaviour are you experiencing, and are you receiving any error messages? It may help if you can share the code you’re running and your current parameters.

---

<div class="post-metadata">

**Author:** ![Flatline](https://avatars.discourse-cdn.com/v4/letter/f/b9bd4f/32.png) [@Flatline](https://discuss.bluerobotics.com/u/Flatline)\
**Post date:** [January 28, 2026, 3:51pm UTC](https://discuss.bluerobotics.com/t/guided-mode-with-pymavlink/21516/7 "2026-01-28T15:51:50Z")

</div>

Hi, we were able to change mode to guided and position hold with pymavlink but when we tried to setpoint in the code for example, go to 1m in x axis(in guided mode) it starts to behave abruptly going diagonally without stopping. we had to kill the power to turn the thrusters off.  
Here’s the snippet of our code:

```py
def set_positional_target_distance(position):
    master.mav.set_position_target_local_ned_send(
        int(1e3 * (time.time() - boot_time)),
        master.target_system, master.target_component,
        mavutil.mavlink.MAV_FRAME_LOCAL_NED,
        mavutil.mavlink.POSITION_TARGET_TYPEMASK_VX_IGNORE |
        mavutil.mavlink.POSITION_TARGET_TYPEMASK_VY_IGNORE |
        mavutil.mavlink.POSITION_TARGET_TYPEMASK_VZ_IGNORE |
        mavutil.mavlink.POSITION_TARGET_TYPEMASK_AX_IGNORE |
        mavutil.mavlink.POSITION_TARGET_TYPEMASK_AY_IGNORE |
        mavutil.mavlink.POSITION_TARGET_TYPEMASK_AZ_IGNORE |
        mavutil.mavlink.POSITION_TARGET_TYPEMASK_YAW_IGNORE |
        mavutil.mavlink.POSITION_TARGET_TYPEMASK_YAW_RATE_IGNORE,
        position[0], position[1],position[2],
        0, 0, 0, # vx, vy, vz
        0, 0, 0, # ax, ay, az
        0, 0 # yaw, yaw_rate
    )
def main():
    arm_vehicle()

    # set_custom_mode('POSHOLD')
    guided_mode()

    stop()
    set_positional_target_distance([1,0,0])
    stop()
    disarm()

```

---

<div class="post-metadata">

**Author:** ![EliotBR](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.bluerobotics.com/eliotbr/32/6937_2.png) [@EliotBR](https://discuss.bluerobotics.com/u/EliotBR)\
**Post date:** [January 28, 2026, 7:32pm UTC](https://discuss.bluerobotics.com/t/guided-mode-with-pymavlink/21516/8 "2026-01-28T19:32:33Z")

</div>

> [@Flatline](#):
>
> … we were able to change mode to guided and position hold with pymavlink …

Nice!

> [@Flatline](#):
>
> … going diagonally …

Which way was the vehicle facing? If you’re using a North-East-Down (NED) frame then the X direction is North, which could be diagonally depending on your current vehicle heading. If you want X to be forwards (using the vehicle’s attitude) then you’ll need to use a Forward-Right-Down (FRD) frame (e.g. [`MAV_FRAME_BODY_FRD`](https://mavlink.io/en/messages/common.html#MAV_FRAME_BODY_FRD)).

> [@Flatline](#):
>
> … without stopping …

Your shared code doesn’t make it clear how it’s trying to stop the vehicle - what does your `stop` function do? If it’s immediate then the vehicle should barely move at all, because it should get the disarm command very soon after entering guided mode.

To confirm, have you managed to _control_ the ROV in guided mode with Cockpit, or just enter the mode?
