Skip to content

Instantly share code, notes, and snippets.

@brentpicasso
Last active February 6, 2017 22:04
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/847d03e9bddbf7c524c666c703a7be47 to your computer and use it in GitHub Desktop.
Save brentpicasso/847d03e9bddbf7c524c666c703a7be47 to your computer and use it in GitHub Desktop.
ShiftX2 linear graph configuration example
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, {0, 0, lowRangeLow, lowRangeHigh, highRangeLow, highRangeHigh})
sleep(10)
end
function updateLinearGraph(value)
low, high = splitWord(value)
txCAN(0, 744389 + 16, 1, {low, high})
end
function onTick()
local yaw = math.abs(getImu(3)) * 100
local pitch = math.abs(getImu(4))
updateLinearGraph(yaw)
end
setTickRate(30)
initCAN(0, 500000)
configLinearGraph(0, 10000, 0, 0)
setLinearThreshold(0, 2000, 0, 255, 0, 0)
setLinearThreshold(1, 5000, 255,127, 0, 0)
setLinearThreshold(2, 8000, 255, 0, 0, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment