Running Lua under nuttx on PX4 flight control board

The PX4FMU is a powerful little flight control board based on the STM32F4 chip. The PX4 development environment currently uses the NuttX embedded RTOS.  In order to build and run apps in the PX4 environment, a developer must rebuild the entire nuttxOS, which has obvious drawbacks.

NuttX does include a simple shell, nsh, which supports a basic scripting language.  However, if you wish to develop complex app logic, nsh is probably not the right tool.

One idea I had was to port a high-level interpreted language to nuttx, to allow developers to script and modify flight control behaviors at runtime, without the need to rebuild nuttx.   So I took the compact Lua interpreter code and ported it to the PX4 environment.

You can find this under my PX4Firmware repository on github.  I have a sample app “pizzahat” that provides a script to the lua interpreter.  The current version is a proof-of-concept that causes Lua to run one of the built-in apps.  This demonstrates that Lua can be used to script all the nuttx builtin applications.

Note that I needed to hack Lua itself significantly to get it running under nuttx: you can find the hacked version (lua-nutt) here.

This is very early-stage, but shows potential.

Edit: I’ve had a couple people ask how big the Lua binary is.  A quick test shows that the px4default .px4 file is 115kB larger with lua-nutt (and the pizzahat test module).  

2 thoughts on “Running Lua under nuttx on PX4 flight control board

Leave a Reply