Page 1 of 1

Lua syntak error

Posted: Sun Jan 13, 2019 7:52 pm
by Raythegreat
Hi,

I'm starting to learn about LUA scripts on Taranis+. I have never used Lua before but know very well the C language.

I saved with Notepad++ the file named pr.lua the following program and when I execute this lua script in the radio setup I have the following error message: "script syntax error".
I saved it on SD card in SCRIPTS/FUNCTIONS

Please advise what can be the problem? Scripts is below.
Thanks,


lcd.clear()
lcd.drawText(1, 1,"drawText() example", 0)
lcd.drawText(1, 11,"0 - default", 0)
lcd.drawText(1, 21,"BLINK", BLINK)
lcd.drawText(1, 31,"INVERS + BLINK", INVERS + BLINK)
lcd.drawText(120, 1,"XXLSIZE", DBLSIZE)
lcd.drawText(120, 21,"MIDSIZE", MIDSIZE)

Re: Lua syntak error

Posted: Mon Jan 14, 2019 12:51 am
by rdeanchurch
If that is the complete program, you need to put a wrapper on it.

local function run()
lcd.clear()
lcd.drawText(1, 1,"drawText() example", 0)
lcd.drawText(1, 11,"0 - default", 0)
lcd.drawText(1, 21,"BLINK", BLINK)
lcd.drawText(1, 31,"INVERS + BLINK", INVERS + BLINK)
lcd.drawText(120, 1,"XXLSIZE", DBLSIZE)
lcd.drawText(120, 21,"MIDSIZE", MIDSIZE)
print (" @#$% @#$% @#$% @#$% @#$% pr.lua run()")
end
return { run=run }

BUT first read about function scripts in
https://opentx.gitbooks.io/opentx-2-2-l ... ripts.html
Particularily,
"
Limitations
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
"
The print statement shows in runs, but nothing shows on the LCD.
Try running it as a Telemetry script.

Re: Lua syntak error

Posted: Mon Jan 14, 2019 1:54 am
by Raythegreat
Thanks rdeanchurch,

Yes I I forgot the wrappers, they were not there.
Do I absolutely need an init and run functions? Like the main() in C language?
How do I show something of the LCD? Let's say I want to print Rudder = 76 and see the result on my screen?

Thanks,
RTG

Re: Lua syntak error

Posted: Mon Jan 14, 2019 2:49 am
by rdeanchurch
Use a Telemetry script.
As I'm flyer, I use voice for in critical flight information so I do not have to look at the lcd.
Since I don't necessarily have the telemetry screen showing, I often put critical announcements in background(), but if there is nothing you want to setup initially or run even when the telemetry screen isn't being displayed, then you do not need init() or background().
You can playFile of the rudder, throttle, ...

Re: Lua syntak error

Posted: Mon Jan 14, 2019 3:05 am
by Raythegreat
Thank you again rdeancherch.

Where can I find a list and the description of parameters of allowable lua functions for Taranis?
That would help me greatly. I looked around and found no place where functions are listed with their parameters description (for the Taranis).

RTG

Re: Lua syntak error

Posted: Mon Jan 14, 2019 3:41 am
by rdeanchurch
In the same document that the above url points to
https://opentx.gitbooks.io/opentx-2-2-l ... guide.html

Best to start at the beginning
https://opentx.gitbooks.io/opentx-2-2-l ... e/content/

Re: Lua syntak error

Posted: Mon Jan 14, 2019 3:58 am
by Raythegreat
Many thanks rdeanchurch

RTG

Re: Lua syntax error

Posted: Sat Feb 02, 2019 5:59 am
by Raythegreat
Hi all,

I've been playing with LUA for a few days now and starting to get used to it.

I have open TX 2.2.2 for both firmware and Companion.

In the companion telemetry simulator, the Cels field does not seem to be working over 2 cells. Works for 1 or 2 cells only. From 3 to 6 does not work.
Also when I use the term Cels to read my FLVSS lipo monitor it does not work. Cels- or Cels+ works. Don't know why Cels in LUA does not work.

My code is:

local voltage
local lipovalue = "Cels"
voltage = getValue(lipovalue)

When I print voltage it gives me 0. If I use local lipovalue = "Cels-" it works and gives me the minimum value as expected.

Please advise.
Thanks,

RTG

Re: Lua syntak error

Posted: Sat Feb 02, 2019 9:16 am
by Kilrah
Cels is a special case and returns a table with all cell voltages, see documentation.
https://opentx.gitbooks.io/opentx-2-2-l ... _data.html

Re: Lua syntak error

Posted: Sat Feb 02, 2019 5:15 pm
by Raythegreat
Thanks Kilrah,

Yes I have seen this. I just wanted to check if there was a simpler way. Cel- will do the job for now.

But what about the telemetry simulator in Companion 2.2.2, number of cells over 2 does not seem to work. 1 or 2 cells works

RTG

Re: Lua syntak error

Posted: Sat Feb 02, 2019 5:53 pm
by Kilrah
Works for me here. You need to populate the voltages in order, if there's a gap higher ones won't appear.

Re: Lua syntak error

Posted: Sat Feb 02, 2019 6:10 pm
by Raythegreat
No gaps, still does not work for me. Anything over 3 cells does not work (for me)

This is what I did:

I defined 4 telemetry sensors coming from calculated values, C1,C2,C3,C4 and I display them in the display menu. All work very well in real life on the transmitter but in Companion and when using LUA no.

With Lua: I have four cells lipo (obviously you knew that)

local volt1
local volt2
local volt3
local volt4

local v1 = "C1"
local v2 = "C2"
local v3 = "C4"
local v4 = "C4"

volt1= getValue(v1)
volt2 = getValue(v2)
volt3 = getValue(v3)
volt4 = getValue(v4)

Only volt1 and volt2 works and I don't have any gaps.

Another thing also. In the Taranis itself the Cels value is the sum of the 4 lipo cells so I wonder why we would not be able to use it.
I understand about the array but I would have used another name than Cels who works as a single value on the Tx (without LUA).


RTG

Re: Lua syntak error

Posted: Sat Feb 02, 2019 7:57 pm
by Raythegreat
Hi,

OK I found in the Telemetry simulator of Companion that if I put 2 as the number of Cels in the field near the 6 entries of LiPo voltages it works. Strange, only 2 there works.
Any other number in that field does not work well.

So now the LUA problem was caused by companion. If I keep 2 there all works; simulator and LUA.

RTG.

Re: Lua syntak error

Posted: Sat Feb 02, 2019 10:17 pm
by Raythegreat
Hi

I believe I have found the reason why only 2 works in the field Cels for the telemetry simulator.
The 2 is NOT the number of cells but (as I thought) but more an ID. Right?

Please confirm how to set these numbers in the 2 columns shown by the two arrows or are they set automatically by the model parameters?.
Please see file attached named telemetry_sim.pdf.

Thanks
RTG

Re: Lua syntak error

Posted: Sun Feb 03, 2019 2:42 am
by Kilrah
There is no attached file. But yes for each sensor the first column is the sensor ID and must match what is set in your model settings.

Re: Lua syntak error

Posted: Sun Feb 03, 2019 4:20 am
by Raythegreat
Thanks Kilrah for the confirmation.

My bad, I thought the 2 was the number of lipo cells, it is the ID of sensor.

Problem solved.

Many Thanks
RTG