Torque

Forums

Forums

Comprehensive list ...
 
Notifications
Clear all

Comprehensive list of PID operators and functions

120 Posts
46 Users
0 Reactions
7,243 Views
(@frodus)
Posts: 518
Honorable Member
Topic starter
 

I've compiled a comprehensive list of PID operators and functions from various posts into one thread. If you know of any additional, post below and I will edit this post and try to keep near the top,or if Ian can STICKY, that'd be awesome.

I've found these:

* — multiply, example 256*A
/ — Divide, example A/10
+ — Add, example 256*A+B
- — Subtract, example B-10
& - Logical AND, example A&4
() — precedence operator, example (256*A+B)*0.1
{A:b} — returns the bth bit of the byte A. Least significant bit is 0, example A = 00001010b = 09h, {A:0} = 0; {A:1} = 1
[XX] - returns the value of a PID, where XX is the ID of the OBD2 sensor. i.e. [0d] (speed) or [ff1001] (gps speed)
Baro() returns barometer psia from [33] – Vehicle or [ff1270] – Phone.
A^B - returns A to the power of b
Log10(A) - returns the Log(base 10) of A
SIGNED(A) returns decimal value of A assuming highest bit is a sign bit
ABS(A) returns absolute value of A
VAL{sensor name} returns the value of the sensor, make sure this matches exactly. Sensor names are their untranslated names.

Piemmm,

Do you have a full list of all the math that is available? Even if you email it to me, I can write it up and document it here. I just don't know if there are any more available.

Also, suggest having a MIN() and MAX() that returns a running minimum or maximum of a particular PID.

 
Posted : 07/03/2014 5:46 pm
(@vasilich)
Posts: 226
Reputable Member
 

The custom PID edit window mentions A<8 in its example string, and after testing it I confirm that Torque supports shift operators x<n and x>n in equations.

 
Posted : 05/04/2014 10:35 pm
(@fatih-koz)
Posts: 11
Active Member
 

Hi,

Does Custom PID's support "if" and "else" statements like in asp/php/vb ?

if ([0xff1208] < 7.0) A="ON" else A="OFF"

I'm trying to build a Custom PID which will display a static text as output value.

Any help will be great ...

 
Posted : 30/09/2014 5:59 pm
(@frodus)
Posts: 518
Honorable Member
Topic starter
 

These are all the ones that Ian has ever announced. Might search the change-logs for more, but this is the most comprehensive list of operators that I could come up with after nearly a week of searching through forum topics.

 
Posted : 30/09/2014 7:39 pm
(@fatih-koz)
Posts: 11
Active Member
 

Hi,

I'll monitor the changelogs for future implemantations but for now as far as searched and understood "if" statements are not possible 🙂

I'll try my chance for a simple "0" / "1" result with below equation ;

[0xff1208] < 7.0

So if above code returns 1 then at least I can use the simple on/off display and this will be a good start.

I tested this custom pid without connecting to ecu, the result was 0 and it did not gave an error.

I will post my test results earliest tomorrow at my Fuel Economy Display topic.

Thanks for the reply and detailed list post.

Best wishes

 
Posted : 30/09/2014 8:07 pm
(@frodus)
Posts: 518
Honorable Member
Topic starter
 

For the ON/OFF display to work, all you need is to be above 0 for ON and 0 or less for OFF.

The "

 
Posted : 30/09/2014 9:58 pm
 Hiej
(@hiej)
Posts: 175
Estimable Member
 

Is there someone that could explain what do to a value?

I mean what is the effect to put A < 16 or B < 8 to an equation?

What is the difference to use X < 16 or X < 8 ?

 
Posted : 04/11/2014 7:34 pm
(@moreause)
Posts: 650
Honorable Member
 

Normally are smaller than and bigger than

they are normally use with the if command they don't change the value it's a check

if value A is > than 16 response is 1 (or on) other wise response is 0 (off)

 
Posted : 05/11/2014 9:24 am
(@vasilich)
Posts: 226
Reputable Member
 

http://en.wikipedia.org/wiki/Logical_shift

moreause, you are wrong - Torque use those as shift operators, not compare operators

 
Posted : 05/11/2014 9:26 am
 Hiej
(@hiej)
Posts: 175
Estimable Member
 

so if i put in the equation "A < 16" the binary value of "A" is shifted to left by 16 bits,

if

"A < 8" the binary value of "A" is shifted to left by 8 bits
"A < 4" the binary value of "A" is shifted to left by 4 bits

and so on...

it's correct?

 
Posted : 05/11/2014 11:13 am
(@moreause)
Posts: 650
Honorable Member
 

a that make more sens

but if i understand correctly since A is a 8 bit value
shifting it by 16 would be equal to set it to 0
unless the end bit become the first bit...

 
Posted : 05/11/2014 4:34 pm
(@vasilich)
Posts: 226
Reputable Member
 

Quote from Hiej on November 5, 2014
...
it's correct?

yes, that is correct. Though that time moreause is also correct - that makes no sense to shift to more than 7 bits to the right, as all variables A,B,C,D,E,F are byte values (thus having only 8 bits), so shifting to 8 or more bits to the right is equal to setting those to 0. When shifting to the left, byte values will be expanded to words or dwords, as internal calculations are made in 32 bit.

 
Posted : 06/11/2014 4:46 pm
(@cintakc)
Posts: 1665
Noble Member
 

Quote from frodus on March 7, 2014

{A:b} — returns the bth bit of the byte A. Least significant bit is 0, example A = 00001010b = 09h, {A:0} = 0; {A:1} = 1

error example A = 00001010b = 09h
must be A = 00001010b = 0Ah

 
Posted : 16/08/2015 6:54 am
(@capp777)
Posts: 2999
Famed Member
 

If bit logic is reversed...

ABS({A:b}-1)

Expect parser is not accepting as written.

or

1-{A:b}

Suggested by Cintakc.

Edited.

 
Posted : 01/10/2015 6:33 pm
(@mpd56)
Posts: 276
Reputable Member
 

Thanks Capp777

Good for us old members with poor memory also.

 
Posted : 01/10/2015 10:57 pm
(@capp777)
Posts: 2999
Famed Member
 

Quote from admin on April 21, 2016
Hi! Right! - in the 1.8.92 update you're going to get a new set of variables that you can use in the equation parser...

Torque traditionally takes some of the hard work away when dealing with responses (which is why you don't immediately need to start of with variable D in a lot of cases). The variables starts from A, B, C, for mode 21, 22, 01, etc where the data headers and response status have already been removed for you. (these are also mirrored by variables N0, N1, N2 (etc) for simplicity)

However, with some awkward manufacturers, they may reply with no header at all (with useful information at the start of the packet that you'll want to get at).

To get the variables for the *whole* raw data reply, you can now use the following variables:

R0, R1, R2, R3 (etc) where in most cases R3/4 would equate to 'A' in normal mode21/22/01 messages (depending if you're using canbus or an iso protocol like 9141)

So, R0 ('Raw 0') will get you the absolute start of the message, which should give you access to the bytes you want

So the equation would now look like:

R0 * 5

For the first value in the reply

End Quote.

 
Posted : 22/04/2016 1:37 pm
(@automate)
Posts: 19
Eminent Member
 

What about the length (number of bytes) of the received data? Is it available in a variable to be used in a formula?

 
Posted : 23/04/2016 8:11 pm
(@danger1979)
Posts: 2
New Member
 

1. VAL{sensor name}
Where can I see a full list of sensor name?

2. can I know the name of the variable "tank capacity" from the profile

 
Posted : 28/04/2016 6:04 am
(@capp777)
Posts: 2999
Famed Member
 

Quote from DANGER1979 on April 28, 2016
1. VAL{sensor name}
Where can I see a full list of sensor name?

2. can I know the name of the variable "tank capacity" from the profile

End Quote.

The easiest way is to use Torquescan which
will display the long names of all the pids
known to Torque.

 
Posted : 28/04/2016 10:02 am
(@danger1979)
Posts: 2
New Member
 

The variable “tank Volume” - in TorqueScan not available.
I want to use this variable in the formula customs PIDs.

 
Posted : 29/04/2016 5:53 am
Page 1 / 6
Share:

  Follow me on twitter