• 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.

FSXA Toggle between GPS NAV1 and NAV2 [SOLVED (well, mostly)]

Messages
67
Country
unitedstates
In my continuing quest to make a glass cockpit for my King Air 300, I've created a button to toggle between the autopilot NAV mode following the GPS or NAV1 (by using <KeyEvent> TOGGLE_GPS_DRIVES_NAV1</KeyEvent> in the button's MouseArea). This works great, but now that it does, I'd really like to be able to select NAV2 as well. I've looked through my listing of events, and the only references to NAV2 I find are for tuning the frequency.

Is there a small snippet of code that will allow me to rotate between GPS, NAV1 and NAV2? Thanks!

P.S. Just so you know I'm not entirely a lazy leech, I have search through this forum, and via Google, but didn't find an answer...!
 
As far as I know, the default NAV mode exclusively uses NAV1. Using NAV2 as a frequency source is not possible.
 
Is there a small snippet of code that will allow me to rotate between GPS, NAV1 and NAV2?

As far as I know, the default NAV mode exclusively uses NAV1. Using NAV2 as a frequency source is not possible.

What do you think about tricking it?

Use Events to set Nav1 active using the Nav2 active frequency value, but use L:Vars, not the A:Vars, to display Nav1 frequency and Nav2 frequency in your gauge. Will open a can or worms keeping track of what everything is really supposed to be, but it should work.

Bob
 
Drat -- I was hoping there was something simple I had missed!

It is theoretically possible. I have Eaglesoft's Cirrus SR22, and their Avidyne PFD cycles through using GPS, VOR1 and VOR2 as NAV sources. Not sure how they do it....

I like rpmc's suggestion. I'm just a little leary of that can of worms!

I must confess, I usually just stick with "following the magenta line". But recently I've been trying my hand at VOR navigation. It would sure be easier if I could switch to NAV2 once I hit the NAV1 waypoint....

Thanks for the help! I'll have to mull this one over for a while!
 
There's nothing that rotates through... you're going to have to do all the hard work. The autopilot, by default, flies following either NAV 1 or GPS. To get it to follow NAV 2, you have to use the event AP_NAV_SELECT_SET. Passing a 1 tells it to use NAV 1, passing a 2 tells it to use NAV 2. It's up to you to figure out how to know what you're on and what you need to command. The sim isn't going to keep track of this, there's nothing telling you which NAV it's following.
 
Oooh, this is excellent stuff! I don't mind keeping track (either through a gauge, or just mentally!); I just needed a nudge to find the correct command to make the AP use NAV2. Once I've got NAV1 and NAV2 set as I want them, this will allow me to switch from one to the other, which is what I want!

Thanks!!
 
Okay, I've given it a whirl, but have been less than entirely successful. I've added a variable to keep track of the navigation source (it will cycle through GPS, NAV1 and NAV2). But something's wrong with my code, because my variable never increments.

Can you spot my goof?!

Code:
[I'm not happy about it, but the gauge I'm modifying is in FSX AceXML format.]

[Here's the code that should produce the display I want. I don't know if it works, because my key variable (NavSourceSel) never gets changed from 0. In it's previous life, this code worked to toggle between GPS and NAV1 driving navigation.]

  <Element id="CRS/DTK/wp/distance Readout">
  <FloatPosition>20.000,194.000</FloatPosition>
  <GaugeText id="CRS Readout">
  <Bold>False</Bold>
  <Bright>True</Bright>
  <FontFace>Arial</FontFace>
  <FontColor>cyan</FontColor>
  <FontHeight>11</FontHeight>
       <GaugeString> %((A:GPS DRIVES NAV1, bool))   //GPS is driving navigation
%{if}
   \{clr2}
   %((A:GPS is active way point, bool))%{if}%((A:GPS WP DESIRED TRACK, degrees))%!03d!%{else}----%{end} DTK\n
   GPS\n
   %((A:GPS is active way point, bool))%{if}%((A:GPS WP NEXT ID, string))%!s!%{else}----%{end}\n
   %((A:GPS is active way point, bool))%{if}%((A:GPS WP DISTANCE, nmiles) s1 0 &gt;=)%{if}%(l1 100 &gt;=)%{if}%(l1)%!d!%{else}%(l1)%!

0.1f!%{end}%{else}----%{end}%{else}----%{end}% NM
   \{clr}
%{else}
   %((L:NavSourceSel,number) 1 ==)%{if}   // NAV1 is driving navigation
   %((A:NAV1 OBS,degrees) near)%!03d! CRS\n
   VOR 1\n
   %((A:NAV1 has nav, bool))%{if}%((A:NAV1 ident, string))%!s!%{else}----%{end}\n
   %((A:NAV1 DME, nmiles) s1 0 &gt;=)%{if}%(l1 100 &gt;=)%{if}%(l1)%!d!%{else}%(l1)%!0.1f!%{end}%{else}----%{end}% NM
%{end}
%{else}
   %((L:NavSourceSel,number) 2 ==)%{if}   // NAV2 is driving navigation
   %((A:NAV2 OBS,degrees) near)%!03d! CRS\n
   VOR 2\n
   %((A:NAV2 has nav, bool))%{if}%((A:NAV2 ident, string))%!s!%{else}----%{end}\n
   %((A:NAV2 DME, nmiles) s1 0 &gt;=)%{if}%(l1 100 &gt;=)%{if}%(l1)%!d!%{else}%(l1)%!0.1f!%{end}%{else}----%{end}% NM
%{end}
      </GaugeString>
  <Size>50,60</Size>
  <Transparent>True</Transparent>
  <AlternateColor id="AlternateColor">
  <FontColor>Magenta</FontColor>
  </AlternateColor>
  </GaugeText>
  </Element>


[Here is a very simple function I added -- clicking an on-screen knob toggles the display of VOR2 information (controlled by the VOR2w variable).]
[I included this code here only to show a successful left mouse click routine.]
<MouseArea id="VOR2 Knob">
    <FloatPosition>15.000,346.000</FloatPosition>
    <Size>25,25</Size>
     <CursorType>Hand</CursorType>
     <MouseClick id="MouseClick">
      <Script>
      (L:VOR2w,bool) ! (&gt;L:VOR2w,bool)
      </Script>
     </MouseClick>
    <Tooltip><DefaultScript>VOR2 Info Switch</DefaultScript></Tooltip>
    </MouseArea>

[Here's the mouse click that doesn't work. When this on-screen button is pressed, nothing happens.]

    
<MouseArea id="NAV/GPS">
    <FloatPosition>48,336</FloatPosition>
    <Size>45,21</Size>
     <HelpId>HELPID_GAUGE_NAV_GPS_SWITCH</HelpId>
     <CursorType>Hand</CursorType>
     <MouseClick id="MouseClick">
      <Script>
      (L:NavSourceSel,number)
      %{case}
      %{:0}1 (&gt;L:NavSourceSel,number)   // follow NAV1
       <KeyEvent>TOGGLE_GPS_DRIVES_NAV1</KeyEvent>
       1 (&gt;K:AP_NAV_SELECT_SET)
      %{:1}2 (&gt;L:NavSourceSel,number)   // follow NAV2
       2 (&gt;K:AP_NAV_SELECT_SET)
      %{:2}0 (&gt;L:NavSourceSel,number)   // follow GPS
       <KeyEvent>TOGGLE_GPS_DRIVES_NAV1</KeyEvent>
      %{end}
      </Script>
     </MouseClick>
    </MouseArea>

I've stared at this for hours, and just can't seem to find what's wrong. I'm suspicious that my %{case} syntax may be wrong, because that's the point where it seems to fail. And if I can't get the NavSourceSel variable to cycle, obviously my display won't be correct.

I've installed BlackBox, so that's how I can see that NavSourceSel is always 0.

Thanks for your help, and your patience!
 
Last edited:
I've made a very small amount of progress, but still can't get the autopilot to follow the NAV2 VOR. I sure wish I wasn't dealing with AcesXML/FSX code!

But perhaps I should stop working on this. I've recently learned that in the REAL King Airs (at least in a B200), the autopilot will not couple to VOR2. Sorta makes me wonder why have a second VOR then. But then, I also wonder why so many planes seem to have 2 GPS units; just to have one screen for the map, and another for the flight plan listing?

I'll keep plugging away -- any help with the code would be much appreciated! I think the main problem is in the <MouseArea id="NAV/GPS"> section at the very end of the XML. I can get NavSourceSel to increment to 1, but it won't turn over to 2. Perhaps my CASE statement is flawed? I've also tried it with IF loops, with similar results.
 
One reason many planes had 2 NAV radios was while NAV1 was used for the ILS, NAV2 could be used to detect an intersecting radial from another VOR that would define an intersection on the approach. The NAV2 needle swings to the other side - you've passed the specified radial and thus arrived at that intersection.
 
You're using text markup commands and tags in a script block. That won't work at all.

Your control variable is incremented by one every time you click and - by taking modulo - will reset to zero after having incremented it thrice.
Code:
<MouseArea id="NAV/GPS">
<FloatPosition>48,336</FloatPosition>
<Size>45,21</Size>
<HelpId>HELPID_GAUGE_NAV_GPS_SWITCH</HelpId>
<CursorType>Hand</CursorType>
<MouseClick id="MouseClick">
<Script>
(L:NavSourceSel,number) ++ 3 % (>L:NavSourceSel,number)
</Script>
</MouseClick>
</MouseArea>

The interaction with FSX' EventIDs should be done in an update block. Make it a habit to cross-check with the corresponding simulation variable before issuing an event. This will avoid flooding the sim with commands.

Code:
<Update>
<Script>
(L:NavSourceSel,number) 0 ==
(A:AUTOPILOT NAV SELECTED, number) 1 != and
if{ 1 (>K:AP_NAV_SELECT_SET) }

(L:NavSourceSel,number) 1 ==
(A:AUTOPILOT NAV SELECTED, number) 2 != and
if{ 2 (>K:AP_NAV_SELECT_SET) }

(L:NavSourceSel,number) 2 ==
(A:GPS DRIVES NAV1, bool) ! and
if{ (>K:TOGGLE_GPS_DRIVES_NAV1) }
</Script>
</Update>
 
Expanding on the previous suggestion, try this:
Code:
<Script>
  (L:NavSourceSel,number) ++ 3 % (>L:NavSourceSel,number)
  (L:NavSourceSel,number) 0 == if{ 0 (&gt;K:AP_NAV_SELECT_SET) }
  (L:NavSourceSel,number) 1 == if{ 1 (&gt;K:AP_NAV_SELECT_SET) }
  (L:NavSourceSel,number) 2 == if{ 2 (&gt;K:AP_NAV_SELECT_SET) }
</Script>
 
THANK YOU SO MUCH!!!

In hindsight, this was NOT a project for a beginner to tackle. But, that's never stopped be before (since I have just enough knowledge to be dangerous!). With your kind coding help, I seem to have the gauge working -- I can switch between GPS, NAV1 and NAV2 at the touch of a button. I've only done one test flight, but things went very smoothly. Switching from NAV1 to NAV2 changed my course, and followed the GPS line very closely, without ever actually using the GPS for navigation!

I'll fly another flight or two, just to make sure there aren't any nasty surprises. Then I'll package the gauges (I've created a glass cockpit for the Beechcraft King Air by modifying the LearJet radio stack, PFD, and EICAS and slightly tweaking Gavin Munro's fabulous GPS unit).

2016_3_21_9_37_30_478.jpg


I'll post here when it's been uploaded.

Again, my eternal gratitude.
 
"Oh what a tangled web we weave...."

It's amazing how many little things are affected by this one change. I've got the main navigation working (I can switch at will between NAV1 and NAV2, and navigation proceeds accordingly). But little things like the TO/FROM flags, and bigger things like the HSI deviation needle still need fiddling with. The deviation needle works for NAV1 (via A:NAV CDI:1), but not for NAV2 (via A:NAV CDI:2). Using BlackBox I can see that the variables are changing appropriately, but so far I haven't gotten the on-screen needle to deflect for NAV2 (which I find odd, since it does work for NAV1).

So, for now I'll keep my deerskin cap on, and see what else I can eliminate from possibility...!
 
Back
Top