Last active
September 30, 2019 01:53
-
-
Save brentpicasso/2f20a1288c58b54da2719de425446b63 to your computer and use it in GitHub Desktop.
Simulated tire, brake temperature, TPMS and engine sensors. Tire and brake data based on g-force readings.
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
--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, sr) | |
local ti = 1 | |
for c=1,items do | |
for t=1,zones do | |
local name = prefixes[c] | |
if zones > 1 then | |
name = name ..t | |
name = name:sub(1, -3) --trim deimal point | |
end | |
println('setting up "' ..name ..'"') | |
ids[ti] = addChannel(name, sr, 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 r() | |
return math.random(0,2) | |
end | |
function updateSensors() | |
setChannel(engineTempId, 198 + r()) | |
setChannel(coolantPressId, 27 + r()) | |
setChannel(oilTempId, 250 + r()) | |
setChannel(oilPressId, 47 + r()) | |
setChannel(diffTempId, 230 + r()) | |
setChannel(heartRateId, 100 + r()) | |
setChannel(transTempId, 210 + r()) | |
setChannel(fuelLevelId, 85 + r()) | |
for p=1,4 do | |
setChannel(pressIds[p], 35 + r()) | |
end | |
end | |
function onTick() | |
updateTires() | |
updateBrakes() | |
updateSensors() | |
end | |
setTickRate(10) | |
setupChannels(tirePrefixes, tireIds, tires, tireZones, minTireVal, maxTireVal, 10) | |
setupChannels(brakePrefixes, brakeIds, brakes, brakeZones, minBrakeVal, maxBrakeVal, 10) | |
pressIds = {} | |
setupChannels({'TPressLF', 'TPressRF', 'TPressLR', 'TPressRR'}, pressIds, 4, 1, 0, 50, 1) | |
engineTempId = addChannel("EngineTemp", 1, 0, 0, 250, 'F') | |
coolantPressId = addChannel("CoolantPres", 1, 0, 0, 25, 'PSI') | |
oilTempId = addChannel("OilTemp", 1, 0, 0, 250, 'F') | |
oilPressId = addChannel("OilPress", 1, 0, 0, 150, 'PSI') | |
diffTempId = addChannel("DiffTemp", 1, 0, 0, 250, 'F') | |
heartRateId = addChannel("HeartRate", 1, 0, 0, 200, 'BPM') | |
transTempId = addChannel("TransTemp", 1, 0, 0, 250, 'F') | |
fuelLevelId = addChannel("FuelLevel", 1, 0, 0, 100, '%') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment