<p>After digging deeper on the Ardupilot website, I've found that besides MAVLink, it now supports onboard Lua scripts with full control of the aircraft that can be loaded to the flight controller's SD card. </p>

<p>The functionality is experimental as of now, and has been available in Copter/Rover since version 4.0 and Plane since v3.11. Further information can be found <a href="https://ardupilot.org/copter/docs/common-lua-scripts.html" rel="nofollow noreferrer">on the project's website.</a></p>

CC BY-SA 4.0
2020-04-29T16:36:55.180Z
2020-04-29T16:36:55.180Z
FlashCactus
<p>I think your best bet would be <a href="https://ardupilot.org/" rel="nofollow noreferrer">Ardupilot</a>. The communication protocol it uses, called MavLink, is documented and easy to use. Connect to the UART with an Arduino and you will have full control over the UAV.</p>

<p>There is even an Arduino library and a bunch of examples, <a href="https://discuss.ardupilot.org/t/mavlink-and-arduino-step-by-step/25566" rel="nofollow noreferrer">like this forum post</a>, of people doing exactly what you are looking to do. I did this once because I needed to grab the GPS and Compass information for a work project. You can research the various mission control programs that use MavLink to see the extent of control the protocol has. If I remember correctly you can even send direct stick commands over that interface to manually pilot the craft. This solution makes for lots of flexibility, especially when you consider the huge community writing Arduino libraries. It would be simple to add just about any sensor you could want.</p>

CC BY-SA 4.0
2020-04-23T20:05:18.193Z
That sounds quite reassuring! I always thought mavlink was just a groundstation protocol, and I couldn't see any "custom/outboard/etc" modes on the list so I assumed Ardupilot didn't have these features available. I'll definitely give it a look, thanks!
FlashCactus
CC BY-SA 4.0
2020-04-23T15:38:33.667Z
2020-04-23T16:10:47.543Z
2020-04-23T16:10:47.543Z
ipaq3115
<p><a href="https://px4.io/" rel="nofollow noreferrer">PX4</a> looks like it is quite flexible, and might be what you are looking for. It might not be as user friendly as for example iNAV, but it should give you much more possibilities even if that comes at the cost of having to write more code.</p>

CC BY-SA 4.0
2020-04-21T15:32:32.570Z
2020-04-21T15:32:32.570Z
Hannes Hultergård
<p>You could consider looking for research autopilots. Researchers try new things in all levels of the autopilot, and so they need extensibility and performance more than advanced features.</p>

<p>From what I understand Ardupilot and PX4 are popular. My university uses <a href="https://rosflight.org" rel="nofollow noreferrer">ROSflight</a>, which is nice because it interfaces with Robot Operating System, which allows for sensor and control data to get around relatively easily. Depending on the type of UAV you're using, you would run <a href="https://github.com/byu-magicc/rosplane" rel="nofollow noreferrer">ROSplane</a> or <a href="https://github.com/byu-magicc/roscopter" rel="nofollow noreferrer">ROScopter</a> on top of it to provide higher level functions. It is all highly extensible, and you can replace any of the layers of the autopilot independently. Also nice, it has a pretty good simulator so that you can try fancy stuff without crashing a real UAV. Do note that it lacks some of the higher-level features provided by other autopilots, and so you'll have to look at what you want to do to decide.</p>

CC BY-SA 4.0
2020-04-29T16:50:11.197Z
2020-04-29T16:50:11.197Z
BillThePlatypus
<p>You can program/script elaborate flight patterns and then translate it to MAVLink format mission messages either live or in pre-recorded mission mode. Then depending on your needs - you either upload your mission or send it live over telemetry connection.</p>

CC BY-SA 4.0
2020-04-23T13:45:52.393Z
2020-04-23T13:45:52.393Z
jpou
<p>Most freely available autopilot-enabled flight control hardware and firmware for hobby/consumer-grade UAVs seem to have a rather fixed feature set. There are usually varying degrees of stabilization, position hold/loiter modes, automatic takeoff and landing, return to home and a waypoint-following "mission" mode, but little beyond that. There are sometimes specialized modes such as thermal soaring and terrain following. However, all of these are pre-programmed and non-extendable, by which I mean that there is no way (at least I could find none) for a user to program their own custom flight logic, e.g. via scripting. I may have missed this, though.</p>

<p>So, <strong>Is there, in any of the autopilot solutions currently available to hobbyists, a way for a user to define their own flight logic without rewriting the autopilot software itself, by instead building on top of existing software?</strong></p>

<p>To be clear, I'm looking for a way to write logic <em>outside</em> of the main flight control/autopilot package, either via some kind of scripting engine native to the autopilot or as a program running on a device parallel to the autopilot that can communicate to it and get the necessary flight information/send commands.</p>

CC BY-SA 4.0
2020-04-23T14:06:19.790Z
Tau Labs supports picoC and full flight scripting. It is very stable and the feature set is robust, but it's a bit abandonware at this point so you'd be on your own for support.
Kenn Sebesta
<flight-controller><software><firmware><autopilot><autonomous>
What are the available solutions for creating complex user-defined UAV behavior in autopilots?
FlashCactus
# What are the available solutions for creating complex user-defined UAV behavior in autopilots?

(Asked by: username_0 on 2020-04-21)

Most freely available autopilot-enabled flight control hardware and firmware for hobby/consumer-grade UAVs seem to have a rather fixed feature set. There are usually varying degrees of stabilization, position hold/loiter modes, automatic takeoff and landing, return to home and a waypoint-following "mission" mode, but little beyond that. There are sometimes specialized modes such as thermal soaring and terrain following. However, all of these are pre-programmed and non-extendable, by which I mean that there is no way (at least I could find none) for a user to program their own custom flight logic, e.g. via scripting. I may have missed this, though.

So, **Is there, in any of the autopilot solutions currently available to hobbyists, a way for a user to define their own flight logic without rewriting the autopilot software itself, by instead building on top of existing software?**

To be clear, I'm looking for a way to write logic *outside* of the main flight control/autopilot package, either via some kind of scripting engine native to the autopilot or as a program running on a device parallel to the autopilot that can communicate to it and get the necessary flight information/send commands.

**Tags:** flight-controller, software, firmware, autopilot, autonomous
> **Comments:**
> **username_1**: Tau Labs supports picoC and full flight scripting. It is very stable and the feature set is robust, but it's a bit abandonware at this point so you'd be on your own for support.  

---

## 5 answers

### Answer by username_0 on 2020-04-29. Score: 0 | Accepted answer

After digging deeper on the Ardupilot website, I've found that besides MAVLink, it now supports onboard Lua scripts with full control of the aircraft that can be loaded to the flight controller's SD card.

The functionality is experimental as of now, and has been available in Copter/Rover since version 4.0 and Plane since v3.11. Further information can be found [on the project's website.](https://ardupilot.org/copter/docs/common-lua-scripts.html)


---

### Answer by username_2 on 2020-04-23. Score: 3

I think your best bet would be [Ardupilot](https://ardupilot.org/). The communication protocol it uses, called MavLink, is documented and easy to use. Connect to the UART with an Arduino and you will have full control over the UAV.

There is even an Arduino library and a bunch of examples, [like this forum post](https://discuss.ardupilot.org/t/mavlink-and-arduino-step-by-step/25566), of people doing exactly what you are looking to do. I did this once because I needed to grab the GPS and Compass information for a work project. You can research the various mission control programs that use MavLink to see the extent of control the protocol has. If I remember correctly you can even send direct stick commands over that interface to manually pilot the craft. This solution makes for lots of flexibility, especially when you consider the huge community writing Arduino libraries. It would be simple to add just about any sensor you could want.

> **Comments:**
> **username_0**: That sounds quite reassuring! I always thought mavlink was just a groundstation protocol, and I couldn't see any "custom/outboard/etc" modes on the list so I assumed Ardupilot didn't have these features available. I'll definitely give it a look, thanks!  

---

### Answer by username_3 on 2020-04-21. Score: 2

[PX4](https://px4.io/) looks like it is quite flexible, and might be what you are looking for. It might not be as user friendly as for example iNAV, but it should give you much more possibilities even if that comes at the cost of having to write more code.


---

### Answer by username_4 on 2020-04-29. Score: 2

You could consider looking for research autopilots. Researchers try new things in all levels of the autopilot, and so they need extensibility and performance more than advanced features.

From what I understand Ardupilot and PX4 are popular. My university uses [ROSflight](https://rosflight.org), which is nice because it interfaces with Robot Operating System, which allows for sensor and control data to get around relatively easily. Depending on the type of UAV you're using, you would run [ROSplane](https://github.com/byu-magicc/rosplane) or [ROScopter](https://github.com/byu-magicc/roscopter) on top of it to provide higher level functions. It is all highly extensible, and you can replace any of the layers of the autopilot independently. Also nice, it has a pretty good simulator so that you can try fancy stuff without crashing a real UAV. Do note that it lacks some of the higher-level features provided by other autopilots, and so you'll have to look at what you want to do to decide.


---

### Answer by username_5 on 2020-04-23. Score: 1

You can program/script elaborate flight patterns and then translate it to MAVLink format mission messages either live or in pre-recorded mission mode. Then depending on your needs - you either upload your mission or send it live over telemetry connection.


---

