Saturday, April 26, 2014

Lua Coming in OpenTX 2

An interesting milestone is upon us.  Lua (the scripting language) will be embedded in OpenTX 2.

Here's an example of how elevon mixing would be expressed in Lua



local inputs = {
                 { "Aileron", SOURCE },
                 { "Elevator", SOURCE },
                 { "Ail. ratio", VALUE, -100, 100, 0 },
                 { "Ele. ratio", VALUE, -100, 100, 0 }
               }
                 
local outputs = { "Elv1", "Elv2" }

local function run(input1, input2, ratio1, ratio2)

  value1 = (input1 * ratio1) / 100
  value2 = (input2 * ratio2) / 100
  elevon1 = value1 + value2
  elevon2 = value1 - value2
  return elevon1, elevon2
end

return { input=inputs, output=outputs, run=run }


Although it should be noted the the docs explicitly say "Do not use Lua model scripts for controlling any aspect of your model that could cause a crash if script stops executing."

No comments:

Post a Comment