BlueROV2 Heading value does not update

Hello, I have written a very simple script to print out the current heading every second. The issue is when I call the function in MAVProxy command line, it prints the same value each iteration. Please take a look at my code as seen in the attached image, and let me know why it is not working.

The code in cmd_Heading is blocking. No other code in mavproxy will run while you are in this loop, so no mavlink packets are parsed during this time and the value never updates.

Try just printing the heading in mavlink_packet every time you assign it.

My goal is to print the current heading every second until the ROV reaches a target heading, given by an amount to turn.
For example if my current heading is 90 degrees and I want to turn 90 degrees and print the current heading every second until it reaches 180 degrees, how can I go about this? Since it seems to block the MAVlink packets from being parsed.

Please, remove time.sleep, loops or any other function that is expensive.
Doing such thing freezes the code.

You should write your own program that runs seprately (and in a different thread) from mavproxy. Instead of making a mavproxy module, make a script that reads the mavlink stream. Use mavproxy to send the mavlink stream to your script via udp.

Another option is to use the idle_task hook for your module, this will be called whenever there is free time. Then you can just check if one second has passed before you print. (Look for blink without delay example for arduino for an idea of how to write non blocking code).

Hi Jacob, do you have any resources I can use to learn how to use mavproxy to send the mavlink stream to my script via UDP? I am unfamiliar with this, thanks.

Hi wahhaj,

You can check the official python documentation here: UdpCommunication - Python Wiki

Check the mavproxy option --out

You may use it to send to a local process by --out=udpout: (udp port 5555).