Lua syntak error

Help with any software/desktop related issues. e.g. companion9x, eePe, etc
Post Reply
Raythegreat
Posts: 211
Joined: Sat Apr 16, 2016 11:33 pm
Country: -

Lua syntak error

Post by Raythegreat » Sun Jan 13, 2019 7:52 pm

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)


rdeanchurch
Posts: 634
Joined: Tue Dec 27, 2011 11:22 pm
Country: United States
Location: Gardnerville, Nv

Re: Lua syntak error

Post by rdeanchurch » Mon Jan 14, 2019 12:51 am

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.
Dean
OldDmbThms: 1. Takeoff, 2. Crash, 3. Repair, GOTO 1

Raythegreat
Posts: 211
Joined: Sat Apr 16, 2016 11:33 pm
Country: -

Re: Lua syntak error

Post by Raythegreat » Mon Jan 14, 2019 1:54 am

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

rdeanchurch
Posts: 634
Joined: Tue Dec 27, 2011 11:22 pm
Country: United States
Location: Gardnerville, Nv

Re: Lua syntak error

Post by rdeanchurch » Mon Jan 14, 2019 2:49 am

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, ...
Dean
OldDmbThms: 1. Takeoff, 2. Crash, 3. Repair, GOTO 1

Raythegreat
Posts: 211
Joined: Sat Apr 16, 2016 11:33 pm
Country: -

Re: Lua syntak error

Post by Raythegreat » Mon Jan 14, 2019 3:05 am

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


rdeanchurch
Posts: 634
Joined: Tue Dec 27, 2011 11:22 pm
Country: United States
Location: Gardnerville, Nv

Re: Lua syntak error

Post by rdeanchurch » Mon Jan 14, 2019 3:41 am

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/
Dean
OldDmbThms: 1. Takeoff, 2. Crash, 3. Repair, GOTO 1

Raythegreat
Posts: 211
Joined: Sat Apr 16, 2016 11:33 pm
Country: -

Re: Lua syntak error

Post by Raythegreat » Mon Jan 14, 2019 3:58 am

Many thanks rdeanchurch

RTG

Raythegreat
Posts: 211
Joined: Sat Apr 16, 2016 11:33 pm
Country: -

Re: Lua syntax error

Post by Raythegreat » Sat Feb 02, 2019 5:59 am

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

User avatar
Kilrah
Posts: 9885
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Lua syntak error

Post by Kilrah » Sat Feb 02, 2019 9:16 am

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

Raythegreat
Posts: 211
Joined: Sat Apr 16, 2016 11:33 pm
Country: -

Re: Lua syntak error

Post by Raythegreat » Sat Feb 02, 2019 5:15 pm

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

User avatar
Kilrah
Posts: 9885
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Lua syntak error

Post by Kilrah » Sat Feb 02, 2019 5:53 pm

Works for me here. You need to populate the voltages in order, if there's a gap higher ones won't appear.

Raythegreat
Posts: 211
Joined: Sat Apr 16, 2016 11:33 pm
Country: -

Re: Lua syntak error

Post by Raythegreat » Sat Feb 02, 2019 6:10 pm

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

Raythegreat
Posts: 211
Joined: Sat Apr 16, 2016 11:33 pm
Country: -

Re: Lua syntak error

Post by Raythegreat » Sat Feb 02, 2019 7:57 pm

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.

Raythegreat
Posts: 211
Joined: Sat Apr 16, 2016 11:33 pm
Country: -

Re: Lua syntak error

Post by Raythegreat » Sat Feb 02, 2019 10:17 pm

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

User avatar
Kilrah
Posts: 9885
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Lua syntak error

Post by Kilrah » Sun Feb 03, 2019 2:42 am

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.

Raythegreat
Posts: 211
Joined: Sat Apr 16, 2016 11:33 pm
Country: -

Re: Lua syntak error

Post by Raythegreat » Sun Feb 03, 2019 4:20 am

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


Post Reply

Return to “Software”