%d is an integer format-specifier so it’s rounding whatever value it gets to the nearest integer. Your parameter is a float, so you want to use %f instead (or you can use e.g. %.3f if you want a float with three decimal places).
Even better, if you’re using Python 3 you can use f-strings, and if you’re using >= Python 3.8 you can use the equals formatting that can help make things a bit clearer:
By the way, where possible it’s preferred for code to be posted as code blocks, so it can be directly copied for testing. There are instructions for how to do that in the Formatting a Post/Comment section of the “How to Use the Blue Robotics Forums” pinned post
EDIT: More generally, those two examples could do with an update, so I’ve raised a github issue about that here:
I took your input and edited my code for reading out the parameters, as presented here:
import time
import sys
# Import mavutil
from pymavlink import mavutil
# Create the connection
master = mavutil.mavlink_connection('udpin:0.0.0.0:505')
master.wait_heartbeat() # Wait a heartbeat before sending commands or trying to send or recieve new data
print("Heartbeat from system (system %u component %u)" % (master.target_system, master.target_system))
# Wait a heartbeat before sending commands
master.wait_heartbeat()
# Request all parameters
master.mav.param_request_list_send(
master.target_system, master.target_component
)
while True:
time.sleep(0.01)
try:
message = master.recv_match(type='PARAM_VALUE', blocking=True).to_dict()
name, value = message['param_id'], message['param_value']
print('name: %s\tvalue: %.3f' % (message['param_id'], message['param_value']))
except Exception as error:
print(error)
sys.exit(0)
The read parameters from ArduSub made more sense. I couldn’t compile my code with the “python3” command. I followed the installation guide; GitHub - ArduPilot/pymavlink: python MAVLink interface and utilities My python version is 2.7.16 and python3 version is 3.9.7. It’s clear that Pymavlink assumes the command “python” is my path.
This is redundant - you extract the name and value into variables, and then extract them again instead of using the variables you just defined. You can either do just
Different versions of python don’t have access to the same libraries. If you want to use pymavlink with python3 and you’re not using a utility like python-is-python3 (mentioned in the installation guide) then you can install it using the python3 command instead of python (e.g. if you installed with