• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

FS2004 AP Heading mode selector

Messages
14
Country
yugoslavia
Hello, me again.

I've been walking in circles past two days and nights trying to write working code for the AP HDG mode selector, McDonnel Douglas type. A spring loaded selector that select heading in degrees, select present aircraft heading hold mode by pushing it, or select previously dialed heading by pulling it.
Here is my code so far:
Code:
<Element>
        <Select>
            <Value>(A:AUTOPILOT HEADING LOCK DIR, degrees) (A:PLANE HEADING DEGREES GYRO, degrees) - 10 &lt;
                            (L:HDG hold mode engage, bool)
                            (&gt;L:HDG hold, bool)
            </Value>
        </Select>
    </Element>
  
        <Element>
        <Select>
            <Value>(A:AUTOPILOT HEADING LOCK DIR, degrees) (A:PLANE HEADING DEGREES GYRO, degrees) - 10 &gt;
                            (L:HDG select mode engage, bool)
                            (&gt;L:HDG sel, bool)
            </Value>
        </Select>
    </Element>

    <Element>
        <Select>
            <Value>(L:HDG hold, bool) if{ (K:AP_HDG_HOLD) ! if{ (&gt;K:AP_HDG_HOLD) } }</Value>
        </Select>
    </Element>

        <Element>
        <Select>
            <Value>(L:HDG sel, bool) if{ (K:AP_PANEL_HEADING_ON) ! if{ (&gt;K:AP_PANEL_HEADING_ON) } }</Value>
        </Select>
    </Element>
                                  
    <Mouse>
        <Area Left="0"
              Top="0"
              Width="20"
              Height="20">
            <Tooltip>Heading mode selector</Tooltip>
            <Cursor Type="Hand"/>
            <Click Kind="LeftSingle+RightSingle" Repeat="Yes">
            (M:Event) 'LeftSingle' scmp 0 == if{ (L:HDG hold mode engage, bool) ! (&gt;L:HDG hold mode engage, bool) }
            (M:Event) 'RightSingle' scmp 0 == if{ (L:HDG select mode engage, bool) ! (&gt;L:HDG select mode engage, bool) }</Click>
        </Area>
    </Mouse>

The idea is to select HDG hold by left click ( push button) and HDG select by right click (pull button ).
Then I introduced another pair of L vars, HDG hold should be ON if difference between selected and indicated heading is less then 10 degrees. Opposite for HDG select.

Then I defined (L:HDG hold, bool) to engage present heading hold, and (L:HDG sel, bool) to engage selected heading. The funny thing is that it works! But the gauge allows both modes to be engaged at the same time. What I want, and not just for this gauge, is the way to turn off one mode if other is engaged. And also to be able to select new airplane heading, but to engage new heading select after the button is pulled, regardless of previously engaged mode. Dial, then pull to engage. If you want new heading, first dial it, then pull (right click) selector to engage it. This is the quote from DC-10 manual, describing the HDG control knob:

HDG Control Knob
Knob has four functions. Normal,
spring-held position provides fine
adjustment of heading. Push to first
detent for fast heading select. Push
full in to engage AP and FD HDG
HOLD and to cancel all armed or
engaged lateral modes. Pull out to
engage HDG SEL mode. HDG knob
also positions heading bugs on HSI's
when HSI switch is in RAD position.

I would ignore the Push to first detent part. Sound way to complicated.

I will then try to implement WheelUp and WheelDown into click kind, for dial heading.

Again, please point me into the right direction, if you, please! Thanks! There must be a way to do that, and more elegant one too, I am certain!
 
Last edited:
You do realize that conditional statements require at least an "if{...}", right?


Besides that, turning modes on and off can be attained fairly easily:
Code:
<Mouse>
<Area Left="0"
             Top="0"
             Width="20"
             Height="20">
<Tooltip>Heading mode selector</Tooltip>
<Cursor Type="Hand"/>
<Click Kind="LeftSingle+RightSingle">
(M:Event) 'LeftSingle' scmp 0 == if{ (L:HDG hold mode engage, bool) ! (&gt;L:HDG hold mode engage, bool) 0 (&gt;L:HDG select mode engage, bool) }
(M:Event) 'RightSingle' scmp 0 == if{ (L:HDG select mode engage, bool) ! (&gt;L:HDG select mode engage, bool) 0 (&gt;L:HDG select mode engage, bool) }</Click>
</Area>
</Mouse>
 
Hi,

They are both coming on at the same time because in your mouse section you do not turn off select mode in the left click line and do not turn off hold mode in the right click line. (Since you only want one of them on at a time, it might make more sense to use a single variable like (L:HDG mode engage, bool) for both. If true, select mode is on, if false, hold mode is on. But we'll ignore that for now.)

Another problem is that you have no if{ statements in your first two Elements, so the limitation of less/greater than 10 degrees is being ignored.

The final problem is that you are trying to use K: variables to test values, like (K:AP_HDG_HOLD) - these are commands, not variables you can read. You use A: variables for that. (You can also replace the two if{ statements with an if{ and an AND ( &amp;&amp; ) which makes things a bit clearer, but we'll ignore that too.)

Something like this might work better. But all I'm doing here is attempting to repair your code; I'm assuming your underlying logic is correct.

Code:
<Element>
        <Select>
            <Value>(A:AUTOPILOT HEADING LOCK DIR, degrees) (A:PLANE HEADING DEGREES GYRO, degrees) - 10 &lt; if{
                            (L:HDG hold mode engage, bool)
                            (&gt;L:HDG hold, bool) }
            </Value>
        </Select>
    </Element>
 
        <Element>
        <Select>
            <Value>(A:AUTOPILOT HEADING LOCK DIR, degrees) (A:PLANE HEADING DEGREES GYRO, degrees) - 10 &gt; if{
                            (L:HDG select mode engage, bool)
                            (&gt;L:HDG sel, bool) }
            </Value>
        </Select>
    </Element>

    <Element>
        <Select>
            <Value>(L:HDG hold, bool) if{ (A:AUTOPILOT HEADING LOCK, bool) ! if{ (&gt;K:AP_HDG_HOLD) } }</Value>
        </Select>
    </Element>

        <Element>
        <Select>
            <Value>(L:HDG sel, bool) if{ (A:AUTOPILOT HEADING LOCK, bool) ! if{ (&gt;K:AP_PANEL_HEADING_ON) } }</Value>
        </Select>
    </Element>
                                 
    <Mouse>
        <Area Left="0"
              Top="0"
              Width="20"
              Height="20">
            <Tooltip>Heading mode selector</Tooltip>
            <Cursor Type="Hand"/>
            <Click Kind="LeftSingle+RightSingle" Repeat="Yes">
            (M:Event) 'LeftSingle' scmp 0 == if{ (L:HDG hold mode engage, bool) ! (&gt;L:HDG hold mode engage, bool) (L:HDG select mode engage, bool) if{ (L:HDG select mode engage, bool) ! (&gt;L:HDG select mode engage, bool) } }
            (M:Event) 'RightSingle' scmp 0 == if{ (L:HDG select mode engage, bool) ! (&gt;L:HDG select mode engage, bool) (L:HDG hold mode engage, bool) if{ (L:HDG hold mode engage, bool) ! (&gt;L:HDG hold mode engage, bool) } }</Click>
        </Area>
    </Mouse>

This has not been tested.

Hope this helps,
 
Thank you very much Bjoern and Tom!

I understand my mistakes now. Although it's all so very new to me and obviously it's to much for novice like me. But nevertheless, one can't learn without trying, right? As for the mouse part of the code, I am only familiar with the most basic version of it, so I must get on to it.

Thanks for your patience and your help, guys! I'll present my final code here, when finished.
 
Last edited:
IMO there is no way to do the following using the 2 FS heading modes as the heading bug will affect either one. Instead I think using a single FS heading mode and using a background var to hold the heading bug until it is needed should work.
But the gauge allows both modes to be engaged at the same time. What I want, and not just for this gauge, is the way to turn off one mode if other is engaged. And also to be able to select new airplane heading, but to engage new heading select after the button is pulled, regardless of previously engaged mode.
The code below is from memory of an old project (source not available right now) modified to follow suit of the DC-10 description above. There are 2 drawbacks/thing to test.
1) Any code that uses the heading bug and or heading digits need to be modified to follow the new heading var. (L:BG Heading Var, number)
2) While code is in there, it is not tested. One thing to make sure happens is if another lateral mode is armed (VOR NAV/ILS) and then acquires it should cancel any HDG mode.

Logic directions on each push or pull (L:HDG Mode, number) -
PUSH (left) - Table moves up
2 = Heading hold ON
1 = Slave current heading and arm for heading hold
0 = All heading modes off
3 = Heading select ON

PULL (right) - Table moves down except mode 2 goes directly to 0

Note - using <Update>is the same as putting code in <Element><Select><Value>

It's a little complicated but commented fully, maybe the logic will help.
Too much coffee :coffee::stirthepo & not tested.

Code:
<Comment>
1) Instead of working with the AP modes (AP_HDG_HOLD & AP_PANEL_HEADING_ON), which are basically the same except in  AP_HDG_HOLD uses the current heading at the time of engagement. Use the heading variable in background logic.

2) One drawback - all other instruments  that use the heading variable will not show the bug correctly as the heading is now part of background logic, until the mode is engaged. The use of the new (L:BG Heading Var, number) should be used in the AP Panel heading digits and any other instrument that relies on the heading bug.

3) Another drawback - the use of a joystick button or other hardware will be a little difficult, although possible with "Keys" or Lua

4) L:Vars and their respective values. Note - "Push to first detent" is re-enabled, and the +/- 10* difference is taken out.

a. (L:HDG Mode, number)
0 = Off
1 = "Push to first detent" and set curent heading to background logic, arm for heading hold
2 = Heading hold is on
3 = Heading select is on

b. (L:BG Heading Var, number)
The background heading variable used in logic

c. (L:BG Button Push Pull, bool)
A var to cancel extra code in clicks to prevent subsequent code to be peformed on a single click


5. Proper aircraft.cfg [autopilot] entries should be used.
use_no_default_bank=1
default_bank_mode=0
</Comment>

<!-- ************************************** THE MULTIPURPOSE HEADING KNOB  CODE ****************************************** -->

<Update>
<!-- Initialize the BG heading variable on first gauge load, go directly to heading select if Heading is on IE saved flight -->
(G:Var1) 0 == if{  (A:AUTOPILOT HEADING LOCK DIR, degrees) (>L:BG Heading Var, number) (A:AUTOPILOT HEADING LOCK, bool) if{ 3  (>L:HDG Mode, number) } 1 (>G:Var1) }

<!-- Keep FS's own heading bug synched with background heading var when in "Heading Select" -->
(L:BG Heading Var, number) (A:AUTOPILOT HEADING LOCK DIR, degrees) != (L:HDG Mode, number) 3 == and if{ (L:BG Heading Var, number) (>K:AP_PANEL_HEADING_SET)  }

<!-- Reset background logic if FS's own heading hold is turned off by any means IE override by NAV/ILS capture etc.. -->
 (L:HDG Mode, number) 2 ==  (L:HDG Mode, number) 3 == || (A:AUTOPILOT HEADING LOCK, bool) ! and if{ 0  (>L:HDG Mode, number) }

 <!-- Reset button push/pull so another command can be used -->
 (L:BG Button Push Pull, bool) if { 0 (>L:BG Button Push Pull, bool) }

<!-- If in mode 0 turn off FS heading hold if on, just in case -->
(L:HDG Mode, number) 0 == (A:AUTOPILOT HEADING LOCK, bool) and if{ (>K:AP_PANEL_HEADING_OFF) }
</Update>


<Mouse>
<Area Left="0"  Top="0" Width="20" Height="20">
<Tooltip>Heading mode selector</Tooltip>
<Cursor Type="Hand"/>
<Click Kind="LeftSingle+RightSingle+WheelDown+WheelUp" Repeat="Yes"> <!-- quite possibly set repeat to No, mouse wheel may work w/o repeat -->

(M:Event) 'LeftSingle' scmp 0 == if{

<!-- The first PUSH code, set FS's & Background heading vars to current heading, arm heading hold -->
(L:HDG Mode, number) 0 == (A:PLANE HEADING DEGREES GYRO, degrees) near (A:AUTOPILOT HEADING LOCK DIR, degrees) != (L:BG Button Push Pull, bool) ! and and if{ (A:PLANE HEADING DEGREES GYRO, degrees) near s1 (>K:AP_PANEL_HEADING_SET) l1 (>L:BG Heading Var, number) 1 (>L:HDG Mode, number) 1  (>L:BG Button Push Pull, bool) (A:AUTOPILOT HEADING LOCK, bool) if{ (>K:AP_PANEL_HEADING_OFF) } }

<!-- The second PUSH code, engage heading HOLD -->
(L:HDG Mode, number) 1 == (A:AUTOPILOT HEADING LOCK, bool) ! (L:BG Button Push Pull, bool) ! and and if{ (>K:AP_PANEL_HEADING_ON) 2  (>L:HDG Mode, number) 1  (>L:BG Button Push Pull, bool) }

<!-- A  THIRD "OPTIONAL" PUSH, cancel heading SELECT -->
(L:HDG Mode, number) 3 == (A:AUTOPILOT HEADING LOCK, bool) (L:BG Button Push Pull, bool) ! and and if{ (>K:AP_PANEL_HEADING_OFF) 0  (>L:HDG Mode, number) 1  (>L:BG Button Push Pull, bool) }

<!-- End left click code -->
 }


 (M:Event) 'RightSingle' scmp 0 == if{

 <!-- The first PULL code, just turn on AP heading, the update code above will keep the heading in sync -->
(L:HDG Mode, number) 0 == (A:AUTOPILOT HEADING LOCK, bool) ! (L:BG Button Push Pull, bool) ! and and if{ (>K:AP_PANEL_HEADING_ON) 3  (>L:HDG Mode, number) 1  (>L:BG Button Push Pull, bool) }

 <!-- A  SECOND "OPTIONAL" PULL,  cancel heading HOLD or HOLD arm -->
(L:HDG Mode, number) 1 == (L:HDG Mode, number) 2 == || (L:BG Button Push Pull, bool) ! and if{ (>K:AP_PANEL_HEADING_OFF) 0  (>L:HDG Mode, number) 1  (>L:BG Button Push Pull, bool) }

 <!-- End right click code -->
 }

 <!-- MOUSE WHEEL EVENTS, The ability to change the heading bug while in any heading mode w/o affecting in heading hold and affecting in heading select -->
 (M:Event) 'WheelUp' scmp 0 == if{ (L:BG Heading Var, number) ++ dnor (>L:BG Heading Var, number) }
 (M:Event) 'WheelDown' scmp 0 == if{ (L:BG Heading Var, number) -- dnor (>L:BG Heading Var, number) }

</Click>
</Area>
</Mouse>

<!-- ************************************** END MULTIPURPOSE HEADING KNOB  CODE ****************************************** -->





<!-- ANY OTHER GAUGE THAT USES A HEADING BUG OR READOUT -->
<Value>(L:BG Heading Var, number)</Value>


<!-- THE HSI RAD SWITCH IF USED, psuedo  -->
<Value>(L:HSI RAD SWITCH, BOOL) if { (L:BG Heading Var, number) } els{  (A:AUTOPILOT HEADING LOCK DIR, degrees) }</Value>

<!-- ANNUNCIATORS  add any electrical logic as necessary -->
HDG HLD = <Visible>(L:HDG Mode, number) 2 ==  (A:AUTOPILOT HEADING LOCK, bool)  and</Visible>
HDG ARM = <Visible>(L:HDG Mode, number) 1 ==  (A:AUTOPILOT HEADING LOCK, bool) !  and</Visible>
HDG SEL = <Visible>(L:HDG Mode, number) 3 ==  (A:AUTOPILOT HEADING LOCK, bool) and</Visible>
 
Last edited:
It's a little complicated but commented fully, maybe the logic will help.
Amazing! If the programmer is creative and motivated enough, anything is possible with xml gauge programming! I have no talent for this type of logical creativity at all, I would say. Nevertheless I find this fascinating and totally inspiring. It'll take quite some time for me to decipher your code, it'll be a challenge. And I'll enjoy it!

Note - using <Update>is the same as putting code in <Element><Select><Value>
Didn't know that either.

Cheers, Roman!
 
Use a dummy heading bug and logic to select either current hdg or dummy heading value and update actual hdg bug as reqd.
 
Back
Top