Hello everyone,
I’m facing two challenges related to Named Float values in my ArduPilot setup:
1. Issue with Mission Planner:
- I successfully set a Named Float value using pymavlink.
- I can observe the Named Float variable (e.g., “my_named_value”) in the Mission Planner’s Quick View Tab.
- However, the value associated with the variable always remains 0.
- Using Mavlink Inspector, I’ve confirmed that Mission Planner is indeed sending the Named Float message to the Autopilot.
- I’m puzzled as to why the value isn’t correctly displayed in the Quick tab.
- Reading Named Float Values in Lua:
I’m encountering an issue while trying to read Named Float values in my ArduPilot Lua script.
- I’ve written a Lua script to listen for Named Float messages.
- The script appears to be running without errors, but it doesn’t seem to be receiving any Named Float messages from Mission Planner.
- I’ve verified this by using
gcs:send_text(0, " **** ")
that theif msg then
block in my script is not being executed. - I used
gcs:send_text(0, " **** ")
to confirm that the script isn’t receiving messages. - Additionally, I verified that the
NAMED_VALUE_FLOAT_msgid
is correctly defined as 251 within my script.
Can you help please.
Lua script:
function mavlink_receiver()
local mavlink_msgs = require("mavlink_msgs")
local NAMED_VALUE_FLOAT_msgid = mavlink_msgs.get_msgid("NAMED_VALUE_FLOAT")
local msg_map = {}
msg_map[NAMED_VALUE_FLOAT_msgid] = "NAMED_VALUE_FLOAT"
-- initialise mavlink rx with number of messages, and buffer depth
mavlink.init(1, 10)
-- register message id to receive
mavlink.register_rx_msgid(NAMED_VALUE_FLOAT_msgid)
local msg,_,timestamp_ms = mavlink.receive_chan()
if msg then
local parsed_msg = mavlink_msgs.decode(msg, msg_map)
if (parsed_msg ~= nil) and (parsed_msg.msgid == NAMED_VALUE_FLOAT_msgid) then
-- convert remote timestamp to local timestamp with jitter correction
--local time_boot_ms = jitter_correction.correct_offboard_timestamp_msec(parsed_msg.time_boot_ms, timestamp_ms:toint())
local value = parsed_msg.value
local name = bytes_to_string(parsed_msg.name)
gcs:send_text(0, "Got mode change .... " .. value)
end
end
return mavlink_receiver, 1000
end
return mavlink_receiver()
The python code:
from pymavlink import mavutil
import time
mavlink_connection_string = "udpout:127.0.0.2:14550" #"tcp:192.168.43.1:5760" #
mav = mavutil.mavlink_connection(mavlink_connection_string)
def send_named_value_float(mav_, name, value):
# Get the time_boot_ms as the time difference since the first heartbeat received
time_boot_ms = int((time.time() - mav_.start_time) * 1000)
# Ensure the name is exactly 10 bytes long
encoded_name = name.encode('ascii').ljust(10, b'\0')
mav_.mav.named_value_float_send(time_boot_ms, encoded_name, value)
def main():
try:
while (1):
# Send the NAMED_VALUE_FLOAT message
send_named_value_float(mav, 'ty1 980', 5)
time.sleep(0.1)
send_named_value_float(mav, 'Battery1 voltage', 4)
time.sleep(0.1)
send_named_value_float(mav, 'lol voltage', 6)
print("send ")
time.sleep(0.2) # Wait for 0.5 seconds before sending the next message
except KeyboardInterrupt:
# Handle any cleanup or resource releasing if necessary
print("Interrupted by user, stopping message sending.")
main()
The Mavlink inspector:
Quick view tab - Mission planner: