RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 1 of 1
Help with Calculated channel
Author Message
Reply with quote
Post Help with Calculated channel 
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

View user's profile Send private message
Reply with quote
Post  
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:

Code:

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


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!


_________________
Ryan Doherty
Autosports Labs
View user's profile Send private message
Reply with quote
Post  
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

View user's profile Send private message
Reply with quote
Post  
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
View user's profile Send private message
Reply with quote
Post  
Oops, direct link to Lua script https://www.autosportlabs.net/BMW_E46_CAN#Script


_________________
Ryan Doherty
Autosports Labs
View user's profile Send private message
Reply with quote
Post  
I'll post up my full script this evening but to clarify, I'm using the e46 script from your site as the starting point and the individual wheel speeds are working correctly.

View user's profile Send private message
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum