Script Language

ersky9x is a port of er9x for use on the sky9x board.
Post Reply
User avatar
MikeB
9x Developer
Posts: 14380
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Script Language

Post by MikeB » Sun Jul 02, 2017 2:01 pm

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
03-Jul-2017 16:41
Updated
(69.09 KiB) Downloaded 41 times
script.pdf
02-Jul-2017 15:07
First issue.
(68.01 KiB) Downloaded 34 times
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

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

Re: Script Language

Post by jhsa » Sun Jul 02, 2017 3:55 pm

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: 1381
Joined: Tue Dec 27, 2011 11:34 pm
Country: -

Re: Script Language

Post by ReSt » Sun Jul 02, 2017 4:16 pm

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 12 times

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

Re: Script Language

Post by jhsa » Sun Jul 02, 2017 5:34 pm

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: 14380
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Script Language

Post by MikeB » Sun Jul 02, 2017 7:01 pm

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.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!


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

Re: Script Language

Post by jhsa » Sun Jul 02, 2017 7:51 pm

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: 21
Joined: Wed Sep 30, 2015 2:14 pm
Country: -

Re: Script Language

Post by Hertz » Sun Jul 02, 2017 11:03 pm

Is there a test version of firmware for 9xtreme available so we could start porting the Lua scripts?

User avatar
MikeB
9x Developer
Posts: 14380
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Script Language

Post by MikeB » Sun Jul 02, 2017 11:11 pm

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.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
MikeB
9x Developer
Posts: 14380
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Script Language

Post by MikeB » Mon Jul 03, 2017 3:57 pm

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 20 times
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

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

Re: Script Language

Post by jhsa » Mon Jul 03, 2017 4:02 pm

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: 16563
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa » Tue Jul 04, 2017 3:42 pm

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: 14380
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Script Language

Post by MikeB » Tue Jul 04, 2017 5:22 pm

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.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

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

Re: Script Language

Post by jhsa » Tue Jul 04, 2017 5:57 pm

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: 14380
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Script Language

Post by MikeB » Tue Jul 04, 2017 9:43 pm

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.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
MikeB
9x Developer
Posts: 14380
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Script Language

Post by MikeB » Thu Jul 06, 2017 9:24 pm

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.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

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

Re: Script Language

Post by jhsa » Thu Jul 06, 2017 10:38 pm

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: 14380
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Script Language

Post by MikeB » Fri Jul 07, 2017 2:39 pm

"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 10 times
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

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

Re: Script Language

Post by jhsa » Fri Jul 07, 2017 3:00 pm

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: 1525
Joined: Sun Dec 16, 2012 7:24 pm
Country: United States
Location: New England, Vermont
Contact:

Re: Script Language

Post by bob195558 » Fri Jul 07, 2017 3:12 pm

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.
RADIOS: ErSky9x on Taranis, ErSky9x on Sky9x, ErSky9x on 9Xtreme,
Er9x-FrSky on 9x-Radio with Smartieparts upgrade Programmer Board and 9x-TelemetrEZ Board.
Some help info here: (http://openrcforums.com/forum/viewtopic.php?f=95&t=7182).
Bob B.

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

Re: Script Language

Post by jhsa » Fri Jul 07, 2017 4:10 pm

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: 1525
Joined: Sun Dec 16, 2012 7:24 pm
Country: United States
Location: New England, Vermont
Contact:

Re: Script Language

Post by bob195558 » Fri Jul 07, 2017 7:03 pm

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.
RADIOS: ErSky9x on Taranis, ErSky9x on Sky9x, ErSky9x on 9Xtreme,
Er9x-FrSky on 9x-Radio with Smartieparts upgrade Programmer Board and 9x-TelemetrEZ Board.
Some help info here: (http://openrcforums.com/forum/viewtopic.php?f=95&t=7182).
Bob B.

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

Re: Script Language

Post by jhsa » Fri Jul 07, 2017 9:02 pm

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: 14380
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Script Language

Post by MikeB » Fri Jul 07, 2017 9:09 pm

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.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

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

Re: Script Language

Post by jhsa » Fri Jul 07, 2017 9:19 pm

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: 14380
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Script Language

Post by MikeB » Thu Jul 13, 2017 11:38 am

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.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

User avatar
MikeB
9x Developer
Posts: 14380
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset

Re: Script Language

Post by MikeB » Sun Jul 16, 2017 7:42 pm

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.
ersky9x/er9x developer
The difficult we do immediately,
The impossible takes a little longer!

Post Reply

Return to “ersky9x”

Who is online

Users browsing this forum: No registered users and 6 guests