RaceCapturePro Lua Scripting Examples

Revision as of 19:53, 9 March 2014 by Brentp (talk | contribs) (added examples)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Automatically Start Logging based on GPS Speed

This script will automatically start logging to SD card when speed exceeds 10MPH and stop when it falls below.

function onTick()
  if getGpsSpeed() > 10 then
    startLogging()
  else
    stopLogging()
  end
end

Automatically start Logging upon Launch (AutoX / Rally / Hill Climb)

This script will start Logging when a dash mounted "ARM" switch is activated via an input and G-force exceeds a threshold Given:

  • GPIO 0 configured as input and connected to dash mounted "Arm" switch
  • Default RaceCapture/Pro mounting orientation (terminal block facing forward, mounted upright)
  • G-force launch threshold is -0.1 G
  • flipping the ARM switch to 'Off' will stop logging
setTickRate(30)

function onTick()
 arm = getGpio(0)
 g = getAccel(1)
 if arm == 0 then
   stopLogging()
 end
 if arm == 1 and g < 0.1 then
   startLogging()
 end
end

Activate a GPIO when start finish line is crossed

This script will pulse one of the GPIO outputs when the start/finish line is detected. First, the onTick rate is set to 10hz, then setGpio() is called with the result of the call to getAtStartFinish()

setTickRate(10)

function onTick()
  if getAtStartFinish() == 1 then
    setGpio(0, 1)
  else
    setGpio(0, 0)
  end
end

or

setTickRate(10)

function onTick()
  setGpio(0, getAtStartFinish())
end

Temperature Warning Indicator Light

This script will activate an output if an analog input exceeds a threshold. It's assumed a temperature sensor is connected to the Analog input channel 0 and is calibrated.

More information: Installation Guide, Sensor Guide, Operation Guide

function onTick()
 if getAnalog(0) > 212 then
   setGpio(0, 1)
 else
   setGpio(0, 0)
 end