E46 Individual Wheels speeds and other channels

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

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

E46 Individual Wheels speeds and other channels

Post by Mustangkev »

I thought this would be a good place to share this info. I have individual wheel speeds, clutch and brake indicator along with a couple of other channels deciphered. These work for my M3, I'm assuming they will work for all 3-series but this would need to be verified.

wheelLFId = addChannel("Wheel_LF", 10, 1, 0, 180, 'MPH')
wheelRFId = addChannel("Wheel_RF", 10, 1, 0, 180, 'MPH')
wheelLRId = addChannel("Wheel_LR", 10, 1, 0, 180, 'MPH')
wheelRRId = addChannel("Wheel_RR", 10, 1, 0, 180, 'MPH')
clutchId = addChannel("Clutch", 10, 0, 0, 1)
brakeId = addChannel("Brake", 10, 0, 0, 1)
fuelId = addChannel("FuelLevel", 1, 1, 0, 70, 'ltrs')
ambTempId = addChannel("AmbTemp", 1, 0, 0, 60, 'C')
ambPresId = addChannel("AmbPress",1, 0, 970, 1030, 'mBar')

--Remove erroneous readings from wheel speed
function wheelFilter(value)
if value > 3583 then value = value - 3584
elseif value > 3071 then value = value - 3072
elseif value > 2559 then value = value - 2560
elseif value > 2047 then value = value - 2048
elseif value > 1535 then value = value - 1536
elseif value > 1023 then value = value - 1024
elseif value > 511 then value = value - 512 end
return value * 0.621
end

[339] = function(data) map_chan(brakeId, data, 0, 1, 0.0625, 0) end,
[496] = function(data) map_chan_le(wheelLFId, data, 0, 2, 0.0625, -8, wheelFilter) map_chan_le(wheelRFId, data, 2, 2, 0.0625, -8, wheelFilter) map_chan_le(wheelLRId, data, 4, 2, 0.0625, -8, wheelFilter) map_chan_le(wheelRRId, data, 6, 2, 0.0625, -8, wheelFilter) end,
[809] = function(data) map_chan(ambPresId, data, 2, 1, 2, 298.5) map_chan(clutchId, data, 3, 1, 1, -20) end,
[1349] = function(data) map_chan(oilTempId, data, 4, 1, 0.8117, -48) end,
[1555] = function(data) map_chan(fuelId, data, 2, 1, 1, 0) end,
[1557] = function(data) map_chan(ambTempId, data, 3, 1, 1, 0) end,

brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

Thanks for sharing! Very clever using the filter function to clear out the extraneous bits. Do you also have it combined with the original script from here? http://autosportlabs.net/BMW_E46_CAN We recently added steering angle to the channels.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

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

Post by Mustangkev »

Yep. I started with the base script that you had available and then added to it.
Next step is to tap in to the ride height sensors for the auto-leveling headlights and use them as shock position channel.

brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

Awesome. Are there ride height sensors on all 4 wheels of the E46, or just certain corners? Did you find out if that data is exposed on CAN bus as well?


We'll combine the two scripts together and notify here you or someone else could test the latest.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

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

Post by Mustangkev »

The ride height sensors are on the left side front and rear. It should be reasonable simple to add additional ones to the right side though. From what I've read, no data is available over the CAN bus from the light control module. The module does have the can bus wires running to it but I believe that is because it stores mileage, VIN and vehicle order as backup the the instrument cluster.

smallspeed
Posts: 43
Joined: Mon Nov 30, 2015 1:08 pm
Location: Leicester, UK

Post by smallspeed »

I have a mk60 ABS system from the E46 M3 in my car, and have CAN bus messages activated and broadcast.. I am going to give your script a try over the weekend - I have removed things like oil temp and TPS as I have a standalone ECU for the engine which doesn't output this data unfortunately :(

Given you have steer angle, wheel speeds, brake activation, etc working, I wondered if anyone has been able to read the brake pressure sensors (F / R) in the ABS system as well?
I did a search and can't see any reference to it anywhere...

brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

The 2.8.7 release here: https://www.autosportlabs.com/2-8-7-fir ... has-moved/

includes support for bitOp, which means it'll be much easier to extract certain E46 data that spans un-even byte boundaries, like fuel level and individual wheel speeds.

From what I understand, brake pressure is not consistently available on all cars; it depends on how the car is optioned.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

smallspeed
Posts: 43
Joined: Mon Nov 30, 2015 1:08 pm
Location: Leicester, UK

Post by smallspeed »

ok thanks will take a look :)
my car isn't actually an e46 but it has the e46 m3 (mk60 teves) abs system with m-track enabled, can emulator, yaw sensor, steer sensor, etc, etc..
hopefully will be getting the unit reprogrammed soon for the full motorsport software which might make it easier to pull things like this off the CAN network too

brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

Here's an experiemental script that enables 15 channels from the E46 CAN bus leveraging the new capabilities of the 2.8.7 firmware.

It's completely untested; and as I don't have an E46 I can only simulate the data by using a 2nd RCP.

https://gist.github.com/brentpicasso/98 ... 066b82c92e

Note, some channels may not have data depending on the specific E46 platform. Brake pressure seems to be one that's commonly missing. Note the script enables the brake switch, separate from brake pressure.

If you have a chance to test it let me know; be forewarned, it could work perfectly or be completely broken. But if you do test it let us know what does work.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

smallspeed
Posts: 43
Joined: Mon Nov 30, 2015 1:08 pm
Location: Leicester, UK

Post by smallspeed »

Very new to lua scripting (like this is my first time doing ANYTHING)
Can anyone comment on this modification?.. Will this give me degrees C rather than F? And do my min/max values have to be exactly the same as before (converted values) or is "near enough = good enough)

--add your virtual channels here
--format addChannel(<name>, <sample rate>, <precision>, <min>, <max>, [units])
tpsId = addChannel("TPS", 10, 0, 0, 100, "%")
tempId = addChannel("EngineTemp", 1, 0, -18, 125, "C")
oilTempId = addChannel("OilTemp", 1, 0, -18, 125, "C")
rpmId = addChannel("RPM", 10, 0, 0, 10000)
steerId = addChannel("Steering", 10, 0, -360, 360, "Deg.")
brakeId = addChannel("BrakeSw", 10, 0, 0, 1)
brakePressId = addChannel("Brake", 10, 0, 0, 255, "Bar")
clutchId = addChannel("Clutch", 10, 0, 0, 1)
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")
gearTempId = addChannel("GearboxTmp", 10, 0, 0, 205, "C")
fuelId = addChannel("Fuel", 1, 0, 0, 100, "%")
extTempId = addChannel("ExtTemp", 1, 0, -18, 50,"C")

--Convert C to F
--function toF(value)
--return value * 1.8 + 32
end

brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

Hi,

first, note we've announced the extended E46 channels here:

https://www.autosportlabs.com/help-us-t ... -channels/

To not perform the C to F conversion, you can remove the "toF" reference in the mapping.

See line 107, 110 and 111 here in the current script:
https://gist.github.com/brentpicasso/98 ... 066b82c92e

you would just remove the part of the line that is

, toF

(remove the comma and the "toF" portion)

so, line 107 looks like this - see how the ", toF" is missing?

map_chan(tempId, data, 1, 1, 0.75, -48 )

Alternatively, you can modify the "toF" function to not do the conversion.

You can do this starting on line 29

--Convert C to F
function toF(value)
return value
end

You can see how it returns just the value without performing any conversion.

Hope this helps - please report back on your findings.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

smallspeed
Posts: 43
Joined: Mon Nov 30, 2015 1:08 pm
Location: Leicester, UK

Post by smallspeed »

Awesome thanks - I'm really new to any kind of programming but use excel a lot - this seems like a half way house so looking forward to playing!
I've not really tested yet but at first glance I don't think I can see brake pressure values on a car with mk60 abs (conti-teves from m3 e46) but I was under the impression that the brake pressure values are not transmitted via CAN on this system anyway.. My car isn't the definitive answer though as its standalone abs / DSc in an e36..

brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

Thanks - either way, let us know what works and what doesn't. :)
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

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

Post by Mustangkev »

I just uploaded this and took a drive around the block. The only two items that don't work for me are gearbox temperature and brake pressure. Every other parameter provided a reading. This was tested on a 2004 M3.

brentp
Site Admin
Posts: 6282
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

Thanks for testing! Not surprised on those channels not working.

Did your fuel level seem accurate, in %?
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

Post Reply