Read MAVLink messages into lua

image
image

I have data being set from an engine that i can view with mavlink inspector, I would like to take actions based on this data, could anyone link me to example code or provide some example code to for example, beep when cylinder head temperature goes above 50?

Thanks

1 Like

If you want to do that on the GCS take a look at adding a mavproxy plugin.

If you want to build your own GCS take a look at pymavlink examples

I do not see the advantage of beeping on the vehicle using lua. If the vehicle is far away you will not listen to the beep

neither, I want to run action on the pixhawk cube based on the telemetry from the engine.

https://ardupilot.org/copter/docs/common-lua-scripts.html

and examples: ardupilot/libraries/AP_Scripting/examples at master · ArduPilot/ardupilot · GitHub

i appreciate your links but these dont meet my needs.

the example CAN code doesnt even work for instance

Open a github issue then.

I want to read mavlink messages onboard the aircraft with onboard lua… not hunt can issues

What you need are Lua bindings to access those values. To my knowledge they do not yet exist, but the instructions for adding a binding are in the link provided above.

Hi, do you find solution for your problem ? I’m working on something similar and I stuck in same place :slight_smile:

What exactly is unclear in the instructions on how to add lua bindings?

I want to creat LUA’s script which allows me to overwrite pwm after failsafe. I’m looking for way where i can find information how can i read messages from pixhawk or read mavlink, or something else which can help me to figure it out :slight_smile:

Failsafe is a trigger for my script

Then create lua bindings to read the failsafe state.

You keep repeating this in multiple threads (which is a good way to get negative attention), but your question isn’t detailed enough to provide valuable help.

Describe your exact intent. Under what conditions does the firmware fail to provide adequate failsafe actions?

What failsafe condition are you trying to detect?

What override is necessary (and why)?

did you find a solution to this? i’m in the same boat

I’ll ask you the same question: what failsafe? And what use case? With some more detailed information, we can set you on a path to success (or confirm lack of feature availability).

hi yuri thanks for the quick response! enjoyed watching some of your videos on lua scripting earlier.

my goal is to build a proof of concept search & rescue drone that flies around and when its companion computer’s camera spots a person, it flies to them and drops a rescue payload nearby, and reports their location.

so the approach i was considering was for the raspberry pi to send a message to a lua script with information on the discovered person’s location, and then the lua script would take over.

i got as far as updating my ardupilot to 4.5 in order to run what looks like examples of lua listening for mavlink messages, but i kept getting this error:

module 'MAVLink/mavlink_msgs' not found

and now after doing a deeper dive into the mavlink docs i’m wondering if the right way to do this is actually for the companion computer to basically take over, sending mavlink commands like MAV_CMD_PAYLOAD_PREPARE_DEPLOY

but “MAV_CMD_PAYLOAD_PREPARE_DEPLOY and MAV_CMD_PAYLOAD_CONTROL_DEPLOY are not supported on any known flight stack. They are deprecated and should not be used.”

so i’m still generally at a loss on how best to proceed from here. any thoughts or guidance are welcome

Seems a simple serial protocol might be best in your use case. Just set up a serial port for scripting on the autopilot and use a UART on the Pi to send whatever data you want.

If you don’t have a UART to spare, even I2C comms could be established.

As for MavLink within Lua, I’ll admit that’s a weak spot in my own knowledge, as I’ve always found ways to avoid using direct MavLink comms in my scripts, and it always seems backwards to use it within scripting, which typically exposes a layer beneath MavLink messaging for more efficient feature management.

do you have any references or guides you could point me towards for doing this?

Reads bytes to a file. You could skip the file I/O and do whatever logic is required based on bytes received.

1 Like