Skip to content

Instantly share code, notes, and snippets.

@brentpicasso
Last active January 27, 2020 20:48
Show Gist options
  • Save brentpicasso/c584c192e45453facdad8a36b7b06470 to your computer and use it in GitHub Desktop.
Save brentpicasso/c584c192e45453facdad8a36b7b06470 to your computer and use it in GitHub Desktop.
Simulated tire and brake temperature data based on g-force readings.
--Note, If 2.10.2 firmware, AccelX and AccelY need to be inverted in the RCP configuration.
tires = 4
tireZones = 4
tirePrefixes = {'TireTmpLF', 'TireTmpRF', 'TireTmpLR', 'TireTmpRR'}
tireValues = {}
tireIds = {}
minTireVal = 0
maxTireVal = 300
brakes = 4
brakeZones = 1
brakePrefixes = {'BrakeTmpLF', 'BrakeTmpRF', 'BrakeTmpLR', 'BrakeTmpRR'}
brakeValues = {}
brakeIds = {}
minBrakeVal = 0
maxBrakeVal = 1000
function setupChannels(prefixes, ids, items, zones, minVal, maxVal)
local ti = 1
for c=1,items do
for t=1,zones do
local name = prefixes[c] .. t
name = name:sub(1, -3) --trim deimal point
println('setting up "' ..name ..'"')
ids[ti] = addChannel(name, 10, 0, minVal, maxVal, 'F')
ti=ti+1
end
end
end
function updateTires()
--left side is 1, 3
--right side is 2, 4
accelX = getImu(0) --braking
if accelX < 0 then accelX = -accelX else accelX = 0 end
accelY = getImu(1) --cornering
local i=1
for c=1, tires do
local offset = 100
left_cornering = 0
right_cornering = 0
if accelY > 0 then left_cornering = accelY * 250 end
if accelY < 0 then right_cornering = (-accelY) * 250 end
for t=1,tireZones do
offset = offset - 20
value = offset + accelX * 250 + math.random(0,20)
if c % 2 == 0 then value = value + right_cornering else value = value + left_cornering end
tireValues[i] = value
setChannel(tireIds[i], tireValues[i])
i=i+1
end
end
end
function updateBrakes()
--front side is 1, 2
--rear side is 3, 4
local offset = 500
accelX = getImu(0) --braking
if accelX < 0 then accelX = -accelX else accelX = 0 end
local i=1
for c=1, brakes do
for t=1,brakeZones do
value = offset + (accelX * 1000) + math.random(0,60)
if c > 2 then value = value - 200 end --rear brakes don't get as hot
brakeValues[i] = value
setChannel(brakeIds[i], brakeValues[i])
i=i+1
end
end
end
function onTick()
updateTires()
updateBrakes()
end
setTickRate(10)
setupChannels(tirePrefixes, tireIds, tires, tireZones, minTireVal, maxTireVal)
setupChannels(brakePrefixes, brakeIds, brakes, brakeZones, minBrakeVal, maxBrakeVal)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment