Help with Calculated channel

Discussion on the Lua Scripting capabilities for RaceCapture/Pro. Also see the <a href="http://autosportlabs.net/RaceCapturePro_Lua_Scripting">Lua Scripting Guide</a>

Moderators: JeffC, stieg

Post Reply
Mustangkev
Posts: 27
Joined: Thu Apr 09, 2015 8:18 pm

Help with Calculated channel

Post by Mustangkev »

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

rdoherty
Posts: 215
Joined: Fri Mar 08, 2013 3:32 am

Post by rdoherty »

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: Select all

function onTick&#40;&#41;
    processCAN&#40;CAN_chan&#41;
    local a1 = getChannel&#40;rrWheelId&#41; 
    local a2 = getChannel&#40;lfWheelId&#41; 
    local a3 = getChannel&#40;lrWheelId&#41; 
    if a2 > 10 then 
        setChannel&#40;rrslipId, 100 * &#40; 1 - &#40; a1 / &#40;&#40;a2 + a3&#41; / 2&#41;&#41;&#41;&#41; 
    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

Mustangkev
Posts: 27
Joined: Thu Apr 09, 2015 8:18 pm

Post by Mustangkev »

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

rdoherty
Posts: 215
Joined: Fri Mar 08, 2013 3:32 am

Post by rdoherty »

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

rdoherty
Posts: 215
Joined: Fri Mar 08, 2013 3:32 am

Post by rdoherty »

Oops, direct link to Lua script https://www.autosportlabs.net/BMW_E46_CAN#Script
Ryan Doherty
Autosports Labs

Mustangkev
Posts: 27
Joined: Thu Apr 09, 2015 8:18 pm

Post by Mustangkev »

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.

Post Reply