Lua Telemetry scripts
-
- 9x Developer
- Posts: 2764
- Joined: Fri Dec 30, 2011 11:11 pm
- Country: -
Lua Telemetry scripts
One very simple example that will work in next release (2.0.6)
Re: Lua Telemetry scripts
Awesome!! I keep saying this, and will say it again, this going to be a major game changer...
Re: Lua Telemetry scripts
Hello,
I'm trying to create a telemetry script, but i only get a blank screen. For now i was trying to make some lines.
I see your telemetry example does not work with 2.05 firmware right? I tried and got blank screen too.
When do you think it will be able to start working with them?
Thanks!
I'm trying to create a telemetry script, but i only get a blank screen. For now i was trying to make some lines.
I see your telemetry example does not work with 2.05 firmware right? I tried and got blank screen too.
When do you think it will be able to start working with them?
Thanks!
-
- 9x Developer
- Posts: 2764
- Joined: Fri Dec 30, 2011 11:11 pm
- Country: -
Re: Lua Telemetry scripts
The one above works with 2.0.6 for a couple of reasons, one of them is the XXL font which was introduced in 2.0.6
-
- 9x Developer
- Posts: 2764
- Joined: Fri Dec 30, 2011 11:11 pm
- Country: -
Re: Lua Telemetry scripts
Don't hesitate to paste your script here, I will try to help
Re: Lua Telemetry scripts
Hi Bertrand,
thanks!
I managed (with some help on rcgroups) to make the display working.
I can now, make my screen division and add some stuff there. Timer is working, and altitude too.
My idea is getting all those data from the mk (using a converter of course, because mk does not speak frsky).
I was looking at the lua.cpp code and there is little data that we can read from telemetry. But i also found that everything is more or less ready.
If the rest of the telemetry data is included in the liaField, it should work? Or I am missing something else?
thanks!
I managed (with some help on rcgroups) to make the display working.
I can now, make my screen division and add some stuff there. Timer is working, and altitude too.
My idea is getting all those data from the mk (using a converter of course, because mk does not speak frsky).
I was looking at the lua.cpp code and there is little data that we can read from telemetry. But i also found that everything is more or less ready.
Code: Select all
static void luaGetValueAndPush(int src)
{
/*
Hint about dividers are taken from putsTelemetryChannel()
*/
if (!TELEMETRY_STREAMING() && src>=MIXSRC_FIRST_TELEM && src<=MIXSRC_LAST_TELEM) {
//telemetry not working, return zero for telemetry sources
lua_pushinteger(L, (int)0);
return;
}
switch (src) {
case MIXSRC_FIRST_TELEM-1+TELEM_TX_VOLTAGE:
case MIXSRC_FIRST_TELEM-1+TELEM_VFAS:
case MIXSRC_FIRST_TELEM-1+TELEM_MIN_VFAS:
case MIXSRC_FIRST_TELEM-1+TELEM_CELLS_SUM:
case MIXSRC_FIRST_TELEM-1+TELEM_MIN_CELLS_SUM:
case MIXSRC_FIRST_TELEM-1+TELEM_CURRENT:
case MIXSRC_FIRST_TELEM-1+TELEM_MAX_CURRENT:
case MIXSRC_FIRST_TELEM-1+TELEM_VSPEED:
//theese need to be divided by 10
lua_pushnumber(L, getValue(src)/10.0);
break;
case MIXSRC_FIRST_TELEM-1+TELEM_A1:
case MIXSRC_FIRST_TELEM-1+TELEM_A2:
//convert raw A1/2 values to calibrated values
lua_pushnumber(L, applyChannelRatio(src-(MIXSRC_FIRST_TELEM-1+TELEM_A1), getValue(src))/100.0);
break;
case MIXSRC_FIRST_TELEM-1+TELEM_MIN_A1:
case MIXSRC_FIRST_TELEM-1+TELEM_MIN_A2:
//convert raw A1/2 values to calibrated values
lua_pushnumber(L, applyChannelRatio(src-(MIXSRC_FIRST_TELEM-1+TELEM_MIN_A1), getValue(src))/100.0);
break;
case MIXSRC_FIRST_TELEM-1+TELEM_CELL:
case MIXSRC_FIRST_TELEM-1+TELEM_MIN_CELL:
case MIXSRC_FIRST_TELEM-1+TELEM_ALT:
case MIXSRC_FIRST_TELEM-1+TELEM_ACCx:
case MIXSRC_FIRST_TELEM-1+TELEM_ACCy:
case MIXSRC_FIRST_TELEM-1+TELEM_ACCz:
//theese need to be divided by 100
lua_pushnumber(L, getValue(src)/100.0);
break;
//TODO: add other values that need special treatment
default:
lua_pushinteger(L, getValue(src));
}
}
struct LuaField {
const char * name;
const uint8_t id;
const uint8_t attr;
};
const LuaField luaFields[] = {
{ "altitude-max", MIXSRC_FIRST_TELEM+TELEM_MAX_ALT-1, 0 },
{ "altitude", MIXSRC_FIRST_TELEM+TELEM_ALT-1, PREC2 },
{ "vario", MIXSRC_FIRST_TELEM+TELEM_VSPEED-1, PREC2 },
{ "tx-voltage", MIXSRC_FIRST_TELEM+TELEM_TX_VOLTAGE-1, PREC1 },
{ "rpm", MIXSRC_FIRST_TELEM+TELEM_RPM-1, 0 },
{ NULL, 0, 0 },
};
-
- 9x Developer
- Posts: 2764
- Joined: Fri Dec 30, 2011 11:11 pm
- Country: -
Re: Lua Telemetry scripts
Nice screen! This array is new as I introduced it in 2.0.6, a lot of strings could be added there, what do you need?
https://github.com/opentx/opentx/issues/1480
https://github.com/opentx/opentx/issues/1480
Re: Lua Telemetry scripts
Bertrand, is possible to have all of them? I mean all the frsky telemetry data can send... Why? Because i need to be able to use for other things, like showing the error codes mikrokopter can send (i will convert the value to string so it will appear on the bottom like the graupner does).
So if i fill the array, it could work? I should try to build the opentx next branch myself (it should be mature for my needs right?).
and again Thanks!
So if i fill the array, it could work? I should try to build the opentx next branch myself (it should be mature for my needs right?).
and again Thanks!
-
- 9x Developer
- Posts: 2764
- Joined: Fri Dec 30, 2011 11:11 pm
- Country: -
Re: Lua Telemetry scripts
Yes it's the right way to proceed, when you have something interesting please open a pull request, I will merge it into 'next'
Re: Lua Telemetry scripts
Hello Bertrand, I just add some lines to the lua.cpp to see if i can add more stuff on the telemetry screen.
I think i found some bug on it (or unfinished stuff). My version builds. but i need to test it. If i build simu i can test it on pc right?
edit:
simu does not work....
i tried and i get a screen that is not complete (linux) ...
edit 2:
i must need to change something else, flashed the firmware on the taranis and lua interpreter does not work anymore.
These are my changes:
and
Am i missing something?
I think i found some bug on it (or unfinished stuff). My version builds. but i need to test it. If i build simu i can test it on pc right?
edit:
simu does not work....
i tried and i get a screen that is not complete (linux) ...
edit 2:
i must need to change something else, flashed the firmware on the taranis and lua interpreter does not work anymore.
These are my changes:
Code: Select all
case MIXSRC_FIRST_TELEM-1+TELEM_A1:
lua_pushnumber(L, applyChannelRatio(src-(MIXSRC_FIRST_TELEM-1+TELEM_A1), getValue(src))/100.0);
break;
case MIXSRC_FIRST_TELEM-1+TELEM_A2:
//convert raw A1/2 values to calibrated values
lua_pushnumber(L, applyChannelRatio(src-(MIXSRC_FIRST_TELEM-1+TELEM_A2), getValue(src))/100.0);
break;
case MIXSRC_FIRST_TELEM-1+TELEM_MIN_A1:
lua_pushnumber(L, applyChannelRatio(src-(MIXSRC_FIRST_TELEM-1+TELEM_MIN_A1), getValue(src))/100.0);
break ;
case MIXSRC_FIRST_TELEM-1+TELEM_MIN_A2:
//convert raw A1/2 values to calibrated values
lua_pushnumber(L, applyChannelRatio(src-(MIXSRC_FIRST_TELEM-1+TELEM_MIN_A2), getValue(src))/100.0);
break;
Code: Select all
const LuaField luaFields[] = {
{ "altitude-max", MIXSRC_FIRST_TELEM+TELEM_MAX_ALT-1, 0 },
{ "altitude", MIXSRC_FIRST_TELEM+TELEM_ALT-1, PREC2 },
{ "vario", MIXSRC_FIRST_TELEM+TELEM_VSPEED-1, PREC2 },
{ "tx-voltage", MIXSRC_FIRST_TELEM+TELEM_TX_VOLTAGE-1, PREC1 },
{ "rpm", MIXSRC_FIRST_TELEM+TELEM_RPM-1, 0 },
{ "vfas", MIXSRC_FIRST_TELEM+TELEM_VFAS-1, 0 },
{ "vfas-min", MIXSRC_FIRST_TELEM+TELEM_MIN_VFAS-1, 0 },
{ "cells", MIXSRC_FIRST_TELEM+TELEM_CELLS_SUM-1, 0 },
{ "cell-min", MIXSRC_FIRST_TELEM+TELEM_MIN_CELLS-1, 0 },
{ "current", MIXSRC_FIRST_TELEM+TELEM_CURRENT-1, 0 },
{ "current-max", MIXSRC_FIRST_TELEM+TELEM_MAX_CURRENT-1, 0 },
{ "A1", MIXSRC_FIRST_TELEM+TELEM_TELEM_A1-1, 0 },
{ "A1-min", MIXSRC_FIRST_TELEM+TELEM_TELEM_A1_MIN-1, 0 },
{ "A2", MIXSRC_FIRST_TELEM+TELEM_TELEM_A2-1, 0 },
{ "A2-min", MIXSRC_FIRST_TELEM+TELEM_TELEM_A2_MIN-1, 0 },
{ "cell", MIXSRC_FIRST_TELEM+TELEM_TELEM_CELL-1, 0 },
{ "cell-min", MIXSRC_FIRST_TELEM+TELEM_TELEM_MIN_CELL-1, 0 },
{ "accx", MIXSRC_FIRST_TELEM+TELEM_TELEM_ACCx-1, 0 },
{ "accy", MIXSRC_FIRST_TELEM+TELEM_TELEM_ACCy-1, 0 },
{ "accz", MIXSRC_FIRST_TELEM+TELEM_TELEM_ACCz-1, 0 },
{ NULL, 0, 0 },
};
-
- 9x Developer
- Posts: 2764
- Joined: Fri Dec 30, 2011 11:11 pm
- Country: -
Re: Lua Telemetry scripts
Which is your make command? Didn't you forget to enable Lua with LUA=YES?
Re: Lua Telemetry scripts
oh bertrand, i thik yes.
My make was just make PCB=TARANIS.
so i should put make PCB=TARANIS LUA= YES?
My make was just make PCB=TARANIS.
so i should put make PCB=TARANIS LUA= YES?
-
- 9x Developer
- Posts: 2764
- Joined: Fri Dec 30, 2011 11:11 pm
- Country: -
Re: Lua Telemetry scripts
Yes (except the space between = and YES)
Re: Lua Telemetry scripts
it's building now... the code i put has some errors.
i'm seeing that now that lua code builds.
i'm seeing that now that lua code builds.
Re: Lua Telemetry scripts
ok, it builds, and runs. lua works. at least with old script. I need to look if the scripts does something more with the new params i added. it's a pity i cant build the simulator to test on computer right away.
-
- 9x Developer
- Posts: 2764
- Joined: Fri Dec 30, 2011 11:11 pm
- Country: -
Re: Lua Telemetry scripts
Yes of course the simulator does work with Lua scripts, it would be completely crazy to have to flash each time I change something!
Re: Lua Telemetry scripts
yes i know, that is how i tested my first lua script. But since i modded the firmware (still does'nt work with my additions) i need to build companion too right? Or just simu is enough? I tried simu as in the wiki but it does not seems complete.
-
- 9x Developer
- Posts: 2764
- Joined: Fri Dec 30, 2011 11:11 pm
- Country: -
Re: Lua Telemetry scripts
Yes simu is the tool I use, as it is really quick to compile (on Linux)
Re: Lua Telemetry scripts
Is it just me or are people being really impatient about all of this? I am not downplaying any extra work that's done, but Bertrand, feel free to state that you just need time to flesh all of this out if that's the case. If you need coding help, I would be willing to see if I could help out myself, but understand if it's just muddying up the water.
Re: Lua Telemetry scripts
These are my changes in lua.cpp:
and
But i'm missing something because it give me a blank screen when trying to use the 'new' values for telemetrie using getValue on the script.
Maybe i'm wrong about the precision (the third value on the array) or I'm doing everything wrong (probably). Any idea?
And bertrand, when i have a virtualbox with linux where i build opentx, but i cant build the simu correctly and use it. It builds, but when i run it,~/simu i get a screen with some sliders but no buttons and not working.
Code: Select all
static void luaGetValueAndPush(int src)
{
/*
Hint about dividers are taken from putsTelemetryChannel()
*/
if (!TELEMETRY_STREAMING() && src>=MIXSRC_FIRST_TELEM && src<=MIXSRC_LAST_TELEM) {
//telemetry not working, return zero for telemetry sources
lua_pushinteger(L, (int)0);
return;
}
switch (src) {
case MIXSRC_FIRST_TELEM-1+TELEM_TX_VOLTAGE:
case MIXSRC_FIRST_TELEM-1+TELEM_VFAS:
case MIXSRC_FIRST_TELEM-1+TELEM_MIN_VFAS:
case MIXSRC_FIRST_TELEM-1+TELEM_CELLS_SUM:
case MIXSRC_FIRST_TELEM-1+TELEM_MIN_CELLS_SUM:
case MIXSRC_FIRST_TELEM-1+TELEM_CURRENT:
case MIXSRC_FIRST_TELEM-1+TELEM_MAX_CURRENT:
case MIXSRC_FIRST_TELEM-1+TELEM_VSPEED:
//theese need to be divided by 10
lua_pushnumber(L, getValue(src)/10.0);
break;
case MIXSRC_FIRST_TELEM-1+TELEM_A1:
lua_pushnumber(L, applyChannelRatio(src-(MIXSRC_FIRST_TELEM-1+TELEM_A1), getValue(src))/100.0);
break;
case MIXSRC_FIRST_TELEM-1+TELEM_A2:
//convert raw A1/2 values to calibrated values
lua_pushnumber(L, applyChannelRatio(src-(MIXSRC_FIRST_TELEM-1+TELEM_A2), getValue(src))/100.0);
break;
case MIXSRC_FIRST_TELEM-1+TELEM_MIN_A1:
lua_pushnumber(L, applyChannelRatio(src-(MIXSRC_FIRST_TELEM-1+TELEM_MIN_A1), getValue(src))/100.0);
break ;
case MIXSRC_FIRST_TELEM-1+TELEM_MIN_A2:
//convert raw A1/2 values to calibrated values
lua_pushnumber(L, applyChannelRatio(src-(MIXSRC_FIRST_TELEM-1+TELEM_MIN_A2), getValue(src))/100.0);
break;
case MIXSRC_FIRST_TELEM-1+TELEM_CELL:
case MIXSRC_FIRST_TELEM-1+TELEM_MIN_CELL:
case MIXSRC_FIRST_TELEM-1+TELEM_ALT:
case MIXSRC_FIRST_TELEM-1+TELEM_ACCx:
case MIXSRC_FIRST_TELEM-1+TELEM_ACCy:
case MIXSRC_FIRST_TELEM-1+TELEM_ACCz:
//theese need to be divided by 100
lua_pushnumber(L, getValue(src)/100.0);
break;
//TODO: add other values that need special treatment
default:
lua_pushinteger(L, getValue(src));
}
}
Code: Select all
const LuaField luaFields[] = {
{ "altitude-max", MIXSRC_FIRST_TELEM+TELEM_MAX_ALT-1, 0 },
{ "altitude", MIXSRC_FIRST_TELEM+TELEM_ALT-1, PREC2 },
{ "vario", MIXSRC_FIRST_TELEM+TELEM_VSPEED-1, PREC2 },
{ "tx-voltage", MIXSRC_FIRST_TELEM+TELEM_TX_VOLTAGE-1, PREC1 },
{ "rpm", MIXSRC_FIRST_TELEM+TELEM_RPM-1, 0 },
{ "vfas", MIXSRC_FIRST_TELEM+TELEM_VFAS-1, 0 },
{ "vfas-min", MIXSRC_FIRST_TELEM+TELEM_MIN_VFAS-1, 0 },
{ "cells", MIXSRC_FIRST_TELEM+TELEM_CELLS_SUM-1, 0 },
{ "cell-min", MIXSRC_FIRST_TELEM+TELEM_MIN_CELL-1, 0 },
{ "cell", MIXSRC_FIRST_TELEM+TELEM_CELL-1, 0 },
{ "current", MIXSRC_FIRST_TELEM+TELEM_CURRENT-1, 0 },
{ "current-max", MIXSRC_FIRST_TELEM+TELEM_MAX_CURRENT-1, 0 },
{ "A1", MIXSRC_FIRST_TELEM+TELEM_A1-1, 0 },
{ "A1-min", MIXSRC_FIRST_TELEM+TELEM_MIN_A1-1, 0 },
{ "A2", MIXSRC_FIRST_TELEM+TELEM_A2-1, 0 },
{ "A2-min", MIXSRC_FIRST_TELEM+TELEM_MIN_A2-1, 0 },
{ "accx", MIXSRC_FIRST_TELEM+TELEM_ACCx-1, 0 },
{ "accy", MIXSRC_FIRST_TELEM+TELEM_ACCy-1, 0 },
{ "accz", MIXSRC_FIRST_TELEM+TELEM_ACCz-1, 0 },
{ NULL, 0, 0 },
};
Maybe i'm wrong about the precision (the third value on the array) or I'm doing everything wrong (probably). Any idea?
And bertrand, when i have a virtualbox with linux where i build opentx, but i cant build the simu correctly and use it. It builds, but when i run it,~/simu i get a screen with some sliders but no buttons and not working.
Re: Lua Telemetry scripts
Hello Bertrand, i was looking at the code, trying to find why my md and latest script still does not work.
Maybe i should fill luaGetValueAndPush
with the proper
lua_pushnumber(L, getValue(src)/10.0); (this is an example)
for each case?
And also put the right precision type on luaFields? I know where to find that (it's a little confusing with all the defines but i can find it).
Thanks.
Maybe i should fill luaGetValueAndPush
with the proper
lua_pushnumber(L, getValue(src)/10.0); (this is an example)
for each case?
And also put the right precision type on luaFields? I know where to find that (it's a little confusing with all the defines but i can find it).
Thanks.
Re: Lua Telemetry scripts
@nicodh, the stuff that you are changing is already done on the other branch and will eventualy be integrated into the next branch. You can find it here https://github.com/opentx/opentx/tree/p ... issue_1480 and https://github.com/opentx/opentx/issues/1480
projectkk2glider@github
Re: Lua Telemetry scripts
Hi dinamich, i tried yesterday your field ids and they works!
Thanks a lot that makes everything easier.
Thanks a lot that makes everything easier.
Re: Lua Telemetry scripts
The is great - thanks! I have been playing around today and have made a simple telemetry script for my quadcopter.
"Attitude" refers to the flight mode, and is changed according to SA position. It is work in progress - there will be more information on the right hand side (RSSI and LiPo state) once I have worked out how to access the data, and I have worked out how to get the LiPo voltage into telemetry.
My question is this: How do I get the RSSI information (specifically), and generally, where do I find the content of the general settings array?
For interest:
I am happy to provide the Taranis program for the quad if that would be useful to anyone (it's very basic, as the magic is programmed in the OpenPilot CC3D unit)
"Attitude" refers to the flight mode, and is changed according to SA position. It is work in progress - there will be more information on the right hand side (RSSI and LiPo state) once I have worked out how to access the data, and I have worked out how to get the LiPo voltage into telemetry.
My question is this: How do I get the RSSI information (specifically), and generally, where do I find the content of the general settings array?
For interest:
Code: Select all
-- This helps me move the individual elements around the screen without having to recalculate all the coodinates!
local timer_xoffset = 5
local timer_yoffset = 4
local tx_x = 5
local tx_y = 48
local function run(event)
local timer = model.getTimer(0)
lcd.drawTimer(timer_xoffset,timer_yoffset,timer.value,XXLSIZE)
lcd.drawRectangle(timer_xoffset - 2,timer_yoffset - 2,111,42)
lcd.drawChannel(tx_x, tx_y, "tx-voltage", LEFT+MIDSIZE)
local txt_x = lcd.getLastPos()
local settings = getGeneralSettings()
local percent = (getValue("tx-voltage")-settings.battMin) * 100 / (settings.battMax-settings.battMin)
lcd.drawNumber(txt_x+5, tx_y, percent, LEFT+MIDSIZE)
lcd.drawText(lcd.getLastPos(), tx_y, "%", MIDSIZE)
lcd.drawGauge(txt_x, tx_y - 2, 89, 16, percent, 100)
if getValue(MIXSRC_SA)<0 then
lcd.drawText(120,4,"Attitude",SMLSIZE)
elseif getValue(MIXSRC_SA) == 0 then
lcd.drawText(120,4,"Part Rate",SMLSIZE)
else
lcd.drawText(120,4,"Full Rate",SMLSIZE)
end
end
return { run=run }
Re: Lua Telemetry scripts
Thanks Kilrah - looks like I need to do some reading. I notice as welll in the tracker #1480, there are some test scripts to get the list of constants. Are these run in the simulator, and if so, where does the output go?
Re: Lua Telemetry scripts
Currently only available on Linux platforms, if you run Companion or stand-alone simulator from a command line window (terminal) you get output from Lua print() statements in terminal. The software also has to be build with the DEBUG=YES option. We are working on something to provide this output on all systems https://github.com/opentx/opentx/issues/1489paulj wrote:I notice as welll in the tracker #1480, there are some test scripts to get the list of constants. Are these run in the simulator, and if so, where does the output go?
projectkk2glider@github
Re: Lua Telemetry scripts
As I am running Linux, and compile everything from source, this is fine for me! Thankyou very much.dinamich wrote:Currently only available on Linux platforms, if you run Companion or stand-alone simulator from a command line window (terminal) you get output from Lua print() statements in terminal. The software also has to be build with the DEBUG=YES option.paulj wrote:I notice as welll in the tracker #1480, there are some test scripts to get the list of constants. Are these run in the simulator, and if so, where does the output go?
Re: Lua Telemetry scripts
I'm running into a problem with lua.
Is the string.len() working? i need to know the length of a string to place it in the screen but string.len is making the script go blank (so there is an error). Are the string functions implemented?
Is the string.len() working? i need to know the length of a string to place it in the screen but string.len is making the script go blank (so there is an error). Are the string functions implemented?
Re: Lua Telemetry scripts
No, string functions aren't available at this point.
Sent via mobile
Sent via mobile