Pymavlink control both yaw and depth

Hi everyone,

I am trying to use pymavlink to control the yaw angle and depth of the bluerov with a desired value.

However, after reading the document of pymavlink, I designed the pid controllers to achieve the depth control and yaw control individually (It can achieve either depth control or yaw control).

When I am trying to achieve both the yaw control and the depth control , here comes a problem that the instant depth value and yaw value can not be obtained together.

The function I designed for the yaw_read and depth read are as follows.
I found out that sometimes either the yaw value or the depth value will be 1000, if the depth value a normal value, then the yaw value will be 1000, and vice versa, which indicates can the depth value and the yaw value cannot be obtained simultaneously.

Does anyone got any ideas how to deal with this situation? Is it related to the thread?

Thank you in advance!

def yaw_read():
    msg = master.recv_match()
    yaw_direction = 1000
    if msg:
        if msg.get_type() == 'ATTITUDE':
            yaw_direction = msg.yaw  
            # print('d=', dep)
    return yaw_direction`
def depth_read():
    msg = master.recv_match()
    dep = 1000
    if msg:
        if msg.get_type() == 'VFR_HUD':
            dep = msg.alt
            # print('depth_function=', dep)
    return dep

Hi @Neve,

You’re mixing message receiving and handling logic in your functions here, and it’s causing issues when a targeted handler function is receiving an irrelevant message. I would recommend having a read of this comment for a few different approaches to avoiding this kind of issue :slight_smile:

This thread is also worth a read for gaining an understanding of how MAVLink works, and how Pymavlink receives and processes messages.