I'm trying to set up a virtual channel based on a calculation of existing CAN channels but I've not been able to get it to work. I started with the channel averaging example that is posted in the scripting examples. I'd like to calculate wheel slip which is one of the rear wheel speeds divided by the average of the two front wheel speeds.
I have an E46 M3 and the individual wheel speeds are working, it's just the calculated channel that isn't.
Can anyone see any issues with the script below?
lfWheelId = addChannel("LFWheelSpd", 10, 0, 0, 200, "MPH")
rfWheelId = addChannel("RFWheelSpd", 10, 0, 0, 200, "MPH")
lrWheelId = addChannel("LRWheelSpd", 10, 0, 0, 200, "MPH")
rrWheelId = addChannel("RRWheelSpd", 10, 0, 0, 200, "MPH")
rrslipId = addChannel("RRWheelSlip", 10, 0, 0, 100, "%")
function onTick()
local a1 = getrrWheelId
local a2 = getlfWheelId
local a3 = getlrWheelId
if lfWheelId > 10 then
setChannel(rrslipId, 100 * ( 1 - ( a1 / ((a2 + a3) / 2))))
end
end
Help with Calculated channel
Yeah, this script doesn't look right to me, I don't see any place you are fetching the actual wheel speeds. You need to first get the raw CAN data, convert it to 'real' values (MPH), set the virtual channel values, get those values again, then compute your slippage.
If you use the e46 canbus script that we have on our wiki (https://www.autosportlabs.net/BMW_E46_CAN), I *think* this is how you could do it:
See how that script is getting the channel? The ids its using are set at the top of the e46 canbus script.
Hope that helps!
If you use the e46 canbus script that we have on our wiki (https://www.autosportlabs.net/BMW_E46_CAN), I *think* this is how you could do it:
Code: Select all
function onTick()
processCAN(CAN_chan)
local a1 = getChannel(rrWheelId)
local a2 = getChannel(lfWheelId)
local a3 = getChannel(lrWheelId)
if a2 > 10 then
setChannel(rrslipId, 100 * ( 1 - ( a1 / ((a2 + a3) / 2))))
end
end
Hope that helps!
Ryan Doherty
Autosports Labs
Autosports Labs
-
- Posts: 27
- Joined: Thu Apr 09, 2015 8:18 pm
Thanks for the help. My issue was that I didn't know the correct command to request a CAN channel. I've tried the new script that you posted but have not been able to get it to work. I've even tried simplifying it as much as possible to get something working so that I can then build it up to the full equation.
This is what I've simplified it too and I'm still not getting any value for the rrslip channel. Any thoughts on why this isn't working?
function onTick()
processCAN(CAN_chan)
local a1 = getChannel(rrWheelId)
setChannel(rrslipId, a1)
end
This is what I've simplified it too and I'm still not getting any value for the rrslip channel. Any thoughts on why this isn't working?
function onTick()
processCAN(CAN_chan)
local a1 = getChannel(rrWheelId)
setChannel(rrslipId, a1)
end
Hi, can you post your entire script? What you last posted won't work because there isn't anything that is fetching data from the CANbus. You need to first get this script working, then you can do the slip computation: https://www.autosportlabs.net/BMW_E46_CAN
Ryan Doherty
Autosports Labs
Autosports Labs
Oops, direct link to Lua script https://www.autosportlabs.net/BMW_E46_CAN#Script
Ryan Doherty
Autosports Labs
Autosports Labs
-
- Posts: 27
- Joined: Thu Apr 09, 2015 8:18 pm