PDA

View Full Version : Trouble using inline-if function (iff) in calc_pids.txt



Mr. P.
June 2nd, 2011, 04:13 AM
I tried to make a custom PID to display boost pressure on a gauge control; the slot definition I used is:

*CLC-00-162 PSI 0 29.0 .1 "iff({SAE.MAP.kPa} > 100, ({SAE.MAP.kPa} - 100) / 100 * 14.696, 0)"

My Parameter Reference Number definition looks like this:
CALC.BOOST F008 CLC-00-162 "PSI" Air "Intake Manifold Boost Pressure"

And this doesn't work; when I use it on a log that has SAE.MAP > 100, I still get "zero" on my CALC.BOOST PID even in those areas where MAP was 150+.

Can anyone spot the error in my use of the iff function?

Mr. P.

WeathermanShawn
June 2nd, 2011, 05:55 AM
Mr. P.

I'm no expert on coding calculated pids, but I believe the "iff" function need a Yes or No logic applied to it:

"iff({CALC.PE}, {CALC.WO2BEN}, {CALC.LTFTBEN})"

For example, iff CALC.PE is true, then ..., if CALC.PE not true, then...

They are very tricky to set-up. Best bet is to PM JC..hope he is not busy and if your calc pid applies to a lot of users, then it might get done quicker.

Good luck..

joecar
June 2nd, 2011, 06:39 AM
*CLC-00-162 PSI 0 29.0 .1 "iff({SAE.MAP.kPa} > 100, ({SAE.MAP.kPa} - 100) / 100 * 14.696, 0)"That should read like this:
*CLC-00-162
psi 0 29.0 .1 "iff({SAE.MAP.kPa} > 100, ({SAE.MAP.kPa} - 100) / 100 * 14.696, 0)"

i.e. note the line split after the CLC-00-162.

BTW: psi is already defined, so you don't have to define PSI, but this isn't the problem.
BTW: note the 0 and 29 are min/max display limits on the chart/gauge (30 looks nicer).
BTW: make sure there are two blank lines at the end of the calc_pids.txt file.
BTW: boost should be referenced to BARO (e.g. Shawn lives at 5300 ft elevation).
BTW: are you trying to make a boost pid...? if so then simply need to define this:
*CLC-00-162
psi 0 30 .1 "{SAE.MAP.psi}-{SAE.BARO.psi}"
kPa 0 200 .1 "{SAE.MAP.kPa}-{SAE.BARO.kPa}"

and then:
CALC.BOOST F008 CLC-00-162 "psi,kPa" Air "Intake Manifold Boost Pressure"

CALC.BOOST will show boost as a positive value, and vacuum as a negative value (i.e. vacuum is negative boost)...
if you really and truly did not want to see vacuum, then define this:
*CLC-00-162
psi 0 30 .1 "iff({SAE.MAP.psi}>{SAE.BARO.psi}, {SAE.MAP.psi}-{SAE.BARO.psi}, 0)"
kPa 0 200 .1 "iff({SAE.MAP.kPa}>{SAE.BARO.kPa}, {SAE.MAP.kPa}-{SAE.BARO.kPa}, 0)"

and of course you still need this:
CALC.BOOST F008 CLC-00-162 "psi,kPa" Air "Intake Manifold Boost Pressure"



:)

joecar
June 2nd, 2011, 06:45 AM
I like to make my Fxxx numbers the same as the CLC-00-xxx numbers wherever I can, but it is not required.

Mr. P.
June 3rd, 2011, 02:28 AM
...I believe the "iff" function need a Yes or No logic applied to it...
Nope; according to the EFILive manual, the conditional [first] parameter is either Zero, or non-Zero; depending on the implicit type conversion used in the underlying software that EFILive is developed with, I am assuming from their literature that False = Zero (0), and True to be "anything not False" i.e. anything non-Zero (including negative numbers, decimals, etc). USUALLY. This is not always the case across all programming languages and platforms.

Mr. P.

joecar
June 3rd, 2011, 02:57 AM
Yes, zero is false, non-zero is true (same sematics as the C programming language)... this means that negative values are true (since they are non-zero).

Mr. P.
June 3rd, 2011, 03:51 AM
That should read like this: ...


Thanks joecar, I appreciate it; I've experiemented for a half-hour and still cannot make the iff function work. :(

I even tried abstracting the sub-formulas out of the function, i.e. I made a PID called CALC.IN_BOOST, and it works returning either 1 or 0 when Kpa > 100; I made CALC.MANVAC which returns the mathematical PSI, and it works correctly; but when I try to make a PID called CALC.BOOST = "iff({CALC.IN_BOOST}, {CALC.MANVAC}, 0)" that just returns a value of zero at all times. I am wondering if the functions in EFILive do not support expressions or constants... ??? and have run out of time to debug through experimentation exactly how they tick.

So frustrating.

Mr. P.

PS - there may be something else at fault, because I select/enable the PIDs, but they do not appear in the Data folder tab (?) but can be bound to my chart/dashpage (??) and draw a flatline at zero. I suspect there is a "mis-binding" somewhere. Maybe it would help to know what the PRN exactly is. I dunno.

joecar
June 3rd, 2011, 05:11 AM
Mr.P post your calc_pids.txt file here, I'll take a closer look at it...

mr.prick
June 3rd, 2011, 07:26 AM
Have you tried removing some commas?
"iff({SAE.MAP.kPa}>100,{SAE.MAP.kPa}-100/100*14.696, 0)"

Blacky
June 3rd, 2011, 08:48 AM
I tried to make a custom PID to display boost pressure on a gauge control; the slot definition I used is:

*CLC-00-162 PSI 0 29.0 .1 "iff({SAE.MAP.kPa} > 100, ({SAE.MAP.kPa} - 100) / 100 * 14.696, 0)"

My Parameter Reference Number definition looks like this:
CALC.BOOST F008 CLC-00-162 "PSI" Air "Intake Manifold Boost Pressure"

And this doesn't work; when I use it on a log that has SAE.MAP > 100, I still get "zero" on my CALC.BOOST PID even in those areas where MAP was 150+.

Can anyone spot the error in my use of the iff function?

Mr. P.

I've been testing the expression you posted and it appears that the parenthesis in the expression: ({SAE.MAP.kPa} - 100) / 100 * 14.696 are causing the expression to evaluate to 0.
If that is the case, then its obviously a bug and needs to be fixed. I'm still working on figuring out if that is really the case.

Regards
Paul

Blacky
June 3rd, 2011, 09:44 AM
I can confirm it is a bug in the expression parser. This type of expression:

iff(condition,(true expression),false expression)

fails to compile properly because the expression parser incorrectly identifies the right parenthesis which is part of the "true expression" as the terminating parenthesis for the iff() function.
That causes the iff() function to compile with only two arguments which in turn cause the iff() function to not be evaluated at all because it does not have 3 arguments.

It will be fixed asap.

Meanwhile you'll need to rewrite the expression to not use parenthesis.
({SAE.MAP.kPa} - 100) / 100 * 14.696
can be rewritten without parenthesis as:
{SAE.MAP.kPa}*0.14696 - 14.696

Regards
Paul

Blacky
June 3rd, 2011, 09:55 AM
I have also now added the following diagnostic messages to StartupLog.txt


10:51:50.285|2980| InFix: iff(3 args: SAE.MAP.kPa > 70 , ( SAE.MAP.kPa - 70 ) / 100 * 14.696 , 0 )
10:51:50.285|2980|Post Fix: SAE.MAP.kPa 70 > SAE.MAP.kPa 70 - 100 / 14.696 * 0 iff(3 args) That shows the algebraic (or in fix) form of the expression, followed by the parsed and compiled reverse polish notation (rpn or post fix) form of the expression.
It also shows the number of arguments parsed for each function.

To generate the StartupLog.txt file append " /l" (that's space forward slash lowercase L) without the quotes to the shortcut that starts the Scan Tool (or Tuning Tool) software.

Regards
Paul

Blacky
June 3rd, 2011, 10:09 AM
And before any C programmers ask...
The iff() function in EFILive will evaluate both the true and false expressions prior to evaluating the conditional expression.
Unlike the C operator ?: which only evaluates one of the true or false expressions after evaluating the conditional expression.

Regards
Paul

Mr. P.
June 4th, 2011, 01:34 PM
You da man! Thanks for giving this attention, it is greatly appreciated.

Mr. P. :)