Script Language

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

Re: Script Language

Post by MikeB » 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.
ersky9x/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 » Thu Oct 05, 2017 6:02 pm

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

Re: Script Language

Post by midelic » Thu Oct 05, 2017 6:54 pm

@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: 77
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic » Thu Oct 12, 2017 7:01 pm

Mike,
I see break in while loop is not implemented, i tried to use and gives me error.

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

Re: Script Language

Post by MikeB » Thu Oct 12, 2017 10:30 pm

"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.
ersky9x/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 » Wed Oct 18, 2017 12:51 pm

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 » Thu Oct 19, 2017 11:45 pm

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 » Tue Nov 07, 2017 10:33 am

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

Re: Script Language

Post by MikeB » Tue Nov 07, 2017 1:08 pm

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

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

Re: Script Language

Post by pafleraf » 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.

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: 24
Joined: Mon Dec 07, 2015 9:04 am
Country: Germany

Re: Script Language

Post by pafleraf » Tue Nov 14, 2017 4:13 pm

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 » Tue Nov 14, 2017 9:33 pm

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

Re: Script Language

Post by bob195558 » Tue Nov 21, 2017 12:12 pm

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.
ErSky9x on Taranis, Sky9x, 9Xtreme, Er9x on 9x with Smartieparts Programmer with TelemetrEZ Board
3D Printing: (http://openrcforums.com/forum/viewforum.php?f=85)

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

Re: Script Language

Post by MikeB » Tue Nov 21, 2017 2:24 pm

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

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

Re: Script Language

Post by jhsa » Tue Nov 21, 2017 2:54 pm

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

Re: Script Language

Post by bob195558 » Tue Nov 21, 2017 4:39 pm

Thank you Mike for looking at this.

Bob B.
ErSky9x on Taranis, Sky9x, 9Xtreme, Er9x on 9x with Smartieparts Programmer with TelemetrEZ Board
3D Printing: (http://openrcforums.com/forum/viewforum.php?f=85)

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 » Thu Nov 30, 2017 8:51 pm

so is this language looking like it could give us LUA style contol for betaflight yet on the 9xr?

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

Re: Script Language

Post by jhsa » Thu Nov 30, 2017 9:10 pm

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

Re: Script Language

Post by midelic » Thu Nov 30, 2017 10:05 pm

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

Re: Script Language

Post by MikeB » Thu Nov 30, 2017 10:55 pm

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

User avatar
midelic
Posts: 77
Joined: Mon Dec 23, 2013 9:57 pm
Country: -

Re: Script Language

Post by midelic » Thu Nov 30, 2017 11:39 pm

Thanks Mike,
I just tested it and working I changed PID in in betaflight.
Awesome.

olivierhacking
Posts: 11
Joined: Sun Jan 10, 2016 8:44 am
Country: -

Re: Script Language

Post by olivierhacking » Fri Dec 08, 2017 10:19 am

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

Re: Script Language

Post by Sterling101 » Tue Dec 19, 2017 11:39 pm

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:-
Turnigy 9XR-Pro with MultiModule and internal FrSky DHT Module - the new go to radio.
Turnigy i10 with FlySky receivers - old work horse now being retired bit by bit.
Turnigy I6 - My first Tx now just used on Quads.

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

Re: Script Language

Post by MikeB » Wed Dec 20, 2017 12:12 am

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

Sterling101
Posts: 116
Joined: Sat Dec 02, 2017 10:32 am
Country: United Kingdom
Location: Nottingham, UK
Contact:

Re: Script Language

Post by Sterling101 » Wed Dec 20, 2017 12:18 am

Thanks Mike,

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

Current Kit:-
Turnigy 9XR-Pro with MultiModule and internal FrSky DHT Module - the new go to radio.
Turnigy i10 with FlySky receivers - old work horse now being retired bit by bit.
Turnigy I6 - My first Tx now just used on Quads.

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

Re: Script Language

Post by MikeB » Wed Dec 20, 2017 11:58 am

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

Mike.
ersky9x/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 » Wed Dec 20, 2017 5:50 pm

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

Re: Script Language

Post by jhsa » Wed Dec 20, 2017 8:22 pm

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

Re: Script Language

Post by Sterling101 » Wed Dec 20, 2017 9:42 pm

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:-
Turnigy 9XR-Pro with MultiModule and internal FrSky DHT Module - the new go to radio.
Turnigy i10 with FlySky receivers - old work horse now being retired bit by bit.
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 » Thu Dec 21, 2017 5:53 pm

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 “ersky9x”