Model specific luas

Help with any software/desktop related issues. e.g. companion9x, eePe, etc
Post Reply
Richard
Posts: 183
Joined: Sat Mar 29, 2014 10:44 pm
Country: United States
Location: Coral Springs, FL

Model specific luas

Post by Richard »

I think once again I am in the wrong page.
I build three lua's to be assigned to a model, but something is wrong. I tested those luas when assigned to the SCRIPTS/MIXES directory and they work just fine. Then I changed the names to telem1.lua, telem2.lua and telem3.lua, and added them to the directory SCRIPTS/EC-PC-9 (EC-PC-9 is my model name).
To complete my point, here is one of the luas I am trying to use:
local txpower=0
local gval=0
local gval1=0
local preval=0
local preval1=0
local switch=100
local active=0
local wait_end = 0
local update=0
local newval=0
local newval1=0
local newflgt=0
local wait_sc=0
local report=0
--local outputs = {"Cons", "Pval","Nval"}

function run(store)
switch=getValue ('sc')
if txpower==0 then
if getValue ('sh') > 0 then
model.setGlobalVariable(0, 8,-1024)
end

if switch < 0 then -- allows to start with SC low
active=1
update=0
report=0
end

if switch >= 0 and active==1 then -- it runs only once and after SC was activated

if newflgt==0 then
newflgt=1
gval=getValue ('consumption')
gval=gval
preval1=model.getGlobalVariable(0,8)
preval=(preval1+1024)*2.4414
if preval-math.floor(preval)<0.5 then
preval=math.floor(preval)
else
preval=math.ceil(preval)
end
newval=(preval+gval)
newval1=(newval/2.4414)-1024
if newval1-math.floor(newval1)<0.5 then
newval1=math.floor(newval1)
else
newval1=math.ceil(newval1)
end
model.setGlobalVariable(0, 8,newval1)
txpower=1
end

end
else
if switch < 0 then
active=1
update=0
wait_sc=1
report=0
end
if switch >= 0 and active==1 and wait_sc==1 then -- it runs only once and after SC was activated
if update==0 then
-- update=1
active=0
wait_sc=0
gval=getValue ('consumption')
gval1=(gval/2.4414)-1024
if gval1-math.floor(gval1)<0.5 then
gval1=math.floor(gval1)
else
gval1=math.ceil(gval1)
end
model.setGlobalVariable(0, 8,gval1)
end
end


end
return gval*10.24,preval*10.24 ,newval*10.24
end
return {run=run} --output=outputs

I guess that either I am missing something in the code, or I am using a wrong filename, or directory.

I am running OpenTX 2.0.18 and using the firmware simulator for Taranis 2.0
Richard

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

Re: Model specific luas

Post by Kilrah »

There are several different types of scripts. telemx.lua are for telemetry scripts only.
Richard
Posts: 183
Joined: Sat Mar 29, 2014 10:44 pm
Country: United States
Location: Coral Springs, FL

Re: Model specific luas

Post by Richard »

OK, How should I name the script above then, and where should I put it (directory) to be run when I select the model?
Richard
User avatar
Kilrah
Posts: 11109
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Model specific luas

Post by Kilrah »

The way you used before and that worked?

Not sure what you're trying to do with those scripts, might help a bit to know. So would

Code: Select all

 tags around the code if posting on the forum.
Richard
Posts: 183
Joined: Sat Mar 29, 2014 10:44 pm
Country: United States
Location: Coral Springs, FL

Re: Model specific luas

Post by Richard »

Kilrah, I will give you the short version, before tagging the script, and I apologize for not having that done before. As a matter of fact it is a good idea to understand what you do a couple of months after you wrote the code. This is because I am not a sw engineer, otherwise I would know better.
Anyhow, the objective of the lua is to have knowledge of the battery capacity left, regardless of how long you fly and how many flights you do, using the FrSky current sensor. Therefore the lua will:
1) Reset the value of GV1 to -1024 when a new battery is installed (and SH is toggled)
2) each time the motor is shoot off (SC low), it will read the battery consumption and the previously stored consumption from GV1, add them both and store the new value in GV1.
Another lua will take care of the "on the fly" warnings on the battery status.
After testing these luas in the field I will publish them for public use.

The reason I did want to do these luas model specific is because the battery capacity is related to each model. May be the way around it would be to give each "version" a different name and load them in the Customs Scripts for each of them. I guess is a different way with the same outcome.

Your thoughts?
Richard

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

Re: Model specific luas

Post by Kilrah »

My thoughts? Unless I'm misunderstanding that you don't need a script to do that, it's built in in the standard functions.
There's a "Persistent mAh" option in the telemetry setup that will store consumption on power down/model change and thus keep it where it is until you reset it manually with a "reset flight" or "reset telemetry".
Richard
Posts: 183
Joined: Sat Mar 29, 2014 10:44 pm
Country: United States
Location: Coral Springs, FL

Re: Model specific luas

Post by Richard »

It looks that that function is in 2.1. Did not find it in 2.0, unless I am looking in the wrong place. I did not upgraded to 2.1 because I already started to work in 2.0, and honestly, I did not too much research to find out how to configure all capabilities offered in the telemetry settings in 2.1. No doubt they are really good, but there are so many parameters in each option that it is very hard to figure them out without at least a description of what each of them, and how they affect each line.
Richard
User avatar
Kilrah
Posts: 11109
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: Model specific luas

Post by Kilrah »

Nope it's in 2.0 too.
screenshot-1.png
screenshot-1.png (1.72 KiB) Viewed 5081 times
Richard
Posts: 183
Joined: Sat Mar 29, 2014 10:44 pm
Country: United States
Location: Coral Springs, FL

Re: Model specific luas

Post by Richard »

Got it!!
Thanks a lot!!
Richard

Post Reply

Return to “Software”