Page 5 of 12

Re: Script Language

Posted: Thu Oct 05, 2017 2:41 pm
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.

Re: Script Language

Posted: Thu Oct 05, 2017 6:02 pm
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

Re: Script Language

Posted: Thu Oct 05, 2017 6:54 pm
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.

Re: Script Language

Posted: Thu Oct 12, 2017 7:01 pm
by midelic
Mike,
I see break in while loop is not implemented, i tried to use and gives me error.

Re: Script Language

Posted: Thu Oct 12, 2017 10:30 pm
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.

Re: Script Language

Posted: Wed Oct 18, 2017 12:51 pm
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.

Re: Script Language

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

Re: Script Language

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

Re: Script Language

Posted: Tue Nov 07, 2017 1:08 pm
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.

Re: Script Language

Posted: Tue Nov 14, 2017 4:06 pm
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

Re: Script Language

Posted: Tue Nov 14, 2017 4:13 pm
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.

Re: Script Language

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

Re: Script Language

Posted: Tue Nov 21, 2017 12:12 pm
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.

Re: Script Language

Posted: Tue Nov 21, 2017 2:24 pm
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.

Re: Script Language

Posted: Tue Nov 21, 2017 2:54 pm
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

Re: Script Language

Posted: Tue Nov 21, 2017 4:39 pm
by bob195558
Thank you Mike for looking at this.

Bob B.

Re: Script Language

Posted: Thu Nov 30, 2017 8:51 pm
by gizmatron
so is this language looking like it could give us LUA style contol for betaflight yet on the 9xr?

Re: Script Language

Posted: Thu Nov 30, 2017 9:10 pm
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

Re: Script Language

Posted: Thu Nov 30, 2017 10:05 pm
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

Re: Script Language

Posted: Thu Nov 30, 2017 10:55 pm
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.

Re: Script Language

Posted: Thu Nov 30, 2017 11:39 pm
by midelic
Thanks Mike,
I just tested it and working I changed PID in in betaflight.
Awesome.

Re: Script Language

Posted: Fri Dec 08, 2017 10:19 am
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?

Re: Script Language

Posted: Tue Dec 19, 2017 11:39 pm
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?

Re: Script Language

Posted: Wed Dec 20, 2017 12:12 am
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.

Re: Script Language

Posted: Wed Dec 20, 2017 12:18 am
by Sterling101
Thanks Mike,

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

Re: Script Language

Posted: Wed Dec 20, 2017 11:58 am
by MikeB
OK, bug with drawtimer found and fixed. I'll post "f8" with this in in a few minutes.

Mike.

Re: Script Language

Posted: Wed Dec 20, 2017 5:50 pm
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?

Re: Script Language

Posted: Wed Dec 20, 2017 8:22 pm
by jhsa
Did you test it with the XJT module?

Thanks

João

Re: Script Language

Posted: Wed Dec 20, 2017 9:42 pm
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.

Re: Script Language

Posted: Thu Dec 21, 2017 5:53 pm
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