Home        Store        Docs        Blog

Pymavlink read and write parameters code example


(Tim) #1

When I run the “Read and Write Parameters” pymavlink script example provided on the Ardusub site (https://www.ardusub.com/developers/pymavlink.html), I receive a heartbeat but then the code hangs at this point in the script and does not print:

# Print old parameter value
message = master.recv_match(type='PARAM_VALUE', blocking=True).to_dict()
print('name: %s\tvalue: %d' % (message['param_id'].decode("utf-8"), message['param_value']))

I am running the script on a topside computer. Any help much appreciated.

Note that the “Receive data and filter by message type” script does work. I am able to receive data.

Thanks, Tim


(Jacob) #2

Hi Tim, we’ve been busy!

Are you still having trouble here?

ping @patrickelectric


(TMJ) #3

Hey Jacob np. Yes still have this issue. Ultimately we would like to modify this script to change the rate at which we receive depth data using the SRn_RAW_SENS parameter.


(Patrick José Pereira) #4

Hi,

Did you change something in the example script ?
Can you run and share the output ok Read all parameters example ?
If you are having delay problems, try to increase the time in sleep functions.


(TMJ) #5

Hi Patrick, we have not modified the script. We are using the “Read and Write Parameters” script. The script hangs at this line and does not return a message:

# Print old parameter value
message = master.recv_match(type='PARAM_VALUE', blocking=True).to_dict()

(Patrick José Pereira) #6

This happens in both examples ? Or just in Read and Write ? Did you increase the delay ?


(Jacob) #7

What version of ArduSub and pymavlink are you using?


(TMJ) #8

Ardusub 3.5.2
pymavlink 2.2.8
We are able to reproduce the problem on two separate pi + pixhawk setups.


(Tim) #9

Ultimately we’d like to modify this code to change the SRn_RAW_SENS parameter to 10 Hz so that we can obtain a faster depth reading. Any help on this is appreciated. Once again the provided example “Read and Write Parameters” script here (https://www.ardusub.com/developers/pymavlink.html) hangs at this line:

Print old parameter value

message = master.recv_match(type=‘PARAM_VALUE’, blocking=True).to_dict()


(Patrick José Pereira) #10

Please, answer the previous questions for further help:



(Tim) #11

Did you change something in the example script ?
No

Can you run and share the output ok Read all parameters example ?
Output:
<pymavlink.dialects.v10.ardupilotmega.MAVLink_heartbeat_message at 0x7f7925a050>
and then I receive a blinking cursor in the terminal indefinitely.

If you are having delay problems, try to increase the time in sleep functions.
There’s no delay problem. The script simply hangs.

This happens in both examples ? Or just in Read and Write ? Did you increase the delay ?
Yes, this happens in both scripts. Changing delay does not help.

Are you able to run this script on your pi+pixhawk setup? This problem occurs on both of our separate pi+pixhawk setups
Thanks for the help!


(Patrick José Pereira) #12

Hi Tim,

Thank you for the reply.

That is weird…, both scripts does not print the pymavlink message, but a simple string, you can check that read all parameters and read and write parameter scripts contains the follow print functions:

# read all parameters
print('name: %s\tvalue: %d' % (message['param_id'].decode("utf-8"), message['param_value']))

# read and write parameter
print('name: %s\tvalue: %d' % (message['param_id'].decode("utf-8"), message['param_value']))
#...
print('name: %s\tvalue: %d' % (message['param_id'].decode("utf-8"), message['param_value']))
#...
print('name: %s\tvalue: %d' % (message['param_id'].decode("utf-8"), message['param_value']))

You can see in this simple record that both scripts are working fine in a fresh companion image:

asciicast

Try to update your pymavlink library with sudo pip install --upgrade pymavlink or a fresh install of the companion image.
Besides that, I can run both scripts fine with Python 3.7.0 with pymavlink 2.2.10 and 2.2.20. Python 2.7.9 with pymavlink 2.2.4 and 2.2.20.


(Tim) #13

Thanks Patrick, I will try this!