Page 1 of 1

Lua script for shift-x crashing my RCP

Posted: Mon Mar 31, 2014 7:40 pm
by SaabPower
I've been crashing Analyzer and bricking the hardware trying to script the shift light. I was trying to run something like this (off the top of my head, not at my RCP now):

Code: Select all

setTickRate(15)

r=0
function onTick() 
	r=r+500
        if(r>7000) then
          r = 0
        end
	if r > 5000 then setGpio(2,1) else setGpio(2,0) end 
	if r > 6000 then setGpio(1,1) else setGpio(1,0) end 
	if r > 7000 then setGpio(0,1) else setGpio(0,0) end
end
Is there something I can do to debug what's going wrong? I was able to have the lights blink by incrementing variable r in onTick and setting each GPIO port with modulus %2,%3,%4 to make each segment blink at different rates.

I am using latest analyzer 1.1.5 and firmware 1.2.7.

Posted: Wed Apr 02, 2014 1:41 pm
by gizmodo
According to this blog post there is a println function that should allow you to debug.
http://www.autosportlabs.com/racecaptur ... -examples/

I haven't had a chance to give it a try yet though.

Re: Lua script for shift-x crashing my RCP

Posted: Sat Apr 05, 2014 11:37 am
by GTIspirit
SaabPower wrote:I've been crashing Analyzer and bricking the hardware trying to script the shift light. I was trying to run something like this (off the top of my head, not at my RCP now):

Code: Select all

setTickRate(15)

r=0
function onTick() 
	r=r+500
        if(r>7000) then
          r = 0
        end
	if r > 5000 then setGpio(2,1) else setGpio(2,0) end 
	if r > 6000 then setGpio(1,1) else setGpio(1,0) end 
	if r > 7000 then setGpio(0,1) else setGpio(0,0) end
end
Is there something I can do to debug what's going wrong? I was able to have the lights blink by incrementing variable r in onTick and setting each GPIO port with modulus %2,%3,%4 to make each segment blink at different rates.

I am using latest analyzer 1.1.5 and firmware 1.2.7.
:idea: This sounds similar to what I had in mind for my ShiftX. As the limit is approaching the light should blink faster and faster, then when the limit is reached the light should stay on solid and the next one should start blinking, etc. So in your example above, the first light would start blinking slowly at say 4000rpm, and start blinking faster as engine speed gets nearer 5000rpm. Then when engine speed is greater than 5000rpm that first light would be solid, and the second light would start blinking slowly, and the blink rate would increase as engine speed approaches 6000, above which it would stay on solid, and so on.

I'm not a SW engineer so coding myself isn't so comfortable, but I'm familiar with the concepts. I guess the implementation would be such that the difference between current engine speed and threshold to next light would be the off time multiplied by a scalar. So for a big difference the off time would be larger, and then as the difference approaches zero the light is essentially on constantly (no off time).

Posted: Mon Apr 07, 2014 10:38 pm
by brentp
We just released a firmware version 1.2.8 that should help with lua scripting stability. Please download / install and try it out, and make sure you're using the latest version of RaceAnalyzer (1.1.15 as of this writing)

Also, we've worked in the ability to have the firmware recover in case a bad script causes RCP to hang - it's in the new v2.0 firmware that's in progress. V2.0 is a major update and won't work with the current version of Race Analyzer, note.

Let us know how the v1.2.8 firmware works!

Posted: Fri Jul 25, 2014 5:17 pm
by momostallion
It seems like anytime I touch the RUN button in the scripting section of race analyzer, it crashes my RCP and it no longer show in device manager under Ports (COM..) .

I have to redo using flashRCP.bat

I am on v1.1.15 and FW 1.2.8

Posted: Fri Jul 25, 2014 5:21 pm
by brentp
The V2 firmware makes improvements in this area, especially around recovering from lua script crashes. I believe we're targeting alpha release this weekend. Stand by...

Posted: Sat Aug 02, 2014 1:23 am
by momostallion
quick post to bump this thread. got bored and played around with blinking lights.

video:
http://youtu.be/Y7ZwME-Fy5E


here is the Lua script used:

Code: Select all

setTickRate(15)  --15hz 

t = 0  --"ticker"

function onTick() 
    t = t+1  --increment ticker
   local v = getAnalog(7)  --get voltage

   if v > 0 and t % 2 == 0 then setGpio(2,1) else setGpio(2,0) end   
     --flash every even Hz (7.5x per second)
   if v > 11 and t % 5 == 0 then setGpio(1,1) else setGpio(1,0) end
     --flash every 5th tick (3x per second)
   if v > 13 and t % 10 == 0 then setGpio(0,1) else setGpio(0,0) end
     --flash every 10th tick (1.5x per second)
 end

Posted: Thu Aug 14, 2014 9:03 pm
by brentp
Please try the script with the V2 firmware and let us know if you still have problems!