Quantcast
Channel: ArduPilot Discourse - Latest topics
Viewing all articles
Browse latest Browse all 46629

LUA - read named float mavlink msg failed

$
0
0

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 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.
  1. 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 the if 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.

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()```

2 posts - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 46629

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>