Page 1 of 2

Landing Gear Warning

Posted: Tue Oct 20, 2020 8:09 am
by BaronD55
I am starting to write the code for my annunciator instrument.
Starting with the "Gear Unsafe" annunciator LED, I haven't got far before getting confused I'm afraid.
Looking through the P3D variables list I've come across one called "GEAR WARNING".
If this was a boolean variable then, I could light up my annunciator LED if 'true', and turn it off otherwise. That would be too easy!
I see that it is in fact assigned to datatype 'enum' and can have one of three values 0, 1 or 2.
Can some kind person help me understand how the gear warning works when 0 = "unknown", 1 = "normal" and 2 = amphibian" ??
What should I be looking for instead?

Re: Landing Gear Warning

Posted: Tue Oct 20, 2020 8:23 am
by Keith Baxter
Hi and welcome to the forum.

Before we start chasing the tail. Please advise you level of understanding of AM. That way we get an understanding of your experience which makes helping more efficient.
Have you gone through the tutorial videos?
viewtopic.php?f=14&t=2787#p22942

Have you consulted the API?
http://siminnovations.com/wiki/index.ph ... API#Canvas

What is your coding experience? If you have no coding experience that will make the response different to someone that is coding smart.

If you have done all that then we will be happy to assist and point you in the right direction.


Keith

Re: Landing Gear Warning

Posted: Tue Oct 20, 2020 7:01 pm
by BaronD55
Hi Keith. Thanks for your welcome.
I believe that I have a good level of understanding of AM (not 'advanced').
Coding experience - I have written and deployed windows based applications (Visual Studio) to the advantage of my employers. In flight simulation I started writing code in the Arduino IDE using Link2FS with FS9 (is that C++?), then moved on to FSX and investigated Mobiflight (is that Lua?) and SimVim as I pushed in to XP11 while building myself a full sized replica of the Baron B58, the sweetest aircraft of the 7 types I flew back in the 1980's. My DIY sim cockpit was fully functional. All done with a blend of Air Manager for instruments and Leo Bodnar for switches. Now I have finally settled on P3Dv5 as my sim of choice and am rewriting all my code using the variables/events.
Regardiong the links you provided :- firstly, thanks. I have already worked through most of the awesome "How to" series of tutorials and thoroughly enjoyed them. I have spent a fair bit of time studying the API and searching the forums.
At this time though I am not sure my question had a lot to do with coding.
A brief explanation that might help me understand how the variable "Gear Warning" works when 0 = "unknown", 1 = "normal" and 2 = amphibian" would be welcome?? To my mind, the name implies a boolean data type. I know I'm wrong with that mindset so I'm looking for illucidation.
Regards

Re: Landing Gear Warning

Posted: Tue Oct 20, 2020 9:39 pm
by Keith Baxter
Hi,

Thank you giving us you background. We now have a better understanding.

I do not have p3d so I cannot help in that regard. But I can give you pointers on how to identify what might help you.

I would run a simple test script and use the tools the console provides. This image will give you and indication. The dataref I used is a int "INT" with units enum and is not writable. Just like the one you inquire.

Please revisit this video in the link I provided.
-E06- FSX P3D and FS2 variable subscribe

The image I provide indicates what the output value is. Both in the subscriptions box and the data viewer. Those are the values to use.
ice_screenshot_20201020-232913.png
To operate an LED visit the LED in the API hardware section.

I provide you with an example on how to switch the led. Learn from it and happy coding.

Code: Select all

function test(a_value)

visible(my_led_orange,a_value==0)
visible(my_led_red,a_value==1)
visible(my_led_green,a_value==2)

end

xpl_dataref_subscribe("sim/aircraft/autopilot/preconfigured_ap_type","int",test)





Note: Some of what you see in the image was not available at the time Tony did the video. They were done on AM3.4 we are now on AM4 beta

Keith

Re: Landing Gear Warning

Posted: Tue Oct 20, 2020 11:10 pm
by Keith Baxter
Hi,

Just to add and make it clearer for you in case you use Hw output add instead of Hw led add.
you would use...

hw_output_set(my_led_orange, a_value==0 ) instead of visible(my_led_orange, a_value==0 )

a_value==0 will return a true if a_value is 0
a_value==0 will return a false if a_value is any other value

in LUA (a_value == 0) or (a_value >= 0) or (a_value <= 0) or (a_value ~= 0) will return a true or false value depending on the value of a_value.

You can prove by adding a print statement.

print( a_value == 0)



Keith

Re: Landing Gear Warning

Posted: Wed Oct 21, 2020 3:01 am
by Sling
Hi and welcome to the forum.

I would add that the enum or enumerator type is simply a list of values that could be returned. It looks like your one has 3 different possible values but I suspect depending on the aircraft type that only 2 are used. In your case I suspect that will be 0 and 1. If you do a simple subscribe as Keith hinted and print the returned value then operating the gear should confirm what value means what.

You can then simply use something like this to get to a true/false.

Code: Select all

gear_lt_bool = fif(gear_data > 0, true, false)

I hope this helps. Be sure to let us know how you go.

Tony

Re: Landing Gear Warning

Posted: Sun Oct 25, 2020 10:08 am
by flyatr
Hello there,

I have recently updated my landing gear code for FS2020. Basically the variables are the same as in P3D. To make the code more compact I add my logic right in the hw_led_set() statement. This statement

Code: Select all

battery and (gear_center > gearDownPct)
will return false or true and therefore turn the LED on or off. Using the "battery" variable the light will be off when the battery is off.

Code: Select all

local gearDownPct = 99.9
function landing_gear(battery, gear_center,gear_left,gear_right,panel_light)
	hw_led_set(led_nose_green,battery and (gear_center > gearDownPct))
	hw_led_set(led_left_green,battery and (gear_center > gearDownPct))
	hw_led_set(led_right_green,battery and (gear_center > gearDownPct))
	
	hw_led_set(led_nose_red,battery and (gear_center > 0 and gear_center < gearDownPct))
	hw_led_set(led_left_red,battery and (gear_center > 0 and gear_center < gearDownPct))
	hw_led_set(led_right_red,battery and (gear_center > 0 and gear_center < gearDownPct))
	
	hw_led_set(led_panel_backlight,battery and panel_light)
end

fs2020_variable_subscribe("ELECTRICAL MASTER BATTERY", "boolean",
                        	"GEAR CENTER POSITION","Percent",
							"GEAR LEFT POSITION","Percent",
							"GEAR RIGHT POSITION","Percent",
							"LIGHT PANEL", "Boolean",
							landing_gear)
The "GEAR WARNING" is a number that can be different from aircraft to aircraft. It could be caused by the GPWS-system calling "landing gear! landin gear!" when you are at low altitude with the gear retracted or maybe an overspeed with the gear out.

I add this for my WARNING annunciator:

Code: Select all

-- WARNING light
	if (gear_warning > 0) then ...

Re: Landing Gear Warning

Posted: Sun Oct 25, 2020 8:07 pm
by Sling
flyatr,

A couple of things about your code.

If you are just turning LED on/off with no control of the brightness you don’t have to use the LED function. In fact it’s better to use digital output instead as it uses less resources.

When setting an LED. The function expects a value between 0.0 and 1.0. You are using a bool. If it works like this AM will be interpreting true/false as 1/0 but it’s not correct per the API. It should really give an error for this.

I hope this helps.

Re: Landing Gear Warning

Posted: Mon Oct 26, 2020 5:30 am
by Ralph
True/false was added as a feature, but it's indeed not the correct way to do it. In that case it's better to use output_add.

Re: Landing Gear Warning

Posted: Mon Oct 26, 2020 7:35 am
by Sling
So it was. That one passed me by.

I don’t see why you added it as it only encourages using the LED function as a simple on/off when the hw output is much better for simple on/off. I guess you can’t go back now.