Page 1 of 2

Lua Telemetry scripts

Posted: Tue Jul 01, 2014 4:13 pm
by bertrand35
One very simple example that will work in next release (2.0.6)
snapshot_01.png
snapshot_01.png (1.43 KiB) Viewed 23245 times
telem2.lua
(769 Bytes) Downloaded 692 times

Re: Lua Telemetry scripts

Posted: Tue Jul 01, 2014 6:55 pm
by FigNewton
Awesome!! I keep saying this, and will say it again, this going to be a major game changer...

Re: Lua Telemetry scripts

Posted: Tue Jul 08, 2014 5:58 pm
by nicodh
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!

Re: Lua Telemetry scripts

Posted: Wed Jul 09, 2014 8:33 am
by bertrand35
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

Re: Lua Telemetry scripts

Posted: Wed Jul 09, 2014 8:33 am
by bertrand35
Don't hesitate to paste your script here, I will try to help

Re: Lua Telemetry scripts

Posted: Wed Jul 09, 2014 2:22 pm
by nicodh
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.
Image

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 },
};
If the rest of the telemetry data is included in the liaField, it should work? Or I am missing something else?

Re: Lua Telemetry scripts

Posted: Wed Jul 09, 2014 10:59 pm
by bertrand35
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

Re: Lua Telemetry scripts

Posted: Thu Jul 10, 2014 6:47 am
by nicodh
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).

:-D

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!

Re: Lua Telemetry scripts

Posted: Thu Jul 10, 2014 8:04 am
by bertrand35
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

Posted: Fri Jul 11, 2014 1:40 pm
by nicodh
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:

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;
and

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 },
};
Am i missing something?

Re: Lua Telemetry scripts

Posted: Fri Jul 11, 2014 2:23 pm
by bertrand35
Which is your make command? Didn't you forget to enable Lua with LUA=YES?

Re: Lua Telemetry scripts

Posted: Fri Jul 11, 2014 2:38 pm
by nicodh
oh bertrand, i thik yes.
My make was just make PCB=TARANIS.

so i should put make PCB=TARANIS LUA= YES?

Re: Lua Telemetry scripts

Posted: Fri Jul 11, 2014 2:48 pm
by bertrand35
Yes (except the space between = and YES)

Re: Lua Telemetry scripts

Posted: Fri Jul 11, 2014 2:58 pm
by nicodh
it's building now... the code i put has some errors.
i'm seeing that now that lua code builds. :)

Re: Lua Telemetry scripts

Posted: Fri Jul 11, 2014 3:00 pm
by nicodh
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. :(

Re: Lua Telemetry scripts

Posted: Fri Jul 11, 2014 3:34 pm
by bertrand35
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

Posted: Fri Jul 11, 2014 6:13 pm
by nicodh
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.

Re: Lua Telemetry scripts

Posted: Fri Jul 11, 2014 10:17 pm
by bertrand35
Yes simu is the tool I use, as it is really quick to compile (on Linux)

Re: Lua Telemetry scripts

Posted: Sat Jul 12, 2014 2:55 am
by FigNewton
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

Posted: Sat Jul 12, 2014 6:05 am
by nicodh
These are my changes in lua.cpp:

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));
  }
}
and

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 },
};
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.

Re: Lua Telemetry scripts

Posted: Sun Jul 13, 2014 7:34 am
by nicodh
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.

Re: Lua Telemetry scripts

Posted: Sun Jul 13, 2014 2:09 pm
by dinamich
@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

Re: Lua Telemetry scripts

Posted: Mon Jul 14, 2014 4:52 am
by nicodh
Hi dinamich, i tried yesterday your field ids and they works!

Thanks a lot that makes everything easier.

Re: Lua Telemetry scripts

Posted: Sat Jul 19, 2014 2:52 pm
by paulj
The is great - thanks! I have been playing around today and have made a simple telemetry script for my quadcopter.

Image

"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 }
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)

Re: Lua Telemetry scripts

Posted: Sat Jul 19, 2014 5:27 pm
by Kilrah

Re: Lua Telemetry scripts

Posted: Mon Jul 21, 2014 4:44 am
by paulj
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

Posted: Mon Jul 21, 2014 8:10 am
by dinamich
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?
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/1489

Re: Lua Telemetry scripts

Posted: Mon Jul 21, 2014 11:46 am
by paulj
dinamich wrote:
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?
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.
As I am running Linux, and compile everything from source, this is fine for me! Thankyou very much.

Re: Lua Telemetry scripts

Posted: Wed Jul 23, 2014 5:40 am
by nicodh
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?

Re: Lua Telemetry scripts

Posted: Wed Jul 23, 2014 5:52 am
by Kilrah
No, string functions aren't available at this point.

Sent via mobile