Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Looking for some help to understand RPN

Featured Replies

Hi,

Perhaps someone can shine some light on this. I have a script group dl'ed for the FBW A320. The script for the EXT PWR Korry switch (which I want to use as an example) looks like this and works just fine - I just don't understand how:

(L:A32NX_EXT_PWR_AVAIL:1,·Number)·(L:A32NX_OVHD_ELEC_EXT_PWR_PB_IS_ON,·Number)·!·and·(L:A32NX_OVHD_INTLT_ANN,·Number)·0·==·(L:A32NX_ELEC_DC_2_BUS_IS_POWERED,·Bool)·and·or·1·and·1·and·(L:A32NX_OVHD_INTLT_ANN,·Number)·2·==·if{·0.1·}·els{·1·}·*
(>L:ExtPwrSeq1)

(L:A32NX_EXT_PWR_AVAIL:1,·Number)·(L:A32NX_OVHD_ELEC_EXT_PWR_PB_IS_ON,·Number)·and·(L:A32NX_OVHD_INTLT_ANN,·Number)·0·==·(L:A32NX_ELEC_DC_2_BUS_IS_POWERED,·Bool)·and·or·(L:A32NX_ELEC_AC_1_BUS_IS_POWERED,·Bool)·and·1·and·(L:A32NX_OVHD_INTLT_ANN,·Number)·2·==·if{·0.1·}·els{·1·}·*·
(>L:ExtPwrSeq2)

(L:A32NX_OVHD_INTLT_ANN,·Number) is the position of the test switch: TEST = 0 / BRT = 1 / DIM = 2. The rest should be self explaining.

(L:ExtPwrSeq1) and (L:ExtPwrSeq2) are variables which describe the status of the annunciator, depending on GND PWR and EXT PWR status. (1) controls the AVAIL light, (2) the ON light.

0 + 0 = OFF

1 + 0 = AVAIL

0 + 1 = ON

With GND PWR available (1), EXT PWR off (0), Test switch BRT (0), DC bus not powered (0), the upper half of the script up to the "if" would look like this:

1 0 not and 0 0 == 0 and or 1 and 1 and 0 2 ==

The result is 0 which triggers the els action and sets (L:ExtPwrSeq1) to 1 (AVAIL light is on).

What I don't understand in the order this script is being processed. According to what I found RPN takes two operands and uses the operator on these two. Except for the negation (not), which is performed directly on the preceding operand.

Which brings me to this:

1 1 and 0 0 == 0 and or 1 and 1 and 0 2 ==

And next:

1 0 0 == 0 and or 1 and 1 and 0 2 ==

Here I'm lost. Three operands and a == operator. And then "and or" right behind each other. What am I missing?

Boris

 

What you're missing is the concept of an RPN stack.  Each entry is "pushed" onto the top of the stack.  A dual-operand operator will remove ("pop") the top two elements off of the stack, perform the operation, and push the result back onto the top of the stack.  Here in my explanation, x y z is a stack with z being the topmost (most recent) entry, x being the bottom. 

So 1 0 0 "pushes" three entries onto the stack (1 0 0, with 1 at the bottom, the last zero at the top), then == "pops" the top two (rightmost) entries as operands (0 and 0) does an equality comparison, and pushes the result (1 representing true) back onto the top of the stack, leaving 1 1 on the stack.

Then the 0 is pushed onto the top of the stack (now 1 1 0), the "and" operator pops the top two entries as operands (0 and 1), does a logical "and" yielding a result of false/0 and pushes that back onto the stack, leaving 1 0 on the stack.

Then the "or" pops the remaining two entries off the stack as operands (1 and 0) and performs a logical "or" yielding a result of 1/true, and pushes that back onto the stack leaving the stack with the single entry of 1

Then 1 is pushed onto the stack (now 1 1), the logical "and" pops the two values and pushes the result 1/true back onto the stack, leaving it with a single entry of 1

Then another 1 is pushed onto the stack (now 1 1), the logical "and" pops the two values and pushes the result 1/true back onto the stack, leaving it with a single entry of 1

Now 0 then 2 are pushed onto the stack, (now 1 0 2), and the final == pops the 2 and 0, does a comparison, and pushes the result 0/false onto the stack, leaving you with 1 0 left on the stack for the subsequent "if" test.

 

Bob Scott | President and CEO, AVSIM Inc
ATP Gulfstream II-III-IV-V

Sys1 (MSFS20+24/XPlane12+11): AMD 9800X3D, water 2x240mm, MSI MPG X670E Carbon, 64GB GSkill 6000/30, nVidia RTX4090FE
Alienware AW3821DW 38" 21:9 GSync, 2x4TB Crucial T705 PCIe5 + 2x2TB Samsung 990 SSD, EVGA 1000P2 PSU, 12.9" iPad Pro
Thrustmaster TCA Boeing Yoke, TCA Airbus Sidestick, Twin TCA Airbus Throttle quads, PFC Cirrus Pedals, Coolermaster HAF932 case

Sys2 (P3Dv5/v4): i9-13900KS, water 2x360mm, ASUS Z790 Hero, 32GB GSkill 7800MHz CAS36, ASUS RTX4090
Samsung 55" JS8500 4K TV@60Hz,
3x 2TB WD SN850X 1x 4TB Crucial P3 M.2 NVME SSD, EVGA 1600T2 PSU
Fiber link to Yamaha RX-V467 Home Theater Receiver, Polk/Klipsch 6" bookshelf speakers, Polk 12" subwoofer, 12.9" iPad Pro
PFC yoke/throttle quad/pedals with custom Hall sensor retrofit, Thermaltake View 71 case, Stream Deck XL button box

Sys3 (DCS/P3Dv4/ATS/ETS): AMD 7800X3D, MSI MPG X870E Carbon, Noctua NH-D15S, 64GB GSkill 6000/30, EVGA RTX3090
Alienware AW3420DW 34" 21:9 GSync, Corsair HX1000i PSU, 4TB Crucial T705 PCIe5 + 2TB Samsung 970Evo Plus,
TM TCA Officer Pack
, Saitek combat pedals, TM Warthog, TM RS300 FF wheel/pedals, Coolermaster HAF XB case

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.