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

Re: Script Language

Post by MikeB »

This code looks suspicious to me:

Code: Select all

while idx <= 6
  if mspRxIdx <= mspRxSize	  
    temp = payload[idx]
    mspRxBuf[mspRxIdx]=temp
    mspRxCRC ^= payload[idx]
    mspRxIdx += 1
    idx += 1
  end
end
if idx is less than 6, but mspRxIdx is greater than mspRxSize then idx doesn't get incremented so the while loop runs forever.

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

flybabo
Posts: 143
Joined: Wed May 16, 2012 11:41 pm
Country: United States
Location: SF Bay Area, CA

Re: Script Language

Post by flybabo »

Mike,
Since most quad flyers move to F3/F4 based FC from old F1 based FC, you may find a "give-away" F1 based FC like Naze32 from your local quad flyers.
Beta-flight firmware developers committed to support those F1 based FCs up to version 3.2 (upcoming version) and they are good enough for your testing.
Or you may buy a popular Omnibus F3 AIO FC:
http://www.readytoflyquads.com/flip-32-f3-omnibus
https://www.banggood.com/Betaflight-F3- ... 86563.html
You can use it for the fixed wing models as well.
HT
User avatar
midelic
Posts: 128
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic »

@flybabo
for test this script no need an expensive FC there are available with 11USD with F3 chip that can run betaflight. I found even cheaper like 7-8 USd but have less USART pins available for Sport use.If a have already an old Naze with f1 chip you can run betaflight>3.1 to use MSP tunneling.
User avatar
midelic
Posts: 128
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic »

Mike,
I see break in while loop is not implemented, i tried to use and gives me error.
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 »

"break" is nothing more than a "goto"

The code:
while a < 5
...
...
end

is loaded and exectuted as:

loopstart:
if a < 5 is false then goto loopend
...
...
goto loopstart
loopend:
(where loopstart and loopend are hidden labels, actually implemented as just addresses).

so, at present, if you want to break from a while loop, you can use:

while a < 5
...
if ???? then goto break1
...
end
break1:

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

cutdact
Posts: 21
Joined: Tue Oct 04, 2016 7:28 am
Country: Finland

Re: Script Language

Post by cutdact »

Alright so i got to try my setup with LUA and a Taranis X9D+ and it looks like my receiver is bad, tried updating everything but still nothnig. So i've ordered a X4R receiver and hopefully that fixes my issue of not receiving properly.
User avatar
gizmatron
Posts: 40
Joined: Fri Jun 27, 2014 6:35 am
Country: France
Location: somewhere on the limits

Re: Script Language

Post by gizmatron »

I think I have an F3 board here mike I can flash to latest betaflight 3.2.1 and send you if you want.. it's a HGL F3 AIO with the onboard OSD the lot I think.. lost a motor pad and banggood refunded me so it's sat in a draw, only across the channel so be faster than china direct
cutdact
Posts: 21
Joined: Tue Oct 04, 2016 7:28 am
Country: Finland

Re: Script Language

Post by cutdact »

I've got a new receiver now so i can continue.

Mike, How can i solve a while loop with 2 expressions? ie. while x and y...
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 »

The following does work:

Code: Select all

a = 0
b = 2
while (a<5) & (b>0)
	a += 1
	if a>3 then b = 0
end
At the end of the while loop, a is 4 and b is 0.
Make sure the two tests are each in brackets.
The reason this works is that a test like (a<5) is an expression that results in a value of 0 (false) or 1 (true). The '&' operator ANDs two values together bitwise, so if both test result in 1, the AND of them is also 1, so the while test is true.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
pafleraf
Posts: 33
Joined: Mon Dec 07, 2015 9:04 am
Country: Germany

Re: Script Language

Post by pafleraf »

Hi Martin!

sorry for being such a pain-in-the-butt to you ;-) Next time I'll try without bit-operations. But seriously, if you have any trouble with the protocol, juts let me know, I should be able to help you. But please note that I use only opentx and frsky hardware, so that I can probably not test anything for you.

Cheers
Raphael.
cutdact wrote: Tue Sep 19, 2017 7:52 pm Thank you for clarifying. I think it's the application ID that is throwing me off here. In LUA they use a bunch of bitwise operations and i can't really get my head around why. https://github.com/betaflight/betafligh ... msp_sp.lua

for example:

sportMspSeq = bit32.band(sportMspSeq + 1, 0x0F)

Isnt this the same as sportMspSeq += 1, with a max value of 15?

so it could be solved like,

sportMspSeq += 1
if sportMspSeq = 15 then sportMspSeq = 0
end

Martin
pafleraf
Posts: 33
Joined: Mon Dec 07, 2015 9:04 am
Country: Germany

Re: Script Language

Post by pafleraf »

Hey Mike!

that's how the code looks like now:

Code: Select all

    while (idx <= protocol.maxRxBufferSize) and (mspRxIdx <= mspRxSize) do
        mspRxBuf[mspRxIdx] = payload[idx]
        mspRxCRC = bit32.bxor(mspRxCRC,payload[idx])
        mspRxIdx = mspRxIdx + 1
        idx = idx + 1
    end
whereby:

Code: Select all

  protocol.maxRxBufferSize = 6
in case Frsky Smartport is used.

By the way, thanks a lot for your very first smartport code based on software bit-banging on atmel uC, I'm still using it (slightly modified, but that would have worked without you).

Cheers
Raphael.
MikeB wrote: Thu Oct 05, 2017 2:41 pm This code looks suspicious to me:

Code: Select all

while idx <= 6
  if mspRxIdx <= mspRxSize	  
    temp = payload[idx]
    mspRxBuf[mspRxIdx]=temp
    mspRxCRC ^= payload[idx]
    mspRxIdx += 1
    idx += 1
  end
end
if idx is less than 6, but mspRxIdx is greater than mspRxSize then idx doesn't get incremented so the while loop runs forever.

Mike.
cutdact
Posts: 21
Joined: Tue Oct 04, 2016 7:28 am
Country: Finland

Re: Script Language

Post by cutdact »

pafleraf wrote: Tue Nov 14, 2017 4:06 pm Hi Martin!

sorry for being such a pain-in-the-butt to you ;-) Next time I'll try without bit-operations. But seriously, if you have any trouble with the protocol, juts let me know, I should be able to help you. But please note that I use only opentx and frsky hardware, so that I can probably not test anything for you.

[/quote]


Hi!

Oh not at all! It's simply my lack of knowledge that is slowing me down. I didnt fully understand the functions in your code thats all :) I'm starting to understand more and more now but i'm lacking time to work on it.

Thanks!

Martin
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 »

Could Script be used to reset Voice Messages being played ? :?:
If Voice Messages pileup with outdated messages, could we have them deleted,
so that Voice Messages would restart with new messages (up to date data)
by clicking a switch.

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
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'd need to create some code to flush the voice queue first. Possibly just need that function and the ability to assign a switch to it.

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 »

MikeB wrote: Tue Nov 21, 2017 2:24 pm Possibly just need that function and the ability to assign a switch to it.

Mike.
Probably Radio Setup / General??

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
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 »

Thank you Mike for looking at this.

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
gizmatron
Posts: 40
Joined: Fri Jun 27, 2014 6:35 am
Country: France
Location: somewhere on the limits

Re: Script Language

Post by gizmatron »

so is this language looking like it could give us LUA style contol for betaflight yet on the 9xr?
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

Yes, LUA style, but not LUA.. :) And not on the 9XR, maybe on the 9XR-PRO. The 9XR radio won't be able to support scripts.

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
midelic
Posts: 128
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic »

Hi,
I made finally a script for controlling PID/Rates in betaflight using ersky9x basic language.
I managed until now to send commands for reading PID and Rates.
However i did not succeed using write commands to change PIDs and Rates.

The main problem seems to be that I'm unable to detect when previous frames sending is complete and code is ready to send the next frame .
In LUA there is this check which I'm unable to find equivalence in ersky9X basic script.

Code: Select all

   if not sportTelemetryPush() then
      return true
   end
this one is checking the frame output see if busy before continuing with the next

BTW I tested this script with 9x pro and multiSTM32 module with multi firmware modified for sport bidirectional.My end goal is to make a complete solution for multi using ersky9x basic scripts.

see below a video with the script running.

https://youtu.be/cY6_ydG9oBY
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 »

sportTelemetrySend( 0xFF )
should return 0 if the send buffer is NOT available and 1 if it is available.
In any case, calling sportTelemetrySend() with all the needed parameters should still return 0 if it cannot send (buffer busy) and 1 if it is queued to go.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
User avatar
midelic
Posts: 128
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic »

Thanks Mike,
I just tested it and working I changed PID in in betaflight.
Awesome.
olivierhacking
Posts: 14
Joined: Sun Jan 10, 2016 8:44 am
Country: -

Re: Script Language

Post by olivierhacking »

Mike - thanks for all your work towards this scripting in Ersky9X.
I am running ersky9x on my 9xtreme board in the Turnigy 9X. Now I hope to run a script that allows me to work with my KISS FC and software. I see @midelic has used one for Betaflight successfully. Anyone know about the same for KISS setups?
Sterling101
Posts: 143
Joined: Sat Dec 02, 2017 10:32 am
Country: United Kingdom
Location: Nottingham, UK
Contact:

Re: Script Language

Post by Sterling101 »

Going right back to basics now but I'm trying to build a custom telemetry screen with a few calculations included but I'm struggling to get Tim1 to display in anything other than just seconds (eg. a 3 minute timer only displays as 180 using drawnumber).

Looking at the last script reference pdf there's a function called drawtimer which I thought might do the trick but I always get an error 109 if I try and use it so it seems it's not implemented in ersky9xr 221f7.

Is there anything I'm missing or do I simply need to apply a spot of maths to the timer before displaying it formatted after slicing it apart to get it into minutes and seconds?
Leigh

Current Kit:-
Taranis X9D plus running ErSkyTx - main radio.
Turnigy 9XR-Pro with internal FrSky DHT Module - used on the simulator.
Retired radios:-
Turnigy i10 with FlySky receivers.
Turnigy I6 - My first Tx now just used on Quads.
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'll check it out tomorrow, but:
drawtimer( x, y, value )
and:
drawtimer( x, y, value, attribute)
should work.
Make sure you use all lower case for the name "drawtimer".

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
Sterling101
Posts: 143
Joined: Sat Dec 02, 2017 10:32 am
Country: United Kingdom
Location: Nottingham, UK
Contact:

Re: Script Language

Post by Sterling101 »

Thanks Mike,

Will have another go tomorrow and see what I can come up with.
Leigh

Current Kit:-
Taranis X9D plus running ErSkyTx - main radio.
Turnigy 9XR-Pro with internal FrSky DHT Module - used on the simulator.
Retired radios:-
Turnigy i10 with FlySky receivers.
Turnigy I6 - My first Tx now just used on Quads.
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 »

OK, bug with drawtimer found and fixed. I'll post "f8" with this in in a few minutes.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
nico84
Posts: 6
Joined: Wed Dec 20, 2017 5:47 pm
Country: -

Re: Script Language

Post by nico84 »

midelic wrote: Thu Nov 30, 2017 11:39 pm Thanks Mike,
I just tested it and working I changed PID in in betaflight.
Awesome.
Cool. Can you make a Script to change vtx channel, Band and Power?
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Script Language

Post by jhsa »

Did you test it with the XJT module?

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
Sterling101
Posts: 143
Joined: Sat Dec 02, 2017 10:32 am
Country: United Kingdom
Location: Nottingham, UK
Contact:

Re: Script Language

Post by Sterling101 »

Thanks for the update Mike.
F8 is working fine now with drawtimer - now to work out the layout for the telemetry screen I'm looking into.
Leigh

Current Kit:-
Taranis X9D plus running ErSkyTx - main radio.
Turnigy 9XR-Pro with internal FrSky DHT Module - used on the simulator.
Retired radios:-
Turnigy i10 with FlySky receivers.
Turnigy I6 - My first Tx now just used on Quads.
nico84
Posts: 6
Joined: Wed Dec 20, 2017 5:47 pm
Country: -

Re: Script Language

Post by nico84 »

I tested the PID script with ar9x, xjt and r-xsr. It does not work. All PIDs are "0". Telemetry is working, I can read the Voltage from Betaflight.
ersky9x version is f8
Betaflight is 3.2

Post Reply

Return to “erskyTx (was ersky9x)”