Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lap simulator script. generates laps based on elapsed distance - useful in a non-circuit environment
--Lap simulator script
--Ensure GPS Distance channel is disabled
--Ensure Race Timing is disabled
--Requires a GPS lock for proper operation
--sets the length of the lap desired, in miles.
lapLength = 1
setTickRate(10)
lcId = addChannel("LapCount", 10, 0)
ltId = addChannel("LapTime", 10, 0)
dId = addChannel("Distance", 10, 4)
totalDist= 0
lapCount = 0
lastTime = 0
lapTime = 0
totalTime = 0
totalDist = 0
function onTick()
--calculate and update the current lap as needed
local currentSpeed = getGpsSpeed() --MPH
local currentTime = getUptime() --Milliseconds
local elapsedTime = currentTime - lastTime
totalTime = totalTime + elapsedTime
local elapsedHours = elapsedTime * 0.000000277778
local dist = currentSpeed * elapsedHours
lastTime = currentTime
totalDist = totalDist + dist
setChannel(dId, totalDist) --update Distance channel
if totalDist > lapLength then
lapCount = lapCount + 1
setChannel(lcId, lapCount) --update LapCount channel
setChannel(ltId, totalTime / 60000) --update LapTime virtual channel
totalTime = 0
totalDist = 0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.