Deaph data problem

iḿ tring to write a controller in pymavlink for my bluerov (whit bar 30 sensor)but when i try to read the altitude it is always 0; this is the code that i use

# Disable "Broad exception" warning
# pylint: disable=W0703

import time
import sys

# Import mavutil
from pymavlink import mavutil

# Create the connection
master = mavutil.mavlink_connection('udpin:')
# Wait a heartbeat before sending commands

# Request all parameters
master.mav.param_request_list_send(master.target_system, master.target_component)

try:                                            # acquisizione profondita
    Z = master.messages['VFR_HUD'].alt
    print('altitude [m]:',Z)
    print('no time message received')

some one can help me pls? because idk if instead i should calculate the z by the zacc

Hi @fusari,

I’m not really sure what you’re trying to do with this program - you’re requesting all the parameters and then not trying to receive them, and then checking whether a specific message has been received that you haven’t requested.

If you’ve opened up a control station software (e.g. QGroundControl) before you run this Python program then most likely a VFR_HUD messages will be available, because control station softwares automatically request particular message rates. Even in that case, your code currently only works if a VFR_HUD message was received while waiting for the initial heartbeat to be detected from the vehicle, whereas it would make more sense to just wait for the message you want directly, instead of your current try-except approach:

msg = master.recv_match(type='VFR_HUD', blocking=True)
print('Depth [m]': -msg.alt)

Hi @EliotBR
i tried the code you suggest but even i “put it down” by 40cm the valie is still 0
if the sistem dont see the sensor i shouldn´t able to print it, right? (to know if there is a connection problem about the sensor)

p.s. if blocking parametr is false msg will be updated only if will receive the values right? i ask because i need to do a acquire date not blocking were if he can take the new valiue he will take it and do thing but if he don´t receive it still do the think whit the old valiue

When you connect to the vehicle with QGroundControl (instead of your program), does it show depth readings, or does it give warning about no external pressure sensor being connected? It’s best to first make sure (with a known working setup/program) that the hardware is behaving as expected, and then trying to change how it behaves with your own programs.

“Blocking” means the program stops at that point and just waits for the requested message (i.e. execution is blocked until some condition is met).

In this case if the message type is not being received then the code will just wait there indefinitely, unless you also set a value for the timeout parameter, in which case it will return None if the message you’re after does not arrive before the timeout occurs. If blocking is left as False (the default behaviour) then it’s like having a timeout of 0 - if the message is not available in the message buffer when it is requested then it will return None instead of a message object.

If you use timeouts / non-blocking behaviour then how you handle receiving None values is up to your code. It’s worth noting that there are some alternative message receiving / handling approaches discussed in this comment :slight_smile: