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.

Autopilot coding question

Featured Replies

I'm trying to make an XML autopilot gauge work..When engaging ALT HOLD, I use the following code: <Click> 0 (>K:AP_ALT_HOLD) (A:AUTOPILOT ALTITUDE LOCK,bool) 0 == if{ 0 (>K:AP_ATT_HOLD_ON) } </Click>The logic is supposed to be:1. Toggle the ALT HOLD function2. If ALT HOLD is now turned off, engage ATT HOLDThis works OK, but... when ALT HOLD turns on, it alsoengages the wing leveler and disconnects NAV or HDG modes.That is not what I wanted to happen!How can I turn on ALT HOLD while keeping NAV or HDG engaged?Really perplexing is that<Click Event="AP_ALT_HOLD"/>does not engage the Wing Leveler, but 0 (>K:AP_ALT_HOLD) does!Help!

Bert

  • Commercial Member

Could you post your entire gauge, and all other gauges working with it?It has to be something contradicting with this gauge and others.Also when you try to provide logic of that sort I would recommend you put it in<Element><Select><Value>CODE HERE</Value></Select></Element>If you want the code to update while the gauge is hiden then add this:<Element><Update Hidden="Yes"/><Select><Value>CODE HERE</Value></Select></Element>But I doubt juts doing that would fix your problem, just post the gauge so I could see it.

Good Day,

Engjell Berisha

 

Angel-Simulations-Small.png

  • Author
Could you post your entire gauge, and all other gauges working with it?
I am not the original author, so I cannot very well post the entire code... :( But I'm finding that brute force coding can restore NAV and HDG after the ALT disconnect <Click> (A:Autopilot Nav1 Lock,bool) 0 != if{ 1 (>L:NAV,bool) } els{ 0 (>L:NAV,bool) } (A:Autopilot Heading Lock,bool) 0 != if{ 1 (>L:HDG,bool) } els{ 0 (>L:HDG,bool) } 0 (>K:AP_ALT_HOLD) (L:NAV,bool) 0 != if{ 0 (>K:AP_NAV1_HOLD_ON) } (L:HDG,bool) 0 != if{ 0 (>K:AP_HDG_HOLD_ON) } </Click> I just wonder if it has to be this complicated..

Bert

  • Moderator

Yes it does. Don't forget that you can also force the wing leveler OFF as well...

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator
  • Author
Yes it does. Don't forget that you can also force the wing leveler OFF as well...
Hi Bill,The issue with the wing leveler is that I do not want it to come on when Idisconnect ALT HOLD, because it, in turn, forces NAV or HDG off.At least, that is what I observe happening.The thing I truly do not understand is that if I disconnect ALT HOLD via"Clickevent", the wing leveler does not come on... why would FSX reactdifferently if the same key event is sent via a different XML statement?

Bert

  • Commercial Member

Bert, you very well can post the entire code if you do not intend to release it as your own work with it retaining basically everything from the original author. If you're out to learn from this code and use it to construct your own AP then there isn't a problem just posting the code. Even if you intent wasn't to learn from it but just to tweak it ever so slightly you could still post it here as you've not the intention of claiming it's yours.Here's what I would do, based on the information you provided: <Element> <Select> <Value>(A:AUTOPILOT ALTITUDE LOCK,bool) 0 == if{ 0 (>K:AP_ATT_HOLD_ON) }</Value> </Select> </Element><Click>(A:Autopilot Heading Lock,bool) 1 == (A:Autopilot Nav1 Lock,bool) 1 == and if{ 1 (>K:AP_NAV1_HOLD_ON) 1 (>K:AP_HDG_HOLD_ON) 0 (>K:AP_WING_LEVELER_ON) 1 (>K:AP_ALT_HOLD_ON) } els{ 1 (>K:AP_ALT_HOLD_ON) }</Click>Not 100% sure if I wrote exactly what you wanted in the code, but here's what it does; if HDG HOLD is on and NAV1 locked onto the HDG HOLD then when you click the ALT HOLD button they will remain that way, the Wing Leveler will be suppressed to off and ALT HOLD on, if HDG HOLD isn't on at the time you click the ALT Button and if NAV1 isn't locked to the HDG HOLD then only the ALT HOLD will go on. I wasn't sure if you wanted to suppress the wing leveler still, but all you'd have to do is copy the wing levler on = 0 part into the els section.That's what I would do, if that still doesn't work then there must be some other code within the gauge overriding what you're trying to do. Hope if done more than just throw you off! :(

Good Day,

Engjell Berisha

 

Angel-Simulations-Small.png

Not sure if it is in FSX, but maybe an entry in the aircraft.cfg... such as:"default_pitch_mode = 0""default_bank_mode = 0""Use_no_pitch" ( wrong syntax )"Use_no_bank" May cure the ills. Just a thaught.Roman

20AUG21_Avsim_Sig.png?dl=1  FS RTWR   SHRS F-111   JoinFS   Little Navmap 
 

 

  • Author
<Click>(A:Autopilot Heading Lock,bool) 1 == (A:Autopilot Nav1 Lock,bool) 1 == and if{ 1 (>K:AP_NAV1_HOLD_ON) 1 (>K:AP_HDG_HOLD_ON) 0 (>K:AP_WING_LEVELER_ON) 1 (>K:AP_ALT_HOLD_ON) } els{ 1 (>K:AP_ALT_HOLD_ON) }</Click>
Hmmm, lots to think about... the logic needs to be fine tuned, but I like the idea of accomplishing multiple thingsin one statement.Now, 0 (>K:AP_WING_LEVELER_ON)I thought this turned the Wing Leveler on, no?My reading was that these key events carry no argument, ie whether I assign 1 or 0 makes no difference.. Would like to know for sure :(
Not sure if it is in FSX, but maybe an entry in the aircraft.cfg... such as:"default_pitch_mode = 0""default_bank_mode = 0""Use_no_pitch" ( wrong syntax )"Use_no_bank" May cure the ills. Just a thaught.Roman
I looked at this... and actually tried it, but it appears to affect the startup only,not what happens after the ALT HOLD is turned off (unfortunately :( )

Bert

  • Commercial Member

I might be wrong, but I use that code all the time that way and it works for me - or maybe I've just not encountered a problem with it yet?

Good Day,

Engjell Berisha

 

Angel-Simulations-Small.png

I might be wrong, but I use that code all the type that way and it works for me - or maybe I've just not encountered a problem with it yet?
I hope you guys get to the botton of this. The autopilots are not real yet-they need to be.Thanks for your work towards reality!!!!

Geofa

WANTED DEAD OR ALIVE-the best Flight Sim!

  • Moderator
0 (>K:AP_WING_LEVELER_ON)I thought this turned the Wing Leveler on, no?My reading was that these key events carry no argument, ie whether I assign 1 or 0 makes no difference.. Would like to know for sure :(
All of the key_events are listed in the SDK, so there should be no "guess work" required here. :(
(>K:AP_WING_LEVELER_OFF)(>K:AP_WING_LEVELER_ON)

There is no need whatever to put either a zero, or a one, or anything at all for that matter before the key_event.For the sake of clarity, please use the "Wrap in Code Tags" button on the editor to encapsulate XML script to preserve the formatting. Also, why don't you use the Enter key once in awhile to make the XML script easier to read? :)

<Click>	 (A:Autopilot Heading Lock,bool) 1 == 	 (A:Autopilot Nav1 Lock,bool) 1 == 	 and	 if{ 		  (>K:AP_NAV1_HOLD_ON)		  (>K:AP_HDG_HOLD_ON)		  (>K:AP_WING_LEVELER_OFF)		  (>K:AP_ALT_HOLD_ON) 	   }	 els{ 		  (>K:AP_ALT_HOLD_ON)		 }</Click>

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator
  • Author
All of the key_events are listed in the SDK, so there should be no "guess work" required here. :(
Well, the sequence: Wing Leveler OFF / ALT Hold ON does indeed keep the NAV or HDG settings intact, so that part is good. :( Unfortunately, the sequence: Wing Leveler OFF / ATT Hold ON knocks out either NAV or HDG... so... back to brute force. <Click> (A:Autopilot Nav1 Lock,bool) (>L:NAV,bool) (A:Autopilot Altitude Lock,bool) (>L:ALT,bool) (A:Autopilot Heading Lock,bool) (>L:HDG,bool) (>K:AP_ALT_HOLD) (L:ALT,bool) 0 != if{ (>K:AP_ATT_HOLD_ON) } (L:NAV,bool) 0 != if{ (>K:AP_NAV1_HOLD_ON) } (L:HDG,bool) 0 != if{ (>K:AP_HDG_HOLD_ON) } </Click>Not pretty, but it does what I was looking for in my original post :(

Bert

There is no need whatever to put either a zero, or a one, or anything at all for that matter before the key_event.
Hi Bill,Be carefull with that statement :( Although such events do not use the preceeding argument, they DO pop this value from the stack !Example:
1 0 (>K:AP_ALT_HOLD) (>L:TEST,number)

Meaning the value of TEST becomes 1, NOT 0.This IS a useless example, :( , but if you use stack processing with embedded events (without using temp storage variables), leaving out the dummy argument of such events gives unexpected problem. As the example illustrates.This is in FSX by the way, haven't tried it in FS9.Cheers, Rob

  • Moderator

In the examples cited, the number preceeding the key_events are completely useless.And Bert, would you PLEASE post XML Script using the "Wrap in code tags" button!It makes the script EVER so much easier to read... :(

<Click>	 (A:Autopilot Nav1 Lock,bool) (>L:NAV,bool)	 (A:Autopilot Altitude Lock,bool) (>L:ALT,bool)	 (A:Autopilot Heading Lock,bool) (>L:HDG,bool)	 (>K:AP_ALT_HOLD)	 (L:ALT,bool) 0 != 		 if{ (>K:AP_ATT_HOLD_ON) }	 (L:NAV,bool) 0 !=		 if{ (>K:AP_NAV1_HOLD_ON) }	 (L:HDG,bool) 0 !=		 if{ (>K:AP_HDG_HOLD_ON) }</Click>

That's much easier to read; unfortunately it makes no real sense... :(

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator
In the examples cited, the number preceeding the key_events are completely useless.And Bert, would you PLEASE post XML Script using the "Wrap in code tags" button!It makes the script EVER so much easier to read... :(
<Click>	 (A:Autopilot Nav1 Lock,bool) (>L:NAV,bool)	 (A:Autopilot Altitude Lock,bool) (>L:ALT,bool)	 (A:Autopilot Heading Lock,bool) (>L:HDG,bool)	 (>K:AP_ALT_HOLD)	 (L:ALT,bool) 0 != 		 if{ (>K:AP_ATT_HOLD_ON) }	 (L:NAV,bool) 0 !=		 if{ (>K:AP_NAV1_HOLD_ON) }	 (L:HDG,bool) 0 !=		 if{ (>K:AP_HDG_HOLD_ON) }</Click>

That's much easier to read; unfortunately it makes no real sense... :(

But it seems to work ! ...at least like a real autopilot...

Geofa

WANTED DEAD OR ALIVE-the best Flight Sim!

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.