Created
October 6, 2017 17:49
-
-
Save brentpicasso/32f20f0c461c6dab3d5da13417a521a0 to your computer and use it in GitHub Desktop.
Lap simulator script. generates laps based on elapsed distance - useful in a non-circuit environment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--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