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 includes Acknowledgments and Getting Started.
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
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:
script input table (optional, see Input Table Syntax)
script output table (optional, see Output Table Syntax)
script init function (optional, see Init Function Syntax)
script run function (see Run Function Syntax)
inputs table defines input parameters (name and source) to run function (see Input Table Syntax)
outputs table defines names for values returned by run function (see Output Table Syntax)
init_func() function is called once when script is loaded.
run_func() function is called periodically
TODO: describe how theme scripts work on Horus type transmitters.
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)
TODO: Need to determine status of wizard in 2.2
Widgets are small scripts that show some info in a 'zone' in one of the model specific user defined (telemetry) screens. You can define those screens within the telemetry menu on the HORUS.
Each model can have up to five custom screens, with up to 8 widgets per screen, depending on their size and layout. Each instance of a widget has his own custom settings.
Widgets are located on the SD card, each in their specific folder /WIDGETS/<name>/main.lua (name must be in 8 characters or less).
Widgets need to be registered through the telemetry setup menu.
widget create function is called
widget update function is called upon registration and at change of settings in the telemetry setup menu.
widget background function is periodically called when custom telemetry screen is not visible. Notice:
This is different from the way telemetry scripts are handled
widget refresh function is periodically called when custom telemetry screen is visible
widget is stopped and disabled if it misbehaves (too long runtime, error in code, low memory)
all widgets are stopped while one-time script is running (see Lua One-time scripts)
Once registered, widgets are started when the model is loaded.
Every widget must include a return statement at the end, that defines its interface to the rest of OpenTX code. This statement defines:
widget name (name must be a string of 10 characters or less)
widget options array (maximum five options are allowed, 10 character names max, no spaces!)
widget create function
widget update function
script background function
script refresh function
options are only passed through to OpenTX to be used on widget creation. Don't change them during operation, this has no effect.
create() function is called once when widget is loaded and begins execution.
update() function is called once when widget is loaded and begins execution.
background() is called periodically when custom telemetry screen containing widget is not visible.
refresh() function is called periodically when custom telemetry screen containing wodget is visible.
in the example given, you can see that no global variables or functions are needed to operate the widget.
variables that are used throughout the widget, can best be declared inside the create function as local variables
those local variablkes can then be passed through to the other functions as an element of the widget array that is returned
The OpenTX team has no intention of making a profit from their work. OpenTX is free and open source and will remain free and open source. But OpenTX is more expensive to maintain than most open source projects. The reason is that there is a never ending flood of hardware to integrate and maintain code for. Hardware that costs.
Another reason is that OpenTX maintains a build server that serves firmware compiled on demand. This is where OpenTX Companion orders your customized firmware. The server is not for free and the bandwidth is ever increasing with tens of thousands of firmware downloads each month.
The OpenTX team is grateful to those who have donated to the project. You have helped making OpenTX and OpenTX Companion great.
The Github Donor List is updated at each OpenTX release.
If you would like to contribute to OpenTX, donations are welcome and appreciated:
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:
script init function (optional, see Init Function Syntax)
script run function (see Run Function Syntax)
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.
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.