Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
This section introduces the types of Lua scripts supported by OpenTX and how they may be used.
Go to https://doc.open-tx.org/opentx-2-3-lua-reference-guide/ for the latest published version of this guide.
This guide covers the development of user-written scripts for R/C transmitters running the OpenTX 2.3 operating system with Lua support. Readers should be familiar with OpenTX, the OpenTX Companion, and know how to transfer files the SD card in the transmitter.
Part I of the guide shows how to enable Lua support for Taranis and includes basic examples of each types of script.
Part II is a programming guide that introduces the types of OpenTX Lua scripts and how to use them.
Part III is the OpenTX Lua API Reference
Part IV addresses common issues in converting Lua scripts that were originally written for OpenTX 2.0
Part V addresses common issues in converting Lua scripts that were originally written for OpenTX 2.1
Part VI covers advanced topics with examples
last updated on 2021/01/09 17:57:00 UTC
TODO: Need to determine status of wizard in 2.2
This section includes Acknowledgments and Getting Started.
One-Time scripts start when called upon by a specific radio function or when the user selects them from a contextual menu. They do their task and are then terminated and unloaded. Please note that all persistent scripts are halted during the execution of one time scripts. They are automatically restarted once the one time script is finished. This is done to provide enough system resources to execute the one time script.
Running a One-Time script will suspend execution of all other currently loaded Lua scripts (Mix, Telemetry, and Functions)
Place them anywhere on SD card, the folder /SCRIPTS/ is recommended. The only exception is official model wizard script, that should be put into /SCRIPTS/WIZARD/ folder that way it will start automatically when new model is created.
Script is executed when user selects Execute on a script file from SD card browser screen.
Script executes until:
it returns value different from 0
is forcefully closed by user by long press of EXIT key
is forcefully closed by system if if it misbehaves (too long runtime, error in code, low
memory)
Telemetry scripts are used for building customized screens. Each model can have up to three active scripts as configured on the model's telemetry configuration page. The same script can be assigned to multiple models.
Scripts are located on the SD card in the folder /SCRIPTS/TELEMETRY/<name>.lua. File name length (without extension) must be 6 characters or less (this limit was 8 characters in OpenTX 2.1).
Telemetry scripts are started when the model is loaded.
script init function is called
script background function is periodically called when custom telemetry screen is not visible. Notice:
In OpenTX 2.0 this function is not called when the custom telemetry screen is visible.
Starting from OpenTX 2.1 this function is always called no matter if the custom screen is visible or not.
script run function is periodically called when custom telemetry screen is visible
script is stopped and disabled if it misbehaves (too long runtime, error in code, low memory)
all telemetry scripts are stopped while one-time script is running (see Lua One-time scripts)
Every script must include a return statement at the end, that defines its interface to the rest of OpenTX code. This statement defines:
script init function (optional)
script background function
script run function
init_func()
function is called once when script is loaded and begins execution.
bg_func()
is called periodically, the screen visibility does not matter.
WARNING - Do not use Lua mix scripts for controlling any aspect of your model that could cause a crash if script stops executing.
Each model can have several mix scripts associated with it. These scripts are run periodically for entire time that model is selected. These scripts behave similar to standard OpenTX mixers but at the same time provide much more flexible and powerful tool.
Mix scripts take one or more values as inputs, do some calculation or logic processing based on them and output one or more values. Each run of a script should be as short as possible. Exceeding the script execution runtime limit will result in the script being forcefully stopped and disabled.
replacement for complex mixes that are not critical to model function
complex processing of inputs and reaction to their current state and/or their history
filtering of telemetry values
cannot update LCD screen or perform user input.
should not exceed allowed run-time/ number of instructions.
mix scripts are run with less priority than built-in mixes. Their execution period is around 30ms and is not guaranteed!
can be disabled/killed anytime due to logic errors in script, not enough free memory, etc...)
Place them on SD card in folder /SCRIPTS/MIXES/. File name length (without extension) must be 6 characters or less (this limit was 8 characters in OpenTX 2.1).
script is loaded from SD card when model is selected
script init function is called
script run function is periodically called (inside GUI thread, period cca 30ms)
script is killed (stopped and disabled) if it misbehaves (too long runtime, error in code, low memory)
all mix scripts are stopped while one-time script is running (see Lua One-time scripts)
If as script output is used as a mixer source
and the script is killed for what ever reason, then the whole mixer line is disabled
! This can be used for example to provide a fall-back in case Lua mixer script gets killed.
Example where Lua mix script is used to drive ailerons in some clever way, but control falls back to the standard aileron mix if script is killed. Second mixer line replaces the first one when the script is alive:
Every script must include a return statement at the end, that defines its interface to the rest of OpenTX code. This statement defines:
init_func() function is called once when script is loaded.
run_func() function is called periodically
OpenTX Companion 2.2 is available for download at http://www.open-tx.org/downloads.html
If you intend to use mixer scripts, when updating the firmware on your transmitter you need to make sure the lua option is checked in the settings for your radio profile (Main menu -> Settings ->Settings...) as shown below. This is not required if you only intend to run telemetry, one-time and function scripts, support for those is included by default.
Also note that the SD Structure path should contain a valid path to a copy of your transmitter's SD card contents, although that's not specific to Lua.
Function scripts are invoked via the 'Lua Script' option of Special Functions configuration page.
specialized handling in response to switch position changes
customized announcements
should not exceed allowed run-time/ number of instructions.
all function scripts are stopped while one-time script is running (see Lua One-time scripts)
Function scripts DO NOT HAVE ACCESS TO LCD DISPLAY
Place them on SD card in folder /SCRIPTS/FUNCTIONS/
script init function is called once when model is loaded
script run function is periodically called as long as switch condition is true
script is stopped and disabled if it misbehaves (too long runtime, error in code, low memory)
Every script must include a return statement at the end, that defines its interface to the rest of OpenTX code. This statement defines:
local variables retain their values for as long as the model is loaded regardless of switch condition value
The script below is an example of customized countdown announcements. Note that the init function determines which version of OpenTX is running and sets the unit parameter for playNumber() accordingly.
run_func(event)
function is called periodically when custom telemetry screen is visible. The event
parameter indicates which transmitter button has been pressed (see ). This is the time when the script has full control of the LCD screen and keys and should draw something on the screen.
script input table (optional, see )
script output table (optional, see )
script init function (optional, see )
script run function (see )
inputs table defines input parameters (name and source) to run function ()
outputs table defines names for values returned by run function (see )
script init function (optional, see )
script run function (see )