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
Posts: 14
Post IF on the equation editor
on: January 8, 2019 (GMT)


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

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

should work too.


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

  Follow me on twitter