1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help reading an evaluation expression

Discussion in 'Gauges' started by jdhughen, 20 Apr 2017.

  1. jdhughen

    jdhughen

    Joined:
    19 Feb 2017
    Messages:
    89
    Country:
    us-southcarolina
    I have bit of code that I'm trying to understand and just can't get to where it makes sense for me. If i can get where i can understand how to interate this i can figure out how to read some of the others i'm working with.

    I have got thru the documentation and think i have figure out all the operators, but just can't put it together into a "If then" type expression that make sense to me.

    as it's written
    Code:
    (A:VELOCITY BODY X, m/s) (A:VELOCITY BODY Z, m/s) atg2 rddg /-/ abs 7 < (A:VELOCITY BODY Y, m/s) (A:VELOCITY BODY Z, m/s) atg2 rddg /-/ 11.5 < && (A:VELOCITY BODY Y, m/s) (A:VELOCITY BODY Z, m/s) atg2 rddg /-/ -5.5 > && if{ 1 (>(L:VectorOnGlass, enum))} els{ 0 (>(L:VectorOnGlass, enum)) }
    I added the "()" for the local Vars, and put it in Infix2Postfix and converted it back from the reverse polish notation format and got this
    Code:
     abs( ( /-/ rddg( atg2( (A:VELOCITY BODY X , m/s),(A:VELOCITY BODY Z , m/s) ) ) ) ) 7 &lt ( /-/ rddg( atg2( (A:VELOCITY BODY Y , m/s),(A:VELOCITY BODY Z , m/s) ) ) ) 11.5 &lt &amp &amp ( /-/ rddg( atg2( (A:VELOCITY BODY Y , m/s),(A:VELOCITY BODY Z , m/s) ) ) ) -5.5 &gt &amp
     if &amp
     {     1 &gt (L:VectorOnGlass , enum)
     } else
     {     0 &gt (L:VectorOnGlass , enum)
     } 
    So i can see that if the evaluation of the expression is true it sets the "L:VectorOnGlass" flag.
    I started in the middle of the () and worked out. I have used Bold Italics in places where I need help.

    starting at the top:
    *******************
    Absolute value of (negate(radians to deg (in radians - ArcTangent2 of ( VBody X , VBody Z in meters/sec ??)))) --- I think this is right although i don't know why you would bother to negate a number you are going to take the absolute value of? also while the SDK list A:Velocity Body X as feet per second, i assume that the ",m/s" parameter request changes that to meters/sec ?

    7 &lt -- would this read, previous is (less than) < 7 ?? or does the < connect to the next section of the expression as in "previous < following" ?

    then....
    Negate(radians to Deg(in radians - ArcTangent2 of ( VBody Y , VBody Z in meters/sec ??)))

    11.5 &lt &amp &amp -- I am totally confused here please help. Does the double &amp mean , if the previous is true AND the following is True ??

    then....
    Negate(radians to Deg(in radians - ArcTangent2 of ( VBody Y , VBody Z in meters/sec ??)))

    -5.5 &gt &amp - greater than something ? I can't get a grip on the "&amp" thing and how it connect things together

    if &amp -- If True

    set flag to 1
    else
    set flag to 0
    ************************

    If someone could please fill in the blanks for me here and set me on the right path.

    thanks
    Joel
     
  2. WarpD

    WarpD

    Joined:
    9 Dec 2007
    Messages:
    892
    Country:
    us-ohio
    Code:
     if ( ( ( abs( ( /-/ rddg( atg2( (A:VELOCITY BODY X , m/s),(A:VELOCITY BODY Z , m/s) ) ) ) ) < 7 ) && ( ( /-/ rddg( atg2( (A:VELOCITY BODY Y , m/s),(A:VELOCITY BODY Z , m/s) ) ) ) < 11.5 ) ) && ( ( /-/ rddg( atg2( (A:VELOCITY BODY Y , m/s),(A:VELOCITY BODY Z , m/s) ) ) ) > -5.5 ) ) ( 
     {    > 1 ) (L:VectorOnGlass , enum) 
     } else ( 
     {    > 0 ) (L:VectorOnGlass , enum) 
     } 
     
  3. tgibson

    tgibson

    Joined:
    22 Sep 2006
    Messages:
    6,582
    Country:
    us-california
    According to the SDK all these units are identical:

    meter per second, meters/second, m/s

    &amp ;&amp ; (without the spaces) means &&, which according to the SDK means: AND

    that's it - it just means AND. So the top two conditions on the stack must both be true for the result to be true.

    Hope this helps,
     
  4. Ronald

    Ronald Resource contributor

    Joined:
    26 Jan 2015
    Messages:
    395
    Is this fragment from C++, XML? a mix of both? or another programming language?

    Here are some ESP SDK links that might be helpful decoding this fragment:
    - https://msdn.microsoft.com/en-us/library/cc526958.aspx - Creating XML Gauges
    - https://msdn.microsoft.com/en-us/library/cc526953.aspx - Creating C++ Gauges
    - https://msdn.microsoft.com/en-us/library/cc526981.aspx - Simulation Variables
    - https://msdn.microsoft.com/en-us/library/cc526980.aspx - Event ID's
     
  5. taguilo

    taguilo Resource contributor

    Joined:
    20 Oct 2006
    Messages:
    1,456
    Country:
    argentina
    I don't recommend that conversion because, as you can see, most of times gives wrong results, like in this case.

    IMO the best mode to understand a script like that is to separate it in parts according to evaluators/conditionals/assignments present in the code.

    So let's analyze your script. We will find:

    Values
    =====
    (A:VELOCITY BODY X, m/s)
    (A:VELOCITY BODY Z, m/s)
    (A:VELOCITY BODY Y, m/s)
    7
    11.5
    -5.5

    Operators
    ======
    atg2
    rddg
    /-/
    abs

    Evaluators
    =======
    &lt; (lower than)
    &amp;&amp (and)

    Conditionals
    =======
    if{}
    els{}

    Assignments
    ========
    (&gt;L:VectorOnGlass, enum)

    First, you split the code using the evaluators as a reference:

    Value = (A:VELOCITY BODY X, m/s) (A:VELOCITY BODY Z, m/s) atg2 rddg /-/ abs Lets call it [EV1] (/-/ operator is redundant)
    Evaluator = 7 &lt;

    Value = (A:VELOCITY BODY Y, m/s) (A:VELOCITY BODY Z, m/s) atg2 rddg /-/ Let's call it [EV2]
    Evaluator = 11.5 &lt;

    Value = same as [EV2]
    Evaluator = -5.5 &gt;

    Now you insert the &amp;&amp; (and) evaluator:
    [EV1] 7 &lt;
    [EV2] 11.5 &lt;
    &amp;&amp;


    Meaning "if [EV1] is lower than 7 and [EV2] is lower than 11.5 then result is 1, else is 0" . Let's call this result [EV3]

    Then it comes the second &amp;&amp; (and) evaluator:
    [EV3] [EV2] -5.5 &gt; &amp;&amp;

    Meaning "if [EV3] is 1 and [EV2] is greater than -5.5 then result is 1, else is 0" . Lets call this result [EV4]

    Finally you have
    [EV4] if{ 1 (&gtL:VectorOnGlass, enum) } els{ 0 (&gt;L:VectorOnGlass, enum) }

    Meaning "if [EV4] is 1 then assign 1 to (L:VectorOnGlass, enum) else assign 0 to (L:VectorOnGlass, enum)"

    With this simple method you will be able to decipher complex scripts without needing for an -erratic- Infix2Postfix conversion.

    Once you adquire experience you'll find that is much easier to handle these kind of scripts in their "compact" version:

    Code:
      (A:VELOCITY BODY X, m/s) (A:VELOCITY BODY Z, m/s) atg2 rddg abs sp0
      (A:VELOCITY BODY Y, m/s) (A:VELOCITY BODY Z, m/s) atg2 rddg /-/ sp1
      l0 7 &lt; l1 11.5 &lt; and  l1 -5.5 > and (>L:VectorOnGlass, enum)
    
    Using registers (s0...s49) and direct boolean (1-0) assignments.


    Tom
     
    Last edited: 20 Apr 2017
    jdhughen and antaris like this.
  6. jdhughen

    jdhughen

    Joined:
    19 Feb 2017
    Messages:
    89
    Country:
    us-southcarolina
    Thank you all for the timely responses. it all makes more sense now.
    Yes this is all XML gauge code (FS9 schema)

    i just want to make sure I have this 1 thing right....

    When you see &amp;&amp; in a script it means AND as in together or Also or "this AND that" not a AND operator, like a bitwise AND function ?

    If so then then writing an expression you could use &amp;&amp; to string several conditional evaluations together that all need to be true to get an overall true result ?

    Also Tom, thanks for the detail process it makes sense now. your streamlined version of the code does lead me to a couple of question about (s0...s49) registers. mainly how long do they hold their value for ? I have several pieces that are moved around by the exact same wordy lengthy expression. Currently I have all that code applied to each piece (ie BMPs, each in it's on element but all children of the same parent element). As in your example could i evaluate once storing the result in a couple registers and apply the result to all the pieces separately or would it be better to use L:vars for this type temp of storage expression evaluations ?

    Joel
     
  7. jdhughen

    jdhughen

    Joined:
    19 Feb 2017
    Messages:
    89
    Country:
    us-southcarolina
    This make's total sense and is a lot easier to read to me that what i stated with. so when writing XML in FSX9 schema can you use < , > , instead of &lt , &gt ?

    Joel
     
  8. tgibson

    tgibson

    Joined:
    22 Sep 2006
    Messages:
    6,582
    Country:
    us-california
    You can use > but you cannot use <, because it triggers an error.

    And technically false is 0 and true is "non zero". It doesn't have to be 1.
     
  9. n4gix

    n4gix Resource contributor

    Joined:
    26 Sep 2006
    Messages:
    10,581
    Country:
    unitedstates
    A double-ampersand '&&" is a logical 'and'
    A single ampersand '&' is a bitwise 'and'

    For both convenience, clarity and my own continued sanity, I use exclusively the textural 'and' and 'or' when scripting logic.
    Yes. However such expressions use the Reverse Polish formation: (Condition1) (Condition2) and
    Stack Registers (of which you are limited to 50), are global only within the scope of a single xml 'gauge'. They cease to exist once the gauge is unloaded of course.
     
  10. jdhughen

    jdhughen

    Joined:
    19 Feb 2017
    Messages:
    89
    Country:
    us-southcarolina
    Bill,

    So just to be clear if you use textual "and" "or" we are talking logical operators and not bitwise?

    So with stack registers, if you had the same expression that was applied to shift calculation of 6 or 7 different bmps each cycle thru the code is there a significant enough savings in cpu clicks to employ the use of stack registers so the script only evaluates once ? and are stack registers faster/better/resource friendler over say use L:vars if you only need them while the gauge is working. ?

    Thanks
    Joel
     
  11. jdhughen

    jdhughen

    Joined:
    19 Feb 2017
    Messages:
    89
    Country:
    us-southcarolina
    So is that because we are talking about XML and the parser thinks your opening a tag ?
    Would "<" be valid in C++ ?

    Joel
     
  12. Ronald

    Ronald Resource contributor

    Joined:
    26 Jan 2015
    Messages:
    395
    Thanks for the feedback on this code-fragment.

    Question (to all): What is the best place to start learning, understanding XML for FS9/X?
     
  13. vololiberista

    vololiberista

    Joined:
    24 Aug 2009
    Messages:
    1,384
    Country:
    italy
    The place where you go when nature calls ;)
     
  14. taguilo

    taguilo Resource contributor

    Joined:
    20 Oct 2006
    Messages:
    1,456
    Country:
    argentina
    Check this thread for a proper answer:
    http://fsdeveloper.com/forum/threads/l-var-vs-storage-register-in-xml.439393/#post-764978

    Tom
     
  15. n4gix

    n4gix Resource contributor

    Joined:
    26 Sep 2006
    Messages:
    10,581
    Country:
    unitedstates
    Yes, those are logical operators.

    I can count the number of times I've needed to resort to bitwise operations on one finger... I'm joking of course, but not more than a few hands worth of fingers! :rotfl:
     
  16. jdhughen

    jdhughen

    Joined:
    19 Feb 2017
    Messages:
    89
    Country:
    us-southcarolina
    Tom,
    Thanks again for this detailed explaination. I have printed it out and taped it up on my project board.

    So could you use a similar process to write scripts in RMP? or does the Infix2Postfix work any better go "to" RPN than "from"?

    Joel
     

Share This Page