Page 1 of 1

double check script format

Posted: Thu Mar 30, 2017 2:36 am
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()
  if getGpsSpeed() > 5 then
    startLogging()
  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 -

Posted: Mon Apr 03, 2017 1:37 pm
by the ocho
well - that didn't work. It never started logging and when we manually started the logger, it never stopped.

Posted: Wed Apr 12, 2017 4:50 pm
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.

Posted: Tue Apr 25, 2017 1:17 pm
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.