Page 1 of 1

Some E36 scripts

Posted: Mon May 08, 2017 1:57 am
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(10) --10Hz

--virtual channels
--addChannel("name",SR,prec,min,max,"unit")
speeddiff_id = addChannel("Speed_",10,0,0,160,"MPH")
gear_id = addChannel("Gear_",5,0,0,5,"gear")


--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()
	rpm_diff = getTimerRpm(1)
	speed = rpm_diff*tirediameter*0.002975
	speed = speed + 0.5 -- round because 0 prec. truncates
	setChannel(speeddiff_id, speed)
end

function updateGear()
	rpm = getTimerRpm(0)
	local gearErr = 0.15
	local gear = 0
	
	if speed > 2 then
		ratio = rpm/(rpm_diff*final)
		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

Posted: Mon May 08, 2017 2:02 pm
by brentp
Awesome, I'll add this to the Wiki under the E36 section. Thank you!

Posted: Mon May 08, 2017 2:06 pm
by brentp

Posted: Mon May 08, 2017 5:24 pm
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

Posted: Mon May 08, 2017 5:50 pm
by brentp

Posted: Tue May 09, 2017 2:05 am
by loftygoals
It should be mentioned in the wiki that it is assumed the differential input attached to the second RPM input.

-bj

Posted: Wed May 10, 2017 3:12 am
by brentp
Got it.

Posted: Thu Jun 15, 2017 6:57 pm
by TXBDan
Hey Brent,

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

Posted: Thu Jun 15, 2017 6:58 pm
by brentp
Actually, the latest 1.10.1 beta software supports underscores as well as spaces. That was a change I just made.

Posted: Tue Jun 20, 2017 1:19 pm
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.

Posted: Tue Jun 20, 2017 3:51 pm
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!

Posted: Fri Jun 23, 2017 8:58 pm
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.