Adding a condition statement

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Message
Author
JackZ
Posts: 2262
Joined: Mon Feb 22, 2016 1:02 pm

Re: Adding a condition statement

#71 Post by JackZ »

vangyver wrote: Mon Aug 16, 2021 7:39 am

Code: Select all

—Add images in Z-order --
img_add_fullscreen("KX165A.png")
redline = img_add("redline.png", 364, 10, 2, 300)

-- Add text --
txt_com1 = txt_add(" ", "size:25px; color:#DCF509; halign:left", 25, 40, 200, 200)
txt_com1stby = txt_add(" ", "size:25px; color:#DCF509; halign:left", 200, 40, 200, 200)

txt_nav1 = txt_add(" ", "size:25px; color:#DCF509; halign:left", 365, 40, 200, 200)
txt_nav1stby = txt_add(" ", "size:25px; color:#DCF509; halign:left", 520, 40, 200, 200)

-- Set default visibility --
img_visible(redline, false)

--subscribe callback --
function new_navcomm_FSX(avionics, nav1, nav1stby, com1, com1stby, battery, generator, FuseNavCom1)

    --make a boolean power variable based on state of avionics, battery, generator and FuseNavCom1 == 1
    local power = avionics >= 8 and (battery >= 8 or generator) and FuseNavCom1 == 1 
    img_visible(redline, power)

    if power then
        txt_set(txt_com1, string.format("%06.02f",com1, com1%1) )
        txt_set(txt_com1stby, string.format("%06.02f",com1stby, com1stby%1))
        txt_set(txt_nav1, string.format("%06.02f",nav1, nav1%1))
        txt_set(txt_nav1stby, string.format("%06.02f",nav1stby, nav1stby%1) )
    else
        txt_set(txt_com1, " ")
        txt_set(txt_com1stby, " ")
        txt_set(txt_nav1, " ")
        txt_set(txt_nav1stby, " ")
    end

end

--subscribes --
fsx_variable_subscribe("ELECTRICAL AVIONICS BUS VOLTAGE", "Volts",
"NAV ACTIVE FREQUENCY:1", "Mhz",
"NAV STANDBY FREQUENCY:1", "Mhz",
"COM ACTIVE FREQUENCY:1", "Mhz",
"COM STANDBY FREQUENCY:1", "Mhz",
"ELECTRICAL BATTERY BUS VOLTAGE", "Volts",
"GENERAL ENG GENERATOR SWITCH:1", "Bool",
"L:FuseNavCom1", "Enum", new_navcomm_FSX)
Quick question: why setting 8 volts as the voltage threshold for your power state?
I strongly doubt that 28 volts avionics like the KA165 will continue to operate with such a low voltage IRL, something like 24volts (say down to 22.5volts to take into account the battery decay in case of battery only supply) should be the absolute lower limit.

It’s a good idea to link the power state to the Fuse, but I am more confused with the electrical battery bus voltage.
I suspect that avionics are tied to the avionics bus only, that bus is in turn fed by either the battery or generator buses.

I reckon that FSX is somewhat much less comprehensive than XPlane systemwise, but I think that in FSX the avionics bus is fed by the main bus which is in turn fed by the battery or generator.

So only checking the avionics bus voltage should be sufficient, along with the fuse status, and of course the avionics switch status.

Jacques
Last edited by JackZ on Mon Aug 16, 2021 3:52 pm, edited 1 time in total.
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Adding a condition statement

#72 Post by Ralph »

I think he took that from an example instrument. Many of our instruments use 8 volt, because some aircraft in X-Plane use a 12 volt system.

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: Adding a condition statement

#73 Post by vangyver »

I am using Air Manager in a way I have never seen anyone else do. It maybe two or three months before I am ready to display my sim but keeping this post short all I can say is the coding meets my requirements. When I am ready I will post my usage for my sim in my facebook group here: https://www.facebook.com/groups/628896667180635
Vangyver

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: Adding a condition statement

#74 Post by vangyver »

Received a reply from A2A makers of the Piper Cherokee 180. https://a2asimulations.com/
Re: Piper Cherokee 180 L:Com1OnOff
Mon Aug 16, 2021 12:01 pm
I've just been having a dig around on Sim Innovation's site to try and learn a bit more about the software Van. I'll pass the most recent info you posted above on to our coders and see if they have any suggestions.

Thanks,
Nick
A2A Simulations Inc.

I replied to Nick: You can always contact Sim Innovations via email here: info@siminnovations.com

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Adding a condition statement

#75 Post by Sling »

Ralph wrote: Mon Aug 16, 2021 3:47 pm I think he took that from an example instrument. Many of our instruments use 8 volt, because some aircraft in X-Plane use a 12 volt system.
Actually I randomly chose 8V when I helped out with the code. I normally use 10V. I think both are reasonable numbers. Most 28v systems have to work 18-32V so half the low end of that for 14v systems gets you to 9V. It’s easily changed to whatever value so desired. I have noticed that a lot of the sim aircraft carry on operating way below those values but that is probably due to a lack of detailed modelling. The value you choose really depends on what you want to align with.

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: Adding a condition statement

#76 Post by vangyver »

Air Manager fix for A2A Com1 on/off knob - (L:Com1OnOff,bool)
A2A LVAR L:Com1OnOff,Bool produces two values when True and two values when False in Air Manager. The values I get are (False False) and (False True). I found my answer in an old modified gauge file I had (Piper PA-28- KR87 (A2A only). Use "L:Com1OnOff", "DOUBLE", and values of 0 or 1.
My script for a new gauge I made with help from Sim Innovations:

Code: Select all

-- Add images in Z-order --
img_add_fullscreen("KX165A.png")
redline = img_add("redline.png", 364, 10, 2, 300)

-- Add text --
txt_com1 = txt_add(" ", "size:25px; color:#DCF509; halign:left", 25, 40, 200, 200)
txt_com1stby = txt_add(" ", "size:25px; color:#DCF509; halign:left", 200, 40, 200, 200)

txt_nav1 = txt_add(" ", "size:25px; color:#DCF509; halign:left", 365, 40, 200, 200)
txt_nav1stby = txt_add(" ", "size:25px; color:#DCF509; halign:left", 520, 40, 200, 200)

-- Set default visibility --
img_visible(redline, false)

--subscribe callback --
function new_navcomm_FSX(avionics, nav1, nav1stby, com1, com1stby, battery, generator, Com1OnOff)

    --make a boolean power variable based on state of avionics, battery, generator and Com1OnOff == 1
    local power = avionics >= 8 and (battery >= 8 or generator) and Com1OnOff == 1 
    img_visible(redline, power)

    if power then
        txt_set(txt_com1, string.format("%06.02f",com1, com1%1) )
        txt_set(txt_com1stby, string.format("%06.02f",com1stby, com1stby%1))
        txt_set(txt_nav1, string.format("%06.02f",nav1, nav1%1))
        txt_set(txt_nav1stby, string.format("%06.02f",nav1stby, nav1stby%1) )
    else
        txt_set(txt_com1, " ")
        txt_set(txt_com1stby, " ")
        txt_set(txt_nav1, " ")
        txt_set(txt_nav1stby, " ")
    end

end

--subscribes --
fsx_variable_subscribe("ELECTRICAL AVIONICS BUS VOLTAGE", "Volts",
"NAV ACTIVE FREQUENCY:1", "Mhz",
"NAV STANDBY FREQUENCY:1", "Mhz",
"COM ACTIVE FREQUENCY:1", "Mhz",
"COM STANDBY FREQUENCY:1", "Mhz",
"ELECTRICAL BATTERY BUS VOLTAGE", "Volts",
"GENERAL ENG GENERATOR SWITCH:1", "Bool",
"L:Com1OnOff", "DOUBLE", new_navcomm_FSX)

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Adding a condition statement

#77 Post by Ralph »

Please put your script between [ code ] next time. Select the script and press the </> button.

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: Adding a condition statement

#78 Post by vangyver »

Code: Select all

Test Script is this correct Ralph ?[code][/code]

vangyver
Posts: 127
Joined: Sat Dec 05, 2015 8:30 am

Re: Adding a condition statement

#79 Post by vangyver »

Ralph ?
Untitled-1.jpg

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Adding a condition statement

#80 Post by Keith Baxter »

vangyver wrote: Tue Aug 17, 2021 10:47 am Ralph ?Untitled-1.jpg
Hi,

Nearly correct.
Check out post #60

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

Post Reply