IF statements not working properly in v4

AlexisVGR
Posts: 21
Joined: Wed Jan 18, 2012 8:23 am

IF statements not working properly in v4

Postby AlexisVGR » Mon Jul 17, 2017 11:23 am

I am trying to port over our F-4 Phantom into P3Dv4. The coding for the aircraft has been done using FS9 XML schema, along with XMLTools in order to be able to set simvars using XML. The same XML gauges were working properly in P3Dv2 and v3.

XML Tools x64 has been installed and works properly, but my XML scripts work selectively and I explain:

User input is masked and assigned to L:vars for Yoke X,Y and pedals, with a range from -16k to 16k. These values are used to drive systems like Stability Augmentation, Autopilot, Trim and the control surfaces themselves.

After the calculations are done, all the variables that affect the elevator (stick, trim, AP etc) are added together and assigned to (A:ELEVATOR POSITION, percent) and so on for the remaining surfaces. In a simple diagram:

(1) Masked user input to Lvar->(2) Lvars for various subsystems->(3) subsystems added into single Lvar->(4) addition of values to Avar

The problem is that this works fine for the ailerons, but the elevator stick values don't update.

After doing some tracking, I found out that the problem lies in my if statements, which are not parsed consistently.

For the stick to move the elevators, the Autopilot needs to be off. This check fails every time.

Similarly, an Lvar initialization check done in another gauge also fails at the same point, the very first IF statement.

I tried updating the gauges to use the new schema, encoded in UTF-8, but the results were identical.

What could be the problem here? Prepar3D Version is 4.0.28.21686

Clifton Crane
Lockheed Martin
Posts: 726
Joined: Tue Sep 25, 2012 2:34 pm

Re: IF statements not working properly in v4

Postby Clifton Crane » Mon Jul 17, 2017 8:09 pm

Hi Alexis,

Could you post an example if-statement that is not working correctly?

Thanks.
Clifton Crane
Prepar3D® Software Engineer

AlexisVGR
Posts: 21
Joined: Wed Jan 18, 2012 8:23 am

Re: IF statements not working properly in v4

Postby AlexisVGR » Tue Jul 18, 2017 10:45 am

Hello Clifton. Here is an example:

Code: Select all

(A:AUTOPILOT MASTER, bool) 0 == if{ (L:ELEV, number) -163.83 / abs 1 >= if{ (L:ELEV, number) -163.83 / (L:PITCH_FEEL, number) * (L:ELEV_TRIM, number) + -100 max 100 min (>L:YOKE_Y, number) } els{ (L:ELEV_TRIM, number) -100 max 100 min (>L:YOKE_Y, number) } (E:ZULU TIME, seconds) (>L:APTIMER, seconds) } els{ (L:ELEV, number) -163.83 / abs 1 < if{ (E:ZULU TIME, seconds) (>L:APTIMER, seconds) (L:ELEV_TRIM, number) -100 max 100 min (>L:YOKE_Y, number) } (E:ZULU TIME, seconds) (L:APTIMER, seconds) - 0.5 >= if{ (L:ELEV, number) -163.83 / (L:PITCH_FEEL, number) * (L:ELEV_TRIM, number) + -100 max 100 min (>L:YOKE_Y, number) } }
(L:ELEV, number) is the +/-16k value of the elevator from the user's stick input.
The expression "(L:ELEV, number) -163.83 / abs 1 >= if{ " never evaluates in v4, leading to a dead elevator.

On one occasion while debugging, I noticed that the (A:AUTOPILOT MASTER, bool) 0 == if statement at the very top was evaluated inversely. Specifically, when the Autopilot was 1, the if code was executed, whereas when it was 0, the "els" was ran.

Another occasion is during an initialization where the statement is:

Code: Select all

(L:F4TABLEINIT, bool) 0 == if{ ....starting...conditions... 1 (>L:F4TABLEINIT, bool) quit }
If it helps, I can PM you the entire gauge so you can see it in a more clear manner.

dsdawson
Posts: 24
Joined: Sat Jan 14, 2012 5:46 pm

Re: IF statements not working properly in v4

Postby dsdawson » Tue Jul 18, 2017 12:11 pm

I think you're missing an operator in here:
(E:ZULU TIME, seconds) (>L:APTIMER, seconds) (L:ELEV_TRIM, number) -100 max 100 min (>L:YOKE_Y, number)

Doug

AlexisVGR
Posts: 21
Joined: Wed Jan 18, 2012 8:23 am

Re: IF statements not working properly in v4

Postby AlexisVGR » Tue Jul 18, 2017 6:06 pm

I think you're missing an operator in here:
(E:ZULU TIME, seconds) (>L:APTIMER, seconds) (L:ELEV_TRIM, number) -100 max 100 min (>L:YOKE_Y, number)

Doug
The presentation doesn't help, but they are two different lines.
(A:AUTOPILOT MASTER, bool) 0 == if{
(L:ELEV, number) -163.83 / abs 1 >= if{
(L:ELEV, number) -163.83 / (L:PITCH_FEEL, number) * (L:ELEV_TRIM, number) + -100 max 100 min (>L:YOKE_Y, number)
} els{
(L:ELEV_TRIM, number) -100 max 100 min (>L:YOKE_Y, number)
}
(E:ZULU TIME, seconds) (>L:APTIMER, seconds)
} els{
(L:ELEV, number) -163.83 / abs 1 < if{
(E:ZULU TIME, seconds) (>L:APTIMER, seconds)
(L:ELEV_TRIM, number) -100 max 100 min (>L:YOKE_Y, number)
}
(E:ZULU TIME, seconds) (L:APTIMER, seconds) - 0.5 >= if{
(L:ELEV, number) -163.83 / (L:PITCH_FEEL, number) * (L:ELEV_TRIM, number) + -100 max 100 min (>L:YOKE_Y, number)
}
}


Return to “Software Development Kit (SDK) Questions”

Who is online

Users browsing this forum: No registered users and 3 guests