double check script format

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
the ocho
Posts: 12
Joined: Mon Mar 20, 2017 3:55 pm

double check script format

Post by the ocho »

two quick questions - does this look correct:

looking to start logging as soon as gps is showing +5mph and stop logging when engine RPM is showing less than 100 rpm (so engine off)

Code: Select all

function onTick&#40;&#41;
  if getGpsSpeed&#40;&#41; > 5 then
    startLogging&#40;&#41;
  else if
    getTimerRpm&#40;0&#41; < 100 then
	stopLogging&#40;&#41;
  end
end
next question - I would like to rename my RPM channels - if i were to change that in setup, would the script need to read:

Code: Select all

getTimerEngineRpm&#40;0&#41;
Or is the name in setup not related to the calls in the Lua script?


thanks for the help -

the ocho
Posts: 12
Joined: Mon Mar 20, 2017 3:55 pm

Post by the ocho »

well - that didn't work. It never started logging and when we manually started the logger, it never stopped.

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

Post by brentp »

You can debug the script while watching the logging output under the script window - check the 'poll log' button.

You can also add some println() statements in your script to help you debug it's behavior, too. like:

println("Logging started")

etc.

The channel name in setup is not reflected in the Lua script - it's always represented by the numeric channel ID.

Script feedback; you might want to disable the else if.

try this:

Code: Select all

function onTick&#40;&#41; 
  local speed = getGpsSpeed&#40;&#41;
  local rpm = getTimerRpm&#40;0&#41;

  if speed > 10 and rpm > 500 then
    startLogging&#40;&#41;
  end

  if speed < 5 and rpm < 100 then
    stopLogging&#40;&#41;
  end
end
See how I added some hysteresis to prevent the logging from quickly starting/stopping? This will help create some crisp start/stopping of the logging.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

the ocho
Posts: 12
Joined: Mon Mar 20, 2017 3:55 pm

Post by the ocho »

code is working great - this is geared towards autocross, so it is set to start logging on the drive up to the start line, then stop logging when the engine is turned off after the run.

thanks for the help.

Post Reply