Skip to content

Instantly share code, notes, and snippets.

@brentpicasso
brentpicasso / E46_CAN_simulator.lua
Created January 25, 2016 19:54
Simulator script for E46
setTickRate(30)
function encodeWheel(value)
low_byte = bit.band(value, 0xFF)
high_byte = bit.rshift(bit.band(value, 0x1F00), 5)
return low_byte, high_byte
end
lf_wheel = 0
rf_wheel = 0
@brentpicasso
brentpicasso / E46_debugging.lua
Last active January 26, 2016 01:04
Adding raw low / high byte debugging for wheel speeds
--This example configured for E46 CAN
-- Automatically starts logging with engine 'on' (RPM triggered)
--how frequently we poll for CAN messages
tickRate = 30
--the CAN baud rate
CAN_baud = 500000
--CAN channel to listen on. 0=first CAN channel, 1=second
CAN_chan = 0
--add your virtual channels here
--RPM simulator!
rpm = 0
rpmDir = 100
maxRpm = 10000
rpmId = addChannel("RPM", 10, 0, 0, 10000)
setTickRate(50)
function onTick()
setChannel(rpmId, rpm)
rpm=rpm + rpmDir
@brentpicasso
brentpicasso / gist:d9fbf7dd44e010651bccbad910d290a4
Last active July 14, 2016 20:24
Trailing average for an sensor channel
fuel2Id = addChannel("Fuel2", 25, 2, 0,10,"%")
--change this to make a bigger averaging window
--300 = 10 seconds averaging at 30Hz tick rate
maxAvg = 300
fuelAvg={}
fuel2Index = 1
function updateFuel2(value)
local i
@brentpicasso
brentpicasso / all_sample_rates.rcp
Last active November 6, 2016 22:02
All possible sample rate combinations for RaceCapture/Pro - for testing. save this as a RCP configuration file (all_sample_rates.rcp)
{
"rcpCfg": {
"analogCfg": {
"0": {
"alpha": 1.0,
"map": {
"raw": [
0.0,
1.25,
2.5,
@brentpicasso
brentpicasso / gist:247d898f369cfb731e0014bb6f9dcb3c
Created December 12, 2016 21:37
Create Random tire and brake temperature data for RaceCapture/Pro
tires = 4
tireZones = 4
tirePrefixes = {'TireTmpFL', 'TireTmpFR', 'TireTmpRL', 'TireTmpRR'}
tireValues = {}
tireIds = {}
minTireVal = 0
maxTireVal = 300
brakes = 4
brakeZones = 4
setTickRate(30)
initCAN(0, 500000)
txCAN(0, 744389 + 10, 1, {0, 9, 0,0,0,5})
leds = 7
function onTick()
local x = getImu(3) / 10
local l = math.floor(math.abs(x))
if l > leds then l = leds end
setTickRate(30)
initCAN(0, 500000)
txCAN(0, 744389 + 12, 1, {0, 0, 5, 0, 0 , 255, 0, 0})
sleep(10)
txCAN(0, 744389 + 12, 1, {0, 1, 20, 0, 255, 0 , 0, 0})
sleep(10)
txCAN(0, 744389 + 12, 1, {1, 0, 5, 0, 0 , 255, 0, 0})
sleep(10)
@brentpicasso
brentpicasso / shiftx2_linear_graph_example.lua
Last active February 6, 2017 22:04
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})
@brentpicasso
brentpicasso / shiftx2_predictive_timer_simulator.lua
Last active February 7, 2017 21:24
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})