Home        Store        Docs        Blog

BlueROV2 Heading value does not update


(Wahhaj Z) #1

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.
Thanks.


(Jacob) #2

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.


(Jacob) #3

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


(Wahhaj Z) #4

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.
Thanks.


(Patrick José Pereira) #5

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


(Jacob) #6

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).


(Wahhaj Z) #7

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.


(Patrick José Pereira) #8

Hi wahhaj,

You can check the official python documentation here: https://wiki.python.org/moin/UdpCommunication


(Jacob) #9

Check the mavproxy option --out

You may use it to send to a local process by --out=udpout:0.0.0.0:5555 (udp port 5555).
http://ardupilot.github.io/MAVProxy/html/getting_started/starting.html