Script Language

erskyTx runs on many radios and upgrade boards
ersky9x was a port of er9x for use on the sky9x board.
Post Reply
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Script Language

Post by MikeB »

I'm developing a script language for use in ersky9x. This thread is for discussions on the language, and I'll update this post with the latest documentation.

Mike.

Here is an initial document that tries to describe the language. Hopefully the language will improve as the development proceeds.
script.pdf
28-May-2019 18:57
Include resettelemetry
(93.52 KiB) Downloaded 593 times
script.pdf
22-Mar-2019 15:07
Add drawing "plot types"
(93.15 KiB) Downloaded 450 times
script.pdf
23-Jan-2019 12:00
Updated for R222d3 test version
(92.41 KiB) Downloaded 452 times
script.pdf
02-Nov-2018 18:48
Updated with serial and file functions and the bytemove function.
(89.61 KiB) Downloaded 471 times
script.pdf
15-Jul-2018 22:15
Updated to include new functions (crossfiresend, const, drawrectangle improved)
Needs r222B4 or later.
(87.16 KiB) Downloaded 511 times
script.pdf
30-Mar-2018 12:10
Updated to include new functions (bitfield, power, crossfirereceive).
Needs r222A4 or later.
(80.84 KiB) Downloaded 548 times
script.pdf
20-Aug-2017 16:37
Updated for multiple scripts and if-elseif
(73.92 KiB) Downloaded 638 times
script.pdf
03-Jul-2017 16:41
Updated
(69.09 KiB) Downloaded 550 times
script.pdf
02-Jul-2017 15:07
First issue.
(68.01 KiB) Downloaded 561 times
A program to run on a PC (Windows) that runs scripts and simulates the display. Copy this .exe into the directory in which you have installed eepe/eepskye (it needs the QT dll files.
Interpreter.zip
13-Nov-2020 12:55
Fix string length bug, strings up to 96 chars are allowed.
(46.8 KiB) Downloaded 327 times
Interpreter.zip
28-May-2019 18:57
Build with latest code from radio
(46.61 KiB) Downloaded 449 times
Interpreter.zip
22-Mar-2019 15:07
Add "slider" to give a value for "getvalue" of -100 to +100.
(45.67 KiB) Downloaded 447 times
Interpreter.zip
14-Oct-2018 16:36
First version
(44.09 KiB) Downloaded 478 times
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

Wonderful, thank you..
I bet this will become way better than the existing LUA, as it is being developed specifically for RC..

João

Sent from my thor using Tapatalk

My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
ReSt
Posts: 1581
Joined: Tue Dec 27, 2011 11:34 pm
Country: -

Re: Script Language

Post by ReSt »

I have attached the Quick Command Reference of an Intel MSC Basic-52

Just as a reference to see, which commands this small Basic supports.

What I'm missing (just a wish list) in your first draft are more control structures e.g.
do - loop / until / while
for - to - STEP - next
iterate
if - then - ELSE
logic compares AND / OR / XOR
abs
NOT

Just a short selection/suggestion of what I would like to see.

BUT IT'S YOUR CHOICE what you do and what can be done.

Reinhard
Command Reference AH52 Basic.zip
(340.5 KiB) Downloaded 528 times
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

Mike,
Control names: (Rud, Ele, Ail, Thr, P1,P2,P3, PPM1-PPM8, CH1-CH24)
Possible to add P4 and P5??

Possible "drawcircle"??
sportTelemetrySend
syntax: sportTelemetrySend( <expression>, <expression>, <expression>, <expression> )
sportTelemetrySend( PhyId, Command, AppId, data)
sportTelemetryReceive
syntax: sportTelemetryReceive( <variable>, <variable>, <variable>, <variable>)
sportTelemetryReceive( PhyId, Command, AppId, data)
What about HUB telemetry?

What about some "Pause" function?? Like the script does something and then pauses for a defined time?

I am asking these questions based on what I think I have understood :)

Thanks

João

EDIT: Also it would help some examples with real values and variables..
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

I hope to add more control structures. I need to work out how to process them when the script is loaded as they all require some "forward references", and also, with the looping structures, they may be nested so multiple forward references need to be handled.
All may be simulated with the code already implemented of course.

I'll add more names to getvalue() as we go on, if you know the numbers to which they correspond all items may be accessed, I'll try to compile a list of them.

Hub (and other) telemetry, will require reading bytes from a "data stream" and then processing them. This is something I have i mind.

Pause may be handled by using the gettime() function, noting the current "time" at the start and waiting until the time exceeds this by your delay time.
HOWEVER, you need to be aware of the way in which scripts are processed, they are not separate programs that run by themselves, they execute as part of the main code. Basically, a script runs from its start until it reaches a "stop" instruction every 10mS. If a script tries to execute "too many" instructions each time it executes, it will be terminated to prevent the script from stopping everything else (like control of the model) from taking place.

With this intial implementation of loading and executing now working, more features should be possible to be added as required.

I have a few more tests I need to do then I'll hopefully post some test versions for others to try.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

Thanks Mike.. I will be glad to test as always.. But I will need some examples to get me started, otherwise I won't know what to test :D I am a good example of the average user, I know nothing ;) :mrgreen:

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
Hertz
Posts: 72
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: Script Language

Post by Hertz »

Is there a test version of firmware for 9xtreme available so we could start porting the Lua scripts?
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

I should have a test version either later today or tomorrow.

I've just added allowing numerical constants to be in hex, binary or octal as well as decimal.
I've also added the functions not() and abs().

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

Fixed a few bugs so now it looks like it is working, although I would expect some problems to occur.
I've posted test versions of ersky9x with this scripting language in, and also updated the document on the first post.
Scripts must have an extension of ".bas", and be put into a "\scripts" directory on the SD card. Only "standalone" scripts are available so far. From the main display go UP LONG (or select "statistics"), then RIGHT about 6 times to get to the script menu to run one.
Errors may occur when loading, or when running. Error reporting is just "Error 3 at line 7", error numbers are in the document. The error number will have 100 added to it if it occured at run time.

This is early days, so hopefully lots more facilities will be added as we go on.

There are some limits built in at present, like the loaded script and it's variables must fit in 6000 bytes, and you can only have 100 (ordinary) variables.
It also only executes 300 lines of script every 10mS.
While loading, I have to create a "symbol table". This also uses the same 6000 bytes, as the loaded code, so may also limit the size of script that may be loaded.
These limits will be reviewed, and the 6000 will also probably change to use available RAM.

I've attached a test script I've been using. It is nothing special, just something to test the operation, but it has worked on a SKY board, a 9Xtreme and a QX7. It just displays some numbers, graphics and text. You should see the Ail stick value, the battery voltage, idletime, and elapsed time (units of 10mS), with a small rectangle flashing on/off every 2 seconds.
Exit the script with either a press of the EXIT button or the rotary encoder button.

Mike.
t.zip
(385 Bytes) Downloaded 536 times
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

Thank you.. will try it later.. A bit busy at the moment ;) :)

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

Loaded the script on the Ar9x board, it seems to be working as you described.. I also see a little diagonal line on the lower left corner.. Did you program it?

Thanks

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

Yes, the little line is drawn by the script, also a single pixel near the top left corner of the display.

I'll see if I can get a script loading as a telemetry script as well as standalone.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

Then it looks like it is all good.. Didn't try to control a model while using a script.. Maybe with a heavier script.. :) If someone writes it of course ;) :)
Tnx
João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

One interesting thing is the "idletime" shown by that script (65% on a SKY board), is about the same as that shown on the STAT2 display.

I have an enhancement in test, the command "while", with an "end", so you will be able to have:
while condition
statements
end

The statements between the while and the end will be repeatedly executed as long as condition is not zero.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

Just got a "Telemetry" script running on a custom telemetry screen. This loads automatically, if selected, stops while a stand alone script runs, and reloads when the stand alone script terminates.
The "Telemetry" script is run, whether you have the custom screen showing or not. There is a new function "sysflags()", which returns several bits, bit 0 is set if the display is available, so you may check whether to run in the "foreground" or in the "background".

I'll be posting "d7" soon with this in.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

Mike, could you please include that telemetry script in the zip file when you post d7?

Thanks

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

"d7" posted (includes COM2 interrupt priority raised on 9Xtreme). You may now have a single "Telemetry" script, configure in the custom telemetry menu.
You need to create a "TELEMETRY" directory in the "SCRIPTS" directory, and put "tel0.bas" from the attached .zip in it, then change the custom telemetry screen to type "script" and select "tel0" as the script. There is a limit of 6 characters for the filename.

There is a new function available "settelitem()" that allows you to set a telemetry value from the script. THe syntax is:
settelitem( "name", value ), where the name text is the name of a telemetry item. The example telemetry script uses this to set the telemetry item "Cus1" to be the same as the radio battery voltage, then also displays the resulting value. If you set the other custom telemetry display to show "Cus1", you should see it having the battery voltage in tenths of a volt.
This script copies the battery value to Cus1 every time it runs, then checks to see if the custom telemetry screen is available (sysflags()) and either stops or displays information as required.

Mike.
t.zip
(635 Bytes) Downloaded 450 times
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

Thanks Mike.. Will test.. But weather today isn't good around here.. :(

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
bob195558
Posts: 2377
Joined: Sun Dec 16, 2012 7:24 pm
Country: United States
Location: New England, Vermont
Contact:

Re: Script Language

Post by bob195558 »

So the Micro SD Card list of folder Directories will have "SCRIPTS" added to it ?
I added the new info to this post: (viewtopic.php?f=35&t=9034&p=116984#p116984).

Bob B.
Er9x on 9x radio, with Smartieparts Programmer and TelemetrEZ Board.
ErSky9x on Taranis, Sky9x, 9Xtreme radios.
3D-Printing: (https://openrcforums.com/forum/viewforum.php?f=129).
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

And inside the "scripts" directory, another one called "Telemetry", as far as I understand..

João

Sent from my thor using Tapatalk

My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
bob195558
Posts: 2377
Joined: Sun Dec 16, 2012 7:24 pm
Country: United States
Location: New England, Vermont
Contact:

Re: Script Language

Post by bob195558 »

OK thanks !
I will add it to the (Micro SD Card list of folder Directories) list: (viewtopic.php?f=35&t=9034&p=116984#p116984).

Bob B.
Er9x on 9x radio, with Smartieparts Programmer and TelemetrEZ Board.
ErSky9x on Taranis, Sky9x, 9Xtreme radios.
3D-Printing: (https://openrcforums.com/forum/viewforum.php?f=129).
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

Mike, I have just flashed d7 to my 9XT and enabled the attached script on one of the custom displays. I have "SCRIPT ERROR" on the screen. I have no receiver ON, does it make a difference? Shouldn't it say "No telemetry" or similar instead?

Encoder problem is fixed, the other problem when moving the stick to bypass the splash screen at power ON is still there..

Thanks

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

Try a power off and on, when you select the script in the menu, it (currently) doesn't start it, only on loading a model or ending a stand alone script is it loaded and run.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

Ok, that worked now on both 9XT and Ar9x.. Funny, I could swear that I did cycle the power before and it didn't work :o

Ar9x, moving the stick right after power ON. I can hear 2 loud clicks (normally one at power ON), and the model name is not played. This seems to be the same problem as on the 9XT, but it behaves differently. The 9XT plays the model name and the voices associated with !THR.

Changing models doesn't stop the script.. It keeps running on the new model.. This doesn't seem right??


João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

I've fixed the script running on the new model when it shouldn't.

Some additions that will be in the next test version:
Strings may now include "special" characters, e.g.
\n - newline (also \t \r etc.)
\037 - Octal value
\x45 - Hex value

Three new functions:
strtoarray - initialises a byte array from a string
getswitch - gets the current state (on or off) of a switch, physical or logical
setswitch - sets a (unused) logical switch on or off

Examples:
strtoarray(barray[2],"xyz\n\"\xF4\037")
sets barray[2] to 'x', barray[3] to 'y' and so on as long as the items fit in the array as declared.

getswitch("AIL") returns the state of the AIL switch as 0 or 1 (9X radios)
getswitch("SCv") returns the state of the SCv as 0 or 1 (FrSky radios)

setswitch("L5",0) sets logical switch L5 to off, as long as the switch function is defined as "----"

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

I've posted "d9", with the items in the preceeding post included.
Since then, I've enhanced the operation of "if".

Options are:
if <expression> then goto <label>
if <expression> then gosub <label>
if <expression> then <statement>
and in the next test version (note no "then" keyword)
if <expression>
<statement>
. . .
<statement>
end

if <expression>
<statement>
. . .
else
<statement>
. . .
end

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

I've posted "e3". This supports multiple scripts running. The script.pdf file on the first post is updated.
Also supported is an elseif option like:

if <expression>
<statement>
. . .
elseif <expression>
. . .
elseif <expression>
. . .
else
<statement>
. . .
end

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

Wonderful, thanks Mike.

João

Sent from my thor using Tapatalk

My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
cutdact
Posts: 21
Joined: Tue Oct 04, 2016 7:28 am
Country: Finland

Re: Script Language

Post by cutdact »

Hi MikeB,

Do you have any working examples with sportTelemetryRecieve and Send? Really interesting project!

Thank you.
User avatar
MikeB
9x Developer
Posts: 17990
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Script Language

Post by MikeB »

Here is a simple (standalone) script that lets you adjust a reference voltage and then send it to a particular sensor for calibration purposes:

Code: Select all

if init = 0
init = 1
voltage = 500
end
drawclear()
drawtext(20, 16, "Mini Hub", 0)
drawtext(0, 24, "Voltage", 0)
drawnumber(78, 24, voltage, PREC2)
drawnumber(50, 32, value, 0)
drawnumber(50, 40, result, 0)
drawnumber(50, 48, temp, 0)
drawnumber(120, 48, getvalue( "A3=" ), 0)
drawnumber(120, 56, getvalue( "A4=" ), 0)
if Event = EVT_MENU_BREAK
result = sportTelemetrySend( 0x1B, 0x31, 0x50FF, voltage )
let value = value + 1
temp = 0
end
if Event = EVT_LEFT_FIRST then voltage -= 1
if Event = EVT_RIGHT_FIRST then voltage += 1
if Event = EVT_DOWN_FIRST then voltage -= 10
if Event = EVT_UP_FIRST then voltage += 10
if voltage < 400 then voltage = 400
if voltage > 600 then voltage = 600
if Event = EVT_EXIT_BREAK then goto done
if Event = EVT_BTN_BREAK then goto done
stop
done:
finish
Do you have anything you can receive SPort telemetry from?
Currently configuration data and User ID passthrough data is available (similar to openTx LUA).
An S6R or S8R receiver would be useful for receiving configuration data.
Normal SPort telemetry data is processed by ersky9x, and the telemetry values may be accessed from a script, so not much point in passing those SPort data packets to the script.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

Post Reply

Return to “erskyTx (was ersky9x)”