Lua script for shift-x crashing my RCP

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
SaabPower
Posts: 4
Joined: Tue Sep 10, 2013 6:55 am

Lua script for shift-x crashing my RCP

Post 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&#40;15&#41;

r=0
function onTick&#40;&#41; 
	r=r+500
        if&#40;r>7000&#41; then
          r = 0
        end
	if r > 5000 then setGpio&#40;2,1&#41; else setGpio&#40;2,0&#41; end 
	if r > 6000 then setGpio&#40;1,1&#41; else setGpio&#40;1,0&#41; end 
	if r > 7000 then setGpio&#40;0,1&#41; else setGpio&#40;0,0&#41; 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.

gizmodo
Posts: 138
Joined: Mon Aug 05, 2013 10:22 pm

Post 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.

GTIspirit
Posts: 233
Joined: Wed Jan 09, 2013 11:20 am
Location: SE Michigan

Re: Lua script for shift-x crashing my RCP

Post 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&#40;15&#41;

r=0
function onTick&#40;&#41; 
	r=r+500
        if&#40;r>7000&#41; then
          r = 0
        end
	if r > 5000 then setGpio&#40;2,1&#41; else setGpio&#40;2,0&#41; end 
	if r > 6000 then setGpio&#40;1,1&#41; else setGpio&#40;1,0&#41; end 
	if r > 7000 then setGpio&#40;0,1&#41; else setGpio&#40;0,0&#41; 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).

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

Post 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!
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

momostallion
Posts: 58
Joined: Wed Feb 12, 2014 1:48 pm
Location: dallas, tx

Post 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

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

Post 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...
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

momostallion
Posts: 58
Joined: Wed Feb 12, 2014 1:48 pm
Location: dallas, tx

Post 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&#40;15&#41;  --15hz 

t = 0  --"ticker"

function onTick&#40;&#41; 
    t = t+1  --increment ticker
   local v = getAnalog&#40;7&#41;  --get voltage

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

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

Post by brentp »

Please try the script with the V2 firmware and let us know if you still have problems!
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

Post Reply