Lua Telemetry scripts

openTx has introduced a range of new features, ideas and bling. It is fast becoming the firmware of choice for many users. openTx will run on ALL current hardware platforms, including the gruvin9x and sky9x boards. Work has already started to support the new FrSky X9D radio!
bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Lua Telemetry scripts

Post by bertrand35 »

This lib costs 4k RAM, is it really needed?

nicodh
Posts: 22
Joined: Mon Mar 12, 2012 10:38 pm
Country: -

Re: Lua Telemetry scripts

Post by nicodh »

Damn Bertrand, that would be awesome to be added in next versions. :-D

I'm trying to put some strings on a precise place of the screen and i hate to do it manually. :-( .

I also want to send a couple of data that i will decode on the script but also need the string functions. :-(
nicodh
Posts: 22
Joined: Mon Mar 12, 2012 10:38 pm
Country: -

Re: Lua Telemetry scripts

Post by nicodh »

bertrand35 wrote:This lib costs 4k RAM, is it really needed?

For me is, (and some 2 or 3 people trying to use the mikrokopter->frsky decoder).
nicodh
Posts: 22
Joined: Mon Mar 12, 2012 10:38 pm
Country: -

Re: Lua Telemetry scripts

Post by nicodh »

So it's just a define line to add the string functions?

Just adding:

#include <lstrlib.c>

should work?
bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Lua Telemetry scripts

Post by bertrand35 »

I will enable it in 2.1
You have to modify the Makefile and linit.c

nicodh
Posts: 22
Joined: Mon Mar 12, 2012 10:38 pm
Country: -

Re: Lua Telemetry scripts

Post by nicodh »

Ok thanks!
Helitamer
Posts: 7
Joined: Thu May 22, 2014 9:00 am
Country: -

Re: Lua Telemetry scripts

Post by Helitamer »

Hi,

i use the opentx firmware 2.0.8 (opentx-taranis-haptic-lua-de-2.0.8.bin) and copy the lua script into this folder \SCRIPTS\DJI F550\tele2.lua but it do not work? i only see three telemetry screens.. is it necessary activate lua scripting ? Firmware Lua option is enabled..

possible the blank inside the model name DJI F550 is a problem?

regards Patrick
paulj
Posts: 22
Joined: Sun Jun 29, 2014 8:20 am
Country: -

Re: Lua Telemetry scripts

Post by paulj »

Helitamer wrote:Hi,

i use the opentx firmware 2.0.8 (opentx-taranis-haptic-lua-de-2.0.8.bin) and copy the lua script into this folder \SCRIPTS\DJI F550\tele2.lua but it do not work? i only see three telemetry screens.. is it necessary activate lua scripting ? Firmware Lua option is enabled..

possible the blank inside the model name DJI F550 is a problem?

regards Patrick

The blank in the name is a problem, based on my experience. Also, the script should be called telem2.lua, not tele2.lua

Rgds.,
Paul
User avatar
Kilrah
Posts: 11109
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Lua Telemetry scripts

Post by Kilrah »

DJI_F550.

Sent via mobile
Helitamer
Posts: 7
Joined: Thu May 22, 2014 9:00 am
Country: -

Re: Lua Telemetry scripts

Post by Helitamer »

Thx, now it works if i replace the blank..
bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Lua Telemetry scripts

Post by bertrand35 »

For the same reason than the Naze32, OpenTX is not compatible with DJI 550 :)
nicodh
Posts: 22
Joined: Mon Mar 12, 2012 10:38 pm
Country: -

Re: Lua Telemetry scripts

Post by nicodh »

Hello Bertrand, I have a new awesome stupid question concerning lua scripts.

If i use a lua custom script, can i use the values from him in a telemetry script?

I'm thinking on using the variables created from Fig newton gheading script into my telemetry script, so i can use the home heading.

another way is to include the gheading script into my lua script and adapt it.

What do you think is the best thing?

Thanks!
lvale
Posts: 13
Joined: Thu Oct 11, 2012 1:31 am
Country: -

Re: Lua Telemetry scripts

Post by lvale »

You only need lines 115 to 131 from the gheading script to achieve a Course to Home feature.

I've opened a issue on OpenTX github and Bertrand kept it open.
https://github.com/opentx/opentx/issues/1581
nicodh
Posts: 22
Joined: Mon Mar 12, 2012 10:38 pm
Country: -

Re: Lua Telemetry scripts

Post by nicodh »

thanks for that info!
that is perfect.
jlsalas
Posts: 6
Joined: Sat Aug 09, 2014 11:24 pm
Country: -

Re: Lua Telemetry scripts

Post by jlsalas »

Hi Friends, I am quite knew with Lua and I need some help.
I use the script Telem2.lua which show me both the "altitude" and "altitude-max" from the vario on my TX screen.
I practice F5J altimeter and I have a RC Electronics basic 2 altimeter on board, which show the official FAI altitude, but I have a difference about 25 m between the altimeter 2 and the vario altitude, so I am thinking about to increase in 25 m the values that the script shows on my TX.
As you know the script is:
lcd.drawNumber(210, 10, getValue("altitude"), XXLSIZE)
lcd.drawText(150, 54, "MAX", 0)
lcd.drawChannel(172, 54, "altitude-max", LEFT)

I suppose that I need to create two new variables that increase the "altitude" and "altitude-max" in 25 metres, and show on the screen these new variables. I don't know how to do it and if it is possible to do that.
Could you help me
thanks in advance
Jose
User avatar
Kilrah
Posts: 11109
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Lua Telemetry scripts

Post by Kilrah »

lcd.drawNumber(210, 10, getValue("altitude")+25, XXLSIZE) ?
jlsalas
Posts: 6
Joined: Sat Aug 09, 2014 11:24 pm
Country: -

Re: Lua Telemetry scripts

Post by jlsalas »

Thanks Klirah, it works, now I can see the new altitude on the screen.
The voice of the TX is still reading aloud the value "Alt" when I press a switch, I don't know if I be able to change that.
User avatar
Kilrah
Posts: 11109
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Lua Telemetry scripts

Post by Kilrah »

Nope. Unless you do the audio play from the script too with the same correction instead of using the built-in method.

Sent via mobile
a944734
Posts: 7
Joined: Mon Jan 13, 2014 4:26 pm
Country: -

Re: Lua Telemetry scripts

Post by a944734 »

Can someone give me a pointer to all the telemetry "channels" there are to be read and then used in scripting.
So far I have seen two different call methods, to my surprise they both seem to get the same values

Variant 1
altitude = getValue("altitude")

Variant 2
CurrentAlt = getValue(206)

Thanks a lot in advance
User avatar
Kilrah
Posts: 11109
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Lua Telemetry scripts

Post by Kilrah »

http://www.open-tx.org/2014/07/19/Lua-reference-guide/

"altitude" is simply a constant that equals 206 to make things simpler. These were added recently.
nicodh
Posts: 22
Joined: Mon Mar 12, 2012 10:38 pm
Country: -

Re: Lua Telemetry scripts

Post by nicodh »

I'm having an issue with a telemetry script (the same as allways).

I need to use a function to convert an integer into a binary string. I'm trying to use the for do sentence, but it seems not to be working... Is it available?
this is the function:

Code: Select all

function NumberToStringBytes(num,optionalNumberOfBytes)
 
local retString=""
optionalNumberOfBytes = optionalNumberOfBytes or 4
 
for i=1,optionalNumberOfBytes do
retString = string.char(num%256) .. retString
num = math.floor(num/256)
end


return retString
 
end
thanks
nicodh
Posts: 22
Joined: Mon Mar 12, 2012 10:38 pm
Country: -

Re: Lua Telemetry scripts

Post by nicodh »

I will answer myself.... the string module is not loaded in the opentx, so i cant do the string.char()...
nicodh
Posts: 22
Joined: Mon Mar 12, 2012 10:38 pm
Country: -

Re: Lua Telemetry scripts

Post by nicodh »

And i resolve it. It's a bit of a hack but seems to work.
it will return a 8 bits string from a number. :-)
Now i can continue.

Code: Select all

function tobits(num)
 	local retString=""
	local i = 8
	while i >= 0 do
		if math.floor(num /(2^i)) >= 1 then
			retString = retString .."1"
			num = num-math.pow(2,i)
		else 
			retString = retString .. "0"
		end
		i = i-1
	end 
	return retString
end
bertrand35
9x Developer
Posts: 2764
Joined: Fri Dec 30, 2011 11:11 pm
Country: -

Re: Lua Telemetry scripts

Post by bertrand35 »

I recently integrated the LTR patch to Lua. It allowed us to add the bitlib library without using more RAM. Perhaps we could do the same with stringlib. It would only cost more flash, but I think we have some available
nicodh
Posts: 22
Joined: Mon Mar 12, 2012 10:38 pm
Country: -

Re: Lua Telemetry scripts

Post by nicodh »

Hello Bertrand, after some time without touching my script (that works. :-D ) I want to do some changes. I want to be able to change a global variable value or a logical switch. The logical switch need to change depending on what i receive from telemetry and will start and stop the Timer. For now i'm using stick system that works but i want to try the telemetry way.
I see that i could use the model.setLogicalSwitch but maybe it could be easier to just change a GV with model.setGlobalVariable and keep the logical hardcoded same as now.
Is there an example of the setLogicalSwitch?
Thanks

Post Reply

Return to “openTx”