Skip to content

Instantly share code, notes, and snippets.

@brentpicasso
Last active February 7, 2017 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brentpicasso/f0e3f1eec61381c2adbae4bcef5d182c to your computer and use it in GitHub Desktop.
Save brentpicasso/f0e3f1eec61381c2adbae4bcef5d182c to your computer and use it in GitHub Desktop.
ShiftX2 predictive timer simulator
function splitWord(value)
return bit.band(value, 0xFF), bit.rshift(bit.band(value, 0xFF00),8)
end
function setLinearThreshold(id, threshold, red, green, blue, flash)
local lowt
local hight
lowt, hight = splitWord(threshold)
txCAN(0, 744389 + 15, 1, {id, 0, lowt, hight, red, green, blue, flash})
sleep(10)
end
function configLinearGraph(lowRange, highRange, renderStyle, linearStyle)
local lowRangeLow
local lowRangeHigh
local highRangeLow
local highRangeHigh
lowRangeLow, lowRangeHigh = splitWord(lowRange)
highRangeLow, highRangeHigh = splitWord(highRange)
txCAN(0, 744389 + 14, 1, {renderStyle, linearStyle, lowRangeLow, lowRangeHigh, highRangeLow, highRangeHigh})
sleep(10)
end
function updateLinearGraph(value)
low, high = splitWord(value)
txCAN(0, 744389 + 16, 1, {low, high})
end
function onTick()
-- simulate +/- changes in predictive timer
local imu = (getImu(0) * 100) + 100
updateLinearGraph(imu)
end
setTickRate(30)
initCAN(0, 500000)
configLinearGraph(0, 200, 1, 0)
setLinearThreshold(0, 0, 255, 0, 0, 0)
setLinearThreshold(1, 70, 255, 127, 0, 0)
setLinearThreshold(2, 100, 0, 255, 0, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment