I have a customized sensor that sends data containing voltage, current, temperature and rpm. I want my flight controller to use voltage and current as Battery Monitor.
Also I want to see temperature and rpm data in GCS.
We have companion computer that has a Mavlink connection to my flight controller.
Is there any way to do this using LUA scripting (or using Mavlink)?
I managed to do this by mixing Mavlink and LUA scripting.
I first receive data from my sensor in my companion computer and then send it using the Mavlink message “BATTERY_STATUS”. Then, in flight control, I receive this message using LUA scripting with the “receive_chan” method of “mavlink” and update the flight control’s battery data using the “update_telem_data” and “update_rpm” methods of “esc_telem” with received values.
can you share your script?
Which one of the scripts do you need?
Mavlink or LUA?
The just the Lua script, I can send the battery message from my esp32 I just can’t do anything with them.
local mavlink_msgs = require("mavlink/mavlink_msgs")
local msg_map = {}
local battery_status_msgid = mavlink_msgs.get_msgid("BATTERY_STATUS")
msg_map[battery_status_msgid] = "BATTERY_STATUS"
-- initialise mavlink rx with number of messages, and buffer depth
mavlink.init(1, 10)
-- register message id to receive
mavlink.register_rx_msgid(battery_status_msgid)
function update()
local telem_data = ESCTelemetryData()
local msg,_,timestamp_ms = mavlink.receive_chan()
if msg then
local parsed_msg = mavlink_msgs.decode(msg, msg_map)
if(parsed_msg.msgid ~= nil and parsed_msg.msgid == battery_status_msgid) then
telem_data:voltage((parsed_msg.voltages[0] or parsed_msg.voltages[1]) / 100)
telem_data:temperature_cdeg(parsed_msg.temperature)
telem_data:current(parsed_msg.current_consumed / 1000)
esc_telem:update_telem_data(1, telem_data, 0x0D)
end
end
return update, 1000
end
return update, 1000
This is the LUA script to do that.
How do you set up the flight controller to use it?? Do I need to change batt settings?
As I remember I just set BATT_MONITOR. Did you test that without setting any more specific parameters?
What did you set the batt monitor to? What kind of sensor.
If I’m right I set BATTx_MONITOR = 9(ESC)