Some E36 scripts

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
TXBDan
Posts: 68
Joined: Sat Mar 25, 2017 1:43 am

Some E36 scripts

Post by TXBDan »

Here are a couple scripts I wrote for my E36 M3. Having the speed sensor in the rear diff is handy. Change the constants to suit your diff ratio and tire size of course. Feel free to suggest how to improve them.

Code: Select all

setTickRate&#40;10&#41; --10Hz

--virtual channels
--addChannel&#40;"name",SR,prec,min,max,"unit"&#41;
speeddiff_id = addChannel&#40;"Speed_",10,0,0,160,"MPH"&#41;
gear_id = addChannel&#40;"Gear_",5,0,0,5,"gear"&#41;


--global constants
first = 4.20
second = 2.49
third = 1.66
fourth = 1.24
fifth = 1.00
final = 3.46
tirediameter = 24.7

--global variables
rpm = 0
rpm_diff = 0
speed = 0

function updateSpeedDiff&#40;&#41;
	rpm_diff = getTimerRpm&#40;1&#41;
	speed = rpm_diff*tirediameter*0.002975
	speed = speed + 0.5 -- round because 0 prec. truncates
	setChannel&#40;speeddiff_id, speed&#41;
end

function updateGear&#40;&#41;
	rpm = getTimerRpm&#40;0&#41;
	local gearErr = 0.15
	local gear = 0
	
	if speed > 2 then
		ratio = rpm/&#40;rpm_diff*final&#41;
		if &#40;&#40;first  - ratio&#41;^2&#41; < &#40;gearErr^2&#41; then gear = 1 end
		if &#40;&#40;second - ratio&#41;^2&#41; < &#40;gearErr^2&#41; then gear = 2 end
		if &#40;&#40;third  - ratio&#41;^2&#41; < &#40;gearErr^2&#41; then gear = 3 end
		if &#40;&#40;fourth - ratio&#41;^2&#41; < &#40;gearErr^2&#41; then gear = 4 end
		if &#40;&#40;fifth  - ratio&#41;^2&#41; < &#40;gearErr^2&#41; then gear = 5 end
	end
     setChannel&#40;gear_id, gear&#41;
end

function onTick&#40;&#41;
  updateSpeedDiff&#40;&#41;
  updateGear&#40;&#41;
end

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

Post by brentp »

Awesome, I'll add this to the Wiki under the E36 section. Thank you!
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

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

Post by brentp »

Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

TXBDan
Posts: 68
Joined: Sat Mar 25, 2017 1:43 am

Post by TXBDan »

cool!

The diff speed signal is on a black w/ white stripe wire and can be found:
Pin 2 on connector X17 to the back of the gauge cluster
Pin 10 on connector X22 on the cruise control module behind the glove box
Pin 10 on radio connector

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

Post by brentp »

Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

loftygoals
Posts: 26
Joined: Fri Oct 31, 2014 4:21 am
Location: Dallas, TX

Post by loftygoals »

It should be mentioned in the wiki that it is assumed the differential input attached to the second RPM input.

-bj

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

Post by brentp »

Got it.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

TXBDan
Posts: 68
Joined: Sat Mar 25, 2017 1:43 am

Post by TXBDan »

Hey Brent,

Since the latest software only supports alphanumerica characters for channel names, we should update this script to remove the underscores.

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

Post by brentp »

Actually, the latest 1.10.1 beta software supports underscores as well as spaces. That was a change I just made.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

TXBDan
Posts: 68
Joined: Sat Mar 25, 2017 1:43 am

Post by TXBDan »

Ah that's good. I'm still confused as to whether i can overwrite existing channels or not so i like to put an underscore after all the ones that i make to keep things clear.

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

Post by brentp »

You need to define unique channel names. Having duplicate names will cause problems in dashboard and analysis.

In dashboard mode, the duplicate channels will both update the same gauge, causing erroneous readings.
In analysis, data is funneled into a single channel name, so you will have problems importing and displaying data.

Hope this resolves the confusion!
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

TXBDan
Posts: 68
Joined: Sat Mar 25, 2017 1:43 am

Post by TXBDan »

brentp wrote:You need to define unique channel names. Having duplicate names will cause problems in dashboard and analysis.

In dashboard mode, the duplicate channels will both update the same gauge, causing erroneous readings.
In analysis, data is funneled into a single channel name, so you will have problems importing and displaying data.

Hope this resolves the confusion!
Ah, that does help. Is there anyway to delete or rename existing channels? In some ways it would be nice to have no predefined channels, only hardware or virtual channel resources that i could then name myself. But i guess that could get ugly.

For example, I would like to use "Speed" for my speed sensor and not the GPS speed as it is by default.

Post Reply