Can't "Run" my script

Discussion on the Lua Scripting capabilities for RaceCapture/Pro. Also see the <a href="http://autosportlabs.net/RaceCapturePro_Lua_Scripting">Lua Scripting Guide</a>

Moderators: JeffC, stieg

Post Reply
lightningrod
Posts: 47
Joined: Wed Oct 04, 2017 1:44 am

Can't "Run" my script

Post by lightningrod »

I have a script that clearly is very close to the memory limit. It runs fine on power up. It also runs immediately after being written,
however if I try to restart it with the app's "Run" button lua fails to restart with the following messages:
[lua] Successfully loaded script.
[lua] Gracefully stopping Lua Task
[lua] Destroying Lua State
[lua] Initializing Lua state
[lua] memory usage: 17KB
[lua] Starting Lua Task
[lua] Loading script. Length: 2205
timebase/logging/telemetry sample rate: 100/100/50
timebase/logging/telemetry sample rate: 100/100/50
[lua] Startup script error: (not enough memory)
[lua] Failure: Failed to load script
Last edited by lightningrod on Sun Jun 30, 2019 5:37 am, edited 1 time in total.

brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

2.17.0 firmware will have a bit more memory freed up, so we should re-test this to find out if it makes a difference.

Can you post your memory consuming script here for testing?
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

lightningrod
Posts: 47
Joined: Wed Oct 04, 2017 1:44 am

Post by lightningrod »

The following script exhibits the symptoms under 2.16.0

Code: Select all

r1=0
r2=0
function ah&#40;&#41;
local r0=r1
r1=r2
r2=r1+&#40;getChannel&#40;"RPM"&#41;/60-r0&#41;/2
return r2
end
a1=0
a2=0
function ai&#40;&#41;
local a0=a1
a1=a2
a2=a1+&#40;-getImu&#40;0&#41;-a0&#41;/2
return a2
end
function u&#40;&#41;
ret=getChannel&#40;"WOT"&#41;
if ret~=nil then
return ret and 1 or 0
end
if getImu&#40;0&#41;<-0.01 then
local o=getImu&#40;1&#41;
if o*o<0.06 then return 1 end
end
return 0
end
e=&#123;&#125;
O=0
H=0
V=&#123;&#125;
function W&#40;F,Z,a&#41;
local A=&#123;&#125;
A.ah=addChannel&#40;"dT_"..F,10,2,0,50,"ms/rpm"&#41;
A.F=F
A.U=&#123;&#125;
A.r=Z
A.s=a
d&#40;A&#41;
e&#91;O&#93;=A
O=O+1
end
function aB&#40;F,t,q,Z,a,p,G&#41;
V&#91;H&#93;=&#123;&#125;
V&#91;H&#93;.G=G
V&#91;H&#93;.F=F
for E=0,O-1 do
local A=e&#91;E&#93;
local C=&#123;&#125;
C.G=addChannel&#40;F..A.F,t,q,Z,a,p&#41;
C.Q=0
C.T=0
A.U&#91;H&#93;=C
end
H=H+1
end
function d&#40;A&#41;
A.g=0
A.M=0
for E=0,H-1 do
A.U&#91;E&#93;.Q=0
A.U&#91;E&#93;.T=0
end
end
function an&#40;A,b&#41;
if b>=A.r then
if b<A.s then
if A.M==0 then
A.M=b
A.g=getUptime&#40;&#41;
else
local n=b-A.M
if n>0 then
local ag=getUptime&#40;&#41;-A.g
local ar=ag/n
setChannel&#40;A.ah,ar&#41;
end
end
for E=0,H-1 do
ao&#40;A.U&#91;E&#93;,V&#91;E&#93;.G&#41;
end
elseif A.M~=0 then
d&#40;A&#41;
end
end
end
function ao&#40;C,ai&#41;
local G=getChannel&#40;ai&#41;
if G then
C.T=C.T+1
C.Q=C.Q+G
local al=C.Q/C.T
setChannel&#40;C.G,al&#41;
end
end
function ap&#40;X&#41;
local b=getChannel&#40;"RPM"&#41;
for E=0,O-1 do
local A=e&#91;E&#93;
if X then
an&#40;A,b&#41;
else
if A.M~=0 then d&#40;A&#41;end
end
end
end
N=nil
R=nil
l=nil
function ay&#40;&#41;
local J=bit.band
local I=readCSer&#40;6,0&#41;
while I do
D=D+1
if D==1 and J&#40;I,0xA2&#41;==0xA2 then
elseif D==2 and J&#40;I,0x80&#41;==0x80 then
elseif D==4 then
k=J&#40;bit.rshift&#40;R,2&#41;,7&#41;
l=J&#40;R,1&#41;*0x80+
J&#40;I,0x7F&#41;
elseif D==6 then
local j=J&#40;R,0x7F&#41;*0x80+J&#40;I,0x7F&#41;
if k==0 then
N=&#40;j+500&#41;*l/10000
elseif k==1 then
N=j/10
end
D=0
elseif D~=3 and D~=5 then
D=0
end
R=I
I=readCSer&#40;6,0&#41;
end
if N then
setChannel&#40;aA,N&#41;
N=nil
end
end
function av&#40;&#41;
local h=&#40;getGpsSpeed&#40;&#41;*0.44704&#41;
local K=ah&#40;&#41;
local aX=ai&#40;&#41;
local w=&#40;aX*9.8&#41;*y+&#40;ad+h*&#40;ae+h*af&#41;&#41;
local c=&#40;w*h/&#40;K*2*3.1416&#41;&#41;
local f=&#40;&#40;c/4.45&#41;*&#40;1*3.28084&#41;&#41;
setChannel&#40;ab,f&#41;
setChannel&#40;ac,&#40;f*K*60/5252.0&#41;&#41;
end
function onTick&#40;&#41;
local X=u&#40;&#41;==1
collectgarbage&#40;&#41;
ay&#40;X&#41;
ap&#40;X&#41;
av&#40;&#41;
sxUpdateLinearGraph&#40;getChannel&#40;"RPM"&#41;/100&#41;
end
initSer&#40;6,19200,8,0,1&#41;aA=addChannel&#40;"AFR",10,1,8,23&#41;D=0
y=&#40;2290*0.453592&#41;af=0.5*0.335*1.72*1.22 ae=0.335 ad=6 ab=addChannel&#40;"Torque",10,1,0,150,"ft-lb"&#41;ac=addChannel&#40;"HP",10,1,0,150,"HP"&#41;
sxSetConfig&#40;0,0,0&#41;local m=sxSetLinearThresh sxCfgLinearGraph&#40;0,0,0,75&#41;m&#40;0,0,5,0,0,127,0&#41;m&#40;1,0,39,0,127,0,0&#41;m&#40;2,0,68-8,127,255,0,0&#41;m&#40;3,0,68-4,255,127,0,0&#41;m&#40;4,0,68,255,0,0,10&#41;
W&#40;"4",4000,5000&#41;
W&#40;"5",5000,6000&#41;
W&#40;"6",6000,7000&#41;
aB&#40;"AF",10,1,7,25,"%O2",aA&#41;
aB&#40;"Torque",10,0,50,150,"ft-lb",ab&#41;
setTickRate&#40;60&#41;

lightningrod
Posts: 47
Joined: Wed Oct 04, 2017 1:44 am

Post by lightningrod »

FWIW: this script still exhibits the same symptoms under 2.17.1.

Post Reply