Page 1 of 1
Help with Calculated channel
Author Message
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

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

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

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

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

_________________
Ryan Doherty
Autosports Labs

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.

 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 Page 1 of 1
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou cannot download files in this forum Select a forum Autosport Labs----------------General DiscussionNews and AnnouncementsNew Project Suggestions CAN Devices----------------ShiftX2AnalogX RaceCapture App----------------RaceCapture App Operation and General Q&ARaceCapture App Bug Reporting / Feature Requests CAN bus and OBDII integration----------------CAN mapping discussionOBDII PIDs discussion RaceCapture/Pro | RaceCapture/Apex | PodiumConnect----------------RaceCapture/Pro introductionsRaceCapture/Pro General Q&ASensorsHardware and InstallationLua ScriptingTelemetryBug ReportingFeature Requests RaceCapture/Track----------------RaceCapture/Track IntroductionsRaceCapture/Track OperationRaceCapture/Track InstallationRaceCapture/Track Bug Reporting / Feature Requests Megajolt/E and Megajolt Lite Jr. (MJLJ)----------------Ignition Map LibraryPowered by Megajolt GalleryAssemblyInstallationOperationQ&AFuture UpgradesBug ReportingFixes/Patches/UpdatesHard Rev Limiter