Thread Tools
This thread is privately moderated by l shems, who may elect to delete unwanted replies.
Dec 09, 2018, 10:40 AM
Have Fun and Just Fly!
l shems's Avatar
Thread OP
Alert

Bugs in openTX lua API's


As the developers of OpenTX do not always have time to fix BUGS, I opened this thread to inform people about which bugs are in which version.

This in order to prevent hours and hours of breaking your head on why something doesn't work as expected.

feel free to add.
Last edited by l shems; Dec 09, 2018 at 10:48 AM.
Sign up now
to remove ads between posts
Dec 09, 2018, 10:40 AM
Have Fun and Just Fly!
l shems's Avatar
Thread OP

model.getcurve() / model.setcurve() incompatibility


The model.getcurve() and model.setcurve() have several incompatibilities in openTX 2.2.1 and 2.2.2:

code that will crash or give problems
Code:
local settings = model.getCurve(1-1)
model.setCurve(1-1,settings)
OpenTX 2.2.1 BUGS
  1. the settings.y (the y values for the curve) indexes start at 0 for settings=model.getCurve(1-1), and at 1 for model.setCurve(1-1,settings)
  2. the settings.smooth (the lines or smooth parameter for a curve) is a boolean for model.getCurve() and a 0/1 for model.setCurve

OpenTX 2.2.2 BUGS
  1. the settings.y (the y values for the curve) indexes start at 0 for settings=model.getCurve(1-1), and at 1 for model.setCurve(1-1,settings)
  2. the settings.smooth (the lines or smooth parameter for a curve) is a boolean for model.getCurve() and a 0/1 OR BOOLEAN for model.setCurve

I have made a replacement function for almost all get and set functions, because they are superfluos in my opinion. It is much better practice to use only one function, in this case simply 'curve', that allows to get and update at the same time.

The use is as follows:
Code:
local settings
settings = curve(1,settings)

   code to change the settings array here 

settings = curve(1,settings)
The idea is that you can now use the same indices as on the radio (1 for curve 1), and you need only one function. if you leave settings at nil, or don't even use it in the function call, you get just the results. Also, because this new function 'curve' will be returning the effective result by using the model.getCurve function to return the results, it will return the ACTUAL settings, even if you intended to update but that didn't work. So this code is even correct for OpenTX 2.0, it just won't change the settings on the radio.
If you use this way of programming, you can even build in the limlit checks that the guys at openTX don't want to do. you can call the function with ANY wanted new settings, and it will always return the NET EFFECT of these new settings, even if some are and others arent taken into account. MUCH easier for all your settings changing code.

This replacement function will properly work for all OpenTX versions and correct for the BUGS.

Code:
local index,parameter,newModelSetting = ...

index=index-1--offset on switchnumbers

local setting

if not (newModelSetting==nil) then
  setting = model.getCurve(index)
  setting[parameter]= newModelSetting
  for j=#setting.y,0,-1 do
    setting.y[j+1] = setting.y[j]
    if setting.x then
      setting.x[j+1] = setting.x[j]
    end
  end
  setting.y[0]=nil
  if setting.x then
    setting.x[0]=nil
  end

  if setting.smooth == true then  -- correct for incorrect setcurve implementation
    setting.smooth = 1
  else
    setting.smooth = 0
  end
  
  if model.setCurve then
    model.setCurve(index,setting)
  end
end
  
setting=nil
newModelSetting=nil

return model.getCurve(index)[parameter]
REMARK: code has changed, because for a smooth curve the x values are having the same issue. I rewrote the code a little to make it more stable.

Have Fun and Just Fly!
Last edited by l shems; May 25, 2019 at 06:02 PM.
Jan 06, 2019, 10:50 AM
Have Fun and Just Fly!
l shems's Avatar
Thread OP

Elevator weight positive in wizard setup


Although no bug in the literal sense, it is very bad practice to have a mixer output go to positive values when you want the surface to go down. The elevator assignment that is done now when you create a new plane setup with the wizard will output a positive value when you push the elevator stick forward, which is not consistent with this definition.

Be aware of this anomaly when using the wizard to start a new model.
Mar 01, 2019, 02:10 AM
Jens Hoffmann
jensdk's Avatar
Hi Guido

In OTX above 2.2 it seems that it's only possible using 3 flightmodes the "easy" ... on a 3pos switch, when I want to activate the 4. mode, nothing happens..
i fly f3K planes need 3 modes for camber and 1 for elevatorpreset when launching.. I have the 3 modes on SA and want the 4 on SF ..
Mar 01, 2019, 10:53 AM
Have Fun and Just Fly!
l shems's Avatar
Thread OP
Quote:
Originally Posted by jensdk
Hi Guido

In OTX above 2.2 it seems that it's only possible using 3 flightmodes the "easy" ... on a 3pos switch, when I want to activate the 4. mode, nothing happens..
i fly f3K planes need 3 modes for camber and 1 for elevatorpreset when launching.. I have the 3 modes on SA and want the 4 on SF ..
Send me a model backup of your attempt, and tell me for which radio and Firmware.

At least I could help determine if it is a bug or misunderstanding.
Mar 08, 2019, 10:25 AM
Jens Hoffmann
jensdk's Avatar
Quote:
Originally Posted by l shems
Send me a model backup of your attempt, and tell me for which radio and Firmware.

At least I could help determine if it is a bug or misunderstanding.
That's all about understanding the priority of the modes,,, sorted !
Mar 08, 2019, 06:43 PM
Have Fun and Just Fly!
l shems's Avatar
Thread OP
Quote:
Originally Posted by jensdk
That's all about understanding the priority of the modes,,, sorted !
Ok. Good!

justfly solutions


Quick Reply
Message:
Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
New Product Taranis Q X7 OpenTX Battery Capacity Remaining Lua Script RcRav Radios 0 Mar 31, 2017 03:17 PM
Discussion OpenTx Lua Script Lap Timer RcRav Radios 0 Jan 10, 2017 02:08 PM
Discussion L/D and Sink rate LUA script for OpenTx FabFlight Sailplane Talk 2 Mar 23, 2016 07:28 PM