Time Delay in 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
Alex W
Posts: 41
Joined: Tue Apr 16, 2013 5:57 pm
Location: Bozeman, MT

Time Delay in Script

Post by Alex W »

Let me preface this by saying that scripting is most assuredly not my strong point:), so sorry if this is an easy question.

Anyway, I would like to be able to setup a automatic logging start/stop script such that at say 5mph it starts logging, then stops logging once the speed has been below 5mph and stayed there for perhaps 60 seconds. I use the logger primarily for autocross, and I would like it to start when I leave my spot in grid and pull up to the starting line, but then not shut off while I am sitting at the line.

redparchel
Posts: 22
Joined: Fri Nov 01, 2013 9:48 pm
Location: Bay Area, CA

Post by redparchel »

Not sure if you found an answer as it has been a while since the post, but you can try the following. note: I haven't tested this, but I'll toss it out as an idea that might work on the latest firmware.

Code: Select all

setTickRate&#40;1&#41; #setting it to 1 to make it easier to understand 
TicksSinceUnderFive = 0 #creating a counter

function onTick&#40;&#41;
  if getGpsSpeed&#40;&#41; > 5 then
	TicksSinceUnderFive = 0 #reset counter
    startLogging&#40;&#41;
  else
	TicksSinceUnderFive = TicksSinceUnderFive + 1 #under 5 increase the counter
	if TicksSinceUnderFive > 60 then #has it been 60 seconds/cycles
	    stopLogging&#40;&#41;
		TicksSinceUnderFive = 0 #reset the counter, overkill
	end
  end
end

We're basically creating a counter to count the number of times we go through the loop (the 'loop' is the onTick method that is continuously excited at the interval set by 'setTickRate' as long as the unit is powered) when we're under 60. the counter in this case is set to '1' which should mean the loop executes one time per second. (if you set tick rate to 10, set the 'if TicksSinceUnderFive < 60 then' to 'if TicksSinceUnderFive < 600 then' )

Sidenote for the Autosportlabs crew: this may be a good use case for a 'getTickRate' method, to make this more dynamic the if line could be:

Code: Select all

if TicksSinceUnderFive < getTickRate&#40;&#41; * 60 

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

Post by brentp »

Thanks for the tip. After reading this, it would be interesting to have a "call me later" function where you could go:

schedule("FunctionName", millisecondsFromNow)

That could add some flexibility, for certain.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

pmacduffie
Posts: 18
Joined: Sat Aug 09, 2014 5:55 pm
Location: Florida

Post by pmacduffie »

You could simply have the race capture start when you move and not stop until you power it off. That's exactly what we do. I cannot ever be sure we wont be stopped for some length of time in a race.

Post Reply