Torque

Forums

Forums

Guest  

Show or hide header
Welcome Guest, posting in this forum require registration.




Torque » Torque OBD ECU Scanner » Torque Discussion / Ideas » Implementing boolean conditionals at PID editor

Pages: [1]
Author Topic: Implementing boolean conditionals at PID editor
rsfjr87
Member
Posts: 18
Post IF on the equation editor
on: January 8, 2019 (GMT)

Gentlemen,

I see that many people would like to use some sort of IF statement at the equation editor in the PID editor.

You could using boolean algebra to do that.

For example, let’s imagine that one would want to implement a RPM monitor:

The custom pid would output equation/values:
0 for RPM = 500) && ([0C] < 1000) ) { Do equation R3*256 } If( ([0C] >= 1000) ) {
Do equation R5*256 + R4
}

In order to do that, we must use int(), so that we only get integers, rounded down.

I am going to name those expressions bellow to make things lean:
A = int( ( [0C] ) / (int([0C]/500)*500+0.01) )
B = int( ( [0C] ) / (int([0C]/1000)*1000+0.01) )

The 0.1 is chosen randomly, just to prevent division by 0. It should be a fraction between -1 and 1, different than 0. And small enough, in order to keep the errors low.

Observe that A results in:
0, for [0C] = 0 to 500.01
1, for [0C] > 500.01
And so on

B results in:
0, for [0C] = 0 to 1000.01
1, for [0C] > 1000.01
And so on.

If we do (1-A), then it equals to 1 for 0

Capp777
Member
Posts: 2993
Post Re: Implementing boolean conditionals at PID editor
on: January 10, 2019 (GMT)

lookup([0c]::0~500=(A*256):500~9999=((A*256)+B))
should work too.

(lookup([0c]::0~500=1:500~9999=0)*(A*256))+
(lookup([0c]::0~500=0:500~9999=1)*((A*256)+B))

rsfjr87
Member
Posts: 18
Post Re: Implementing boolean conditionals at PID editor
on: January 20, 2019 (GMT)

Thanks!

Pages: [1]
WP-Forum by: Fredrik Fahlstad, Version: 2.4
Page loaded in: 0.012 seconds.

  Follow me on twitter