Hi everyone!
Over the last couple of months, I've been working on an interface to obtain data from my ECU to send via CAN to the Race Capture Pro.
Here are the parameters I am currently obtaining:
* RPM
* Vehicle Speed
* Coolant Temp
* Throttle Position
* Clutch Switch
* Brake Switch
* Calculated Gear
My data is structured like this
{ 'RPM 1' , 'RPM 2' , 'Speed' , 'Coolant temp','Throttle Position', 'Clutch Switch', 'Brake Switch', 'Calculated Gear'}
| high byte low byte | byte | byte | byte | byte | byte | byte |
| (RPM1 | RPM2 << 8 )/4.0 | 0 - 255 | 0 - 255 | 0 - 100 | 0/1 | 0/1 | 0-6 |
All of the parameters will be packed into a 8 byte CAN message sent on to the race capture pro:
{'canID'',EXT','RPM1','RPM2','Speed','Coolant temp','Throttle Position','Clutch Switch','Brake Switch','Calculated Gear'}
This leads me to my question. I'm absolutely terrible with Lua, and I have no idea how to interpret my RPM data in the RCP.
What I do know:
* I'm fairly confident the ECU data is little endian
* The RPM value can be calculated in C/Arduino like this: (RPM1 | RPM2 << 8 )/4.0
Below is my best guess on how to map the CAN data out in the RCP. Any help you may have is appreciated.
--format is: [CAN Id] = function(data) map_chan(<channel id>, data, <CAN offset>, <CAN length>, <multiplier>, <adder>)
CAN_map = {``
[1365] = function(data) map_chan_le(rpmID, data, 0, 2 , .25, 0)
map_chan_le(mphID, data, 2, 1 , 0, 0),
map_chan_le(tmpID, data, 3, 1 , 0, 0),
map_chan_le(tpsID, data, 4, 1 , 0, 0),
map_chan_le(cltID, data, 5, 1 , 0, 0),
map_chan_le(brkID, data, 6, 1 , 0, 0),
map_chan_le(gerID, data, 7, 1 , 0, 0) end,
}
Thanks!
Ryan
LUA / Can Bus help
Re: LUA / Can Bus help
Replying to myself, in case it helps anyone.
Basing my script on the E46 supported LUA script, I have been able to successfully send data into the RCP and read it on the gauges screen
I found that packing all of the data into one can message is problematic, however, things do seem to work fairly well when each parameter is split into it's own specific can packet.
Additionally, I found the map_chan_be does a pretty good job of interpreting my RPM data (turns out my data was big endian, rather the little endian as I had erroneously thought), however, it's not perfect. I'll have to spend a little time on the formula. Once I'm done, I'll post more detail.
Cheers,
Ryan
Basing my script on the E46 supported LUA script, I have been able to successfully send data into the RCP and read it on the gauges screen
I found that packing all of the data into one can message is problematic, however, things do seem to work fairly well when each parameter is split into it's own specific can packet.
Additionally, I found the map_chan_be does a pretty good job of interpreting my RPM data (turns out my data was big endian, rather the little endian as I had erroneously thought), however, it's not perfect. I'll have to spend a little time on the formula. Once I'm done, I'll post more detail.
Cheers,
Ryan
Re: LUA / Can Bus help
this is how I pulled it off in LUAfinse wrote: * The RPM value can be calculated in C/Arduino like this: (RPM1 | RPM2 << 8 )/4.0
Ryan
Code: Select all
local byts={RPM[1],RPM[2]}
for i=1,2 do
cv=cv+byts[i]*256^(i-1)
end
cv=((cv / 4.0) - 5)
For what it's worth, this is the complete lua script for my CAN implementation:finse wrote: Below is my best guess on how to map the CAN data out in the RCP. Any help you may have is appreciated.
Code: Select all
tickRate = 30
CAN_baud = 500000
CAN_chan = 0
rpmId = addChannel("RPM", 10, 0, 0, 8300)
kmhId = addChannel("Speed(MPH)",10, 0, 0, 170)
tmpId = addChannel("Coolant",10,0,0,250)
brkId = addChannel("Brake",10)
cltId = addChannel("Clutch",10)
gerId = addChannel("Gear",10)
tpsId = addChannel("Throttle", 100)
CAN_map = {
[601] = function(data) map_rpm(rpmId, data, 2, 2, .25, 0) end,
[602] = function(data) map_int(kmhId, data, 2, 1, 1, 0) end,
[603] = function(data) map_int(tmpId, data, 2, 1, 1, 0) end,
[604] = function(data) map_int(brkId, data, 2, 1, 1, 0) map_int(cltId, data, 3, 1, 1, 0) end,
[605] = function(data) map_int(gerId, data, 2, 1, 1, 0) end,
[606] = function(data) map_int(tpsId, data, 2, 1, 1, 0) end
}
function onTick()
processCAN(CAN_chan)
end
function processCAN(chan)
repeat
local id, e, data = rxCAN(chan)
if id ~= nil then
local map = CAN_map[id]
if map ~= nil then
map(data)
end
end
until id == nil
end
function map_rpm(cid, data, offset, len, mult, add, filter)
local byts={data[2], data[3]}
for i=1,2 do
cv=cv+byts[i]*256^(i-1)
end
cv=((cv / 4.0) - 5)
setChannel(cid, cv)
end
function map_int(cid, data, offset, len, mult, add, filter)
cv = data[offset]
setChannel(cid, cv)
end
initCAN(CAN_chan, CAN_baud)
setTickRate(tickRate)