Board index FlightGear Support Interfacing

listen to property to trigger DHC6 autopilot xml

Connecting two computers, using generic protocol, connecting with Matlab?

listen to property to trigger DHC6 autopilot xml

Postby Volador » Sat Jul 24, 2021 4:28 pm

The DHC-6 uses a lot of xml rather than nasal (apparently this is a better/faster way to code) anyway, thanks to all the help I've had on the forum I now facing the puzzle of how to execute long xml commands by listening to a property:

In my case for example, property input/arduino/ap/Hdg-hold receives a momentary change from false to true and sets back to false when released on the interface. The property I'm trying to change the state of is /controls/autopilot/settings/hdgflag which need to lock as true or false.

One option I considered was to write a big nasal block which listened to the ardino state change and then executed a copy of all the xml associated with hdgflag=true - but this seem very inefficient on the face of it. Is there a way to use the nasal to 'point' to where all this xml is (like a subroutine) or would I need to copy the whole section of xml that dealt with hdgflag (and repeat the process for all the .xml code for the autopilot functions?)

...or is 'toggle' part of the solution - ie use a listener on input/arduino/ap/Hdg-hold and when it changes false to true and then back to false, toggle the property /controls/autopilot/settings/hdgflag - the thing is, there is a lot of logic in the xml that determines weather or not the hdg can be switched on as the AP has to be on first (or will FG just figure all that out anyway?)
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: listen to property to trigger DHC6 autopilot xml

Postby Volador » Mon Jul 26, 2021 8:52 pm

The autopilot for the DCH6 seems to be all xml/bindings, is there a way to copy the chunks of xml and execute them within Nasal or does't it work that way? Rather you'd have to write all the equivalent Nasal setprop("controls/autopilot/apflag",true); commands to replicate what the xml list of bindings is doing?
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: listen to property to trigger DHC6 autopilot xml

Postby S&J » Mon Jul 26, 2021 9:17 pm

Use a switch to set and hold the property once it sees a momentary signal.
"Stay away from negative people.They have a problem for every solution." - Albert Einstein
S&J
 
Posts: 794
Joined: Wed Aug 26, 2020 7:31 pm

Re: listen to property to trigger DHC6 autopilot xml

Postby Volador » Tue Jul 27, 2021 9:00 am

I suspect some properties are only set under certain conditions, hence the list of bindings for a particular function. Forcing a property might not get the right result in all cases. eg you can only set the glide-slope if autopilot = true and the speed <= x etc etc. What I'm trying to do is use a listener to a custom property eg: input/arduino/GSbtn and once detected execute all the bindings associated with that <pick> in the xml - which will also check all the logic for speed and autopilot engaged etc
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: listen to property to trigger DHC6 autopilot xml

Postby powoflight » Thu Sep 09, 2021 5:19 pm

I have converted the twinotter ap xml to nasal and use it in joystick input xml.
I will send it later.
powoflight
 
Posts: 212
Joined: Fri Mar 25, 2016 11:04 am
Location: LOWW
Callsign: OE-POW
Version: 2020.4
OS: win7 Ubuntu 18.04

Re: listen to property to trigger DHC6 autopilot xml

Postby Volador » Thu Sep 09, 2021 7:19 pm

Bernhard, that's brilliant, thank you :)
Chris
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: listen to property to trigger DHC6 autopilot xml

Postby powoflight » Fri Sep 10, 2021 8:09 am

I have written for my external HW an xml file like
/flightgear/fgdata/Input/Joysticks/Local/Arduino_2.xml

I have more than one Aircraft that is mapped to one Button, So for example AP Button can be used for C172, C182, Twinotter, A320, etc. This is done in an external nasal script .

For the Twinotter its give us No. 3 .
If you use only one A/C you dont need it. Than forget the code
if ( AirCraftType==3 ) {
.
}

1) nasal script
Code: Select all
<?xml version="1.0"?>
 <nasal>
  <script><![CDATA[       
   var AirCraftType=0;
   var Version=0;
   io.load_nasal(getprop("/sim/fg-home") ~"/Nasal/joystick_pow.nas", "joystick_pow");
   AirCraftType = joystick_pow.aircraftversion();
   print("AirCraftType INCLUDE : ", AirCraftType);

   # ==============================================================
   # dhc6 
   # ==============================================================
   var dhc6_ALTMODE=0;
   var dhc6_HDGMODE=0;
   var dhc6_AP_init=0;

   var dhc6AllAPOff=func()  {
         setprop("controls/autopilot/settings/apflag",0)  ;
         
         # HDG off
         setprop("controls/autopilot/settings/hdgflag",0)  ;
         setprop("controls/autopilot/settings/hdgsetflag",0)  ;
         setprop("controls/autopilot/settings/navsetflag",0)  ;
         
         # ALT off
         setprop("controls/autopilot/settings/altflag",0)  ;
         setprop("controls/autopilot/settings/altsetflag",0)  ;
         setprop("controls/autopilot/settings/gssetflag",0)  ;
         setprop("controls/autopilot/settings/vssetflag",0)  ;
          dhc6_ALTMODE=0;
          dhc6_HDGMODE=0;
         gui.popupTip("AP off");                      
   }
     
     # ========================================================= 
     var Dhc6APOnOff2020=func()  {
     
      print("Dhc6APOnOff2020 "); #debug
      setprop("/autopilot/locks/altitude", "")  ;
      setprop("/autopilot/locks/speed", "")  ;
      setprop("/autopilot/locks/heading", "")  ;
      
      setprop("/controls/autopilot/settings/altflag", 0)  ;
      setprop("controls/autopilot/settings/altsetflag",0)  ;
      setprop("/controls/autopilot/settings/vssetflag", 0)  ;
      setprop("/controls/autopilot/settings/gssetflag", 0)  ;
      setprop("/controls/autopilot/settings/hdgsetflag", 0)  ;
      setprop("/controls/autopilot/settings/navsetflag", 0)  ;
      
      setprop("controls/autopilot/settings/hdgflag",0)  ; 
    }
 
    # =========================================================
   var Dhc6_AP_Hdg=func() {
 
      setprop("autopilot/locks/heading", "wing-leveler")  ;
      if  ( getprop("controls/autopilot/settings/hdgflag") == 0  ) {   
            setprop("autopilot/locks/heading", "")  ; 
      }

      if  ( getprop("controls/autopilot/settings/hdgflag") == 0 ){
        setprop("autopilot/locks/heading", "")  ;
      }
      setprop("controls/autopilot/settings/hdgsetflag", 0)  ; 
      setprop("controls/autopilot/settings/navsetflag", 0)  ; 
      
      setprop("autopilot/locks/passive-mode", 0)  ;           
   }   
   
   # =========================================================
   var Dhc6_AP_Altitude=func() {
      #line
      print("Dhc6_AP_Altitude=func");
      if  ( getprop("controls/autopilot/settings/iasflag") == 0) {
         setprop("autopilot/locks/altitude", "");   
      }
      setprop("controls/autopilot/settings/altsetflag", 0)  ;
      setprop("controls/autopilot/settings/vssetflag", 0)  ;
      setprop("controls/autopilot/settings/gssetflag", 0)  ;
      setprop("autopilot/locks/passive-mode", 0)  ;
   }   

   # =========================================================
   # AP-Speed
      var Dhc6_AP_Speed=func() {
      print("AP-Speed");
      #  Speed-toggle 
      if ( ( getprop("controls/autopilot/settings/apflag") == 1 )
       and
      (getprop("position/altitude-agl-ft") > 100.0 )) {
        setprop("controls/autopilot/settings/iasflag", 1)  ;
        gui.popupTip("IAS Speed on");
      } else {
         setprop("controls/autopilot/settings/iasflag", 0)  ;
         gui.popupTip("IAS Speed off or Altitude to Low ");
      }
      setprop("controls/autopilot/settings/altsetflag", 0)  ;
      setprop("/controls/autopilot/settings/gssetflag", 0)  ;
      setprop("/controls/autopilot/settings/vssetflag", 0)  ;
      # sp DHC6
      setprop("autopilot/locks/passive-mode", 0)  ;
   }
   ]]></script>
</nasal> 


2) AP On/OFF
Code: Select all
   
 <button n="1"> <!--   Autopilot    -->
   <desc>Autopilot Toggle</desc>
   <repeatable type="bool">false</repeatable>
 
 # 3: dhc6
    <binding>
       <command>nasal</command>
       <script>
       if ( AirCraftType == 3 ) {
          print(" AirCraftType == 3 ");
          print(" apflag ", getprop("controls/autopilot/settings/apflag"));
         
          if (dhc6_AP_init ==0 ) {
              Dhc6APOnOff2020();
              print("          dhc6_AP_init ");
              setprop("controls/autopilot/settings/apflag",1);
              dhc6_AP_init = 1;
            }
         else {
      if ( getprop("controls/autopilot/settings/apflag") == 0 ) {
               setprop("controls/autopilot/settings/apflag",1);
               print("           dhc6 ap on ");
               Dhc6APOnOff2020();
               print("powo_dhc6AllAPOff on "); #debug
               gui.popupTip("AP on");
      } else if ( getprop("controls/autopilot/settings/apflag") == 1 ){
               setprop("controls/autopilot/settings/apflag",0)  ;
               print("            dhc6 ap off ");
               Dhc6APOnOff2020();
               print("powo_dhc6AllAPOff off "); #debug
               gui.popupTip("AP off");
      }
   }         
     }     
       </script>
 </binding>   
 </button>


3) HDG
Code: Select all
# ========================================================================
# dhc6 HDG on                                                                       ok  button n="4"
# ========================================================================   

<button n="1">   
   <repeatable type="bool">false</repeatable>
   <desc>Autopilot  HDG mode toggle </desc>

     # dhc6 hdg on  off
    <binding>
       <command>nasal</command>
       <script>
      <!--
       if ( AirCraftType == 3 and  ( getprop("controls/autopilot/settings/apflag") == 1 ) ) {
         if ( getprop("controls/autopilot/settings/hdgflag") == 0 ) {
                  setprop("controls/autopilot/settings/hdgflag",1);
                 gui.popupTip("HDG on");
         } else {
         setprop("controls/autopilot/settings/hdgflag",0)  ;
         setprop("controls/autopilot/settings/hdgsetflag",0)  ;
         setprop("controls/autopilot/settings/navsetflag",0)  ;
         gui.popupTip("HDG off");
         }
      }
       -->
        if ( (AirCraftType == 3) and  ( getprop("controls/autopilot/settings/apflag") == 1 ) ) {
         if ( getprop("controls/autopilot/settings/hdgflag") == 0 ) {
            setprop("controls/autopilot/settings/hdgflag",1);
            # mist 6
            Dhc6_AP_Hdg();
              gui.popupTip("HDG on");
              #mist
         } else if ( getprop("controls/autopilot/settings/hdgflag") == 1 ) {
            setprop("controls/autopilot/settings/hdgflag",0)  ;
            # line 12
            Dhc6_AP_Hdg();
            gui.popupTip("HDG off");
         }
      }     
       
       </script>
  </binding>   
  </button>


4) dhc6 SWITCH hdg nav Mode
I think there must be some fault in there .
If hdg is on and switch to nav alt mode should switch of after dhc find nav path
Code: Select all
# ========================================================================
# dhc6 SWITCH hdg nav Mode
# ========================================================================      

<button n="2">   
   <repeatable type="bool">false</repeatable>
   <desc>Autopilot  PITCH mode </desc>
   # dhc6 SWITCH hdg nav Mode   
   <binding>
       <command>nasal</command>
       <script>
      if ( (AirCraftType == 3)
         and 
         ( getprop("controls/autopilot/settings/apflag") == 1 )
         and
         ( getprop("controls/autopilot/settings/hdgflag") == 1 )    ) {
     
          # hdg ON
         if ( dhc6_HDGMODE == 0 ) {
            setprop("controls/autopilot/settings/hdgsetflag",1);
            setprop("autopilot/locks/heading", "dg-heading-hold") ;
            setprop("controls/autopilot/settings/navsetflag",0)  ;
              gui.popupTip("HDG-set Mode");
              print("HDG-set Mode");
        }         
         # nav ON
          if ( dhc6_HDGMODE == 1 ) {
            setprop("controls/autopilot/settings/hdgsetflag",0);  # disable check in fg9adc button 9
            setprop("controls/autopilot/settings/navsetflag",1)  ;
            if  ( getprop("instrumentation/nav[0]/crs-catched") == 1 ){
               setprop("controls/autopilot/settings/hdgsetflag", 0)  ;
            }
            if  ( getprop("controls/autopilot/settings/hdgflag") == 1 ){
               setprop("autopilot/locks/heading", "nav1-hold")  ;
            }
            gui.popupTip("NAV-set Mode");   
            print("NAV-set Mode");          
        }
         # hdg nav OFF         
          if ( dhc6_HDGMODE == 2 ) {
            setprop("controls/autopilot/settings/hdgsetflag",0);
            setprop("controls/autopilot/settings/navsetflag",0)  ;
            setprop("autopilot/locks/heading", "wing-leveler") ;
              gui.popupTip("HDG Mode ");
              print("HDG Mode"  );            
        }         

             dhc6_HDGMODE = dhc6_HDGMODE + 1;
             if (dhc6_HDGMODE == 3) {dhc6_HDGMODE = 0;}               
      }

       </script>
 </binding>    
 </button>


5) ALT
Code: Select all
# ========================================================================
# dhc6 ALT  on off
# ========================================================================
<button n="3">
   <repeatable type="bool">false</repeatable>
   <desc>Autopilot ALT mode</desc>
   
   # dhc6 ALT  on off
    <binding>
       <command>nasal</command>
       <script>
        if ( (AirCraftType == 3)
       and 
      ( getprop("controls/autopilot/settings/apflag") == 1 ) ) {
         if (getprop("controls/autopilot/settings/altflag") == 0 ) {
            setprop("controls/autopilot/settings/altflag",1);
            Dhc6_AP_Altitude();
            gui.popupTip("AP Altitude on");
         }  else if (getprop("controls/autopilot/settings/altflag") == 1 ) {
            setprop("controls/autopilot/settings/altflag",0)  ;
            Dhc6_AP_Altitude();
            gui.popupTip("AP Altitude off");
         } else {
            gui.popupTip("dhc6 AP Altitude Wrong");
        }
       
      } 
       </script>
 </binding>      
 </button>


6) dhc6 ALT Switch mode altitude-hold . gs1-hold . vertical-speed-hold
I think there must be some fault in there .
If alt hold is on and switch to gs1 hold alt mode should switch of after dhc find gs path
Code: Select all
# ========================================================================
# dhc6 ALT  Switch mode altitude-hold . gs1-hold . vertical-speed-hold
# ========================================================================
<button n="4">
    <repeatable type="bool">false</repeatable>
    <desc>KAP140: NAV  ; CENTURYIII:Move Hdg select button to the right (wrap)</desc>
   
#     dhc6 ALT Switch mode altitude-hold . gs1-hold . vertical-speed-hold
    <binding>
       <command>nasal</command>
       <script>
         if (  (AirCraftType == 3)  and 
                 ( getprop("controls/autopilot/settings/apflag") == 1 )
                and
                   ( getprop("controls/autopilot/settings/altflag") == 1 )
              ) {
             
             setprop("controls/autopilot/settings/iasflag",0);
            setprop("controls/autopilot/settings/vssetflag",0)  ;             
             
             # altitude-hold
         if ( dhc6_ALTMODE == 0 ) {
            setprop("controls/autopilot/settings/altsetflag",1);
            setprop("controls/autopilot/settings/gssetflag",0)  ;
            setprop("controls/autopilot/settings/vssetflag",0)  ;
            setprop("/controls/autopilot/settings/iasflag", 0)  ;
            setprop("autopilot/locks/altitude", "altitude-hold")  ;                  
              gui.popupTip("altitude-hold");
        }

          # Gs-set  mode                    
         if ( dhc6_ALTMODE == 1 ) {
              setprop("controls/autopilot/settings/altsetflag",0);

            if ( ( getprop("instrumentation/nav[0]/gs-in-range") == 1 )
            and
            (getprop("controls/autopilot/settings/altflag") == 1 )) {
               setprop("controls/autopilot/settings/gssetflag", 1)  ;
             }
            if   ( getprop("instrumentation/nav[0]/gs-catched") == 1  ){
               setprop("controls/autopilot/settings/altsetflag", 0)  ;
               setprop("controls/autopilot/settings/iasflag", 0)  ;
               setprop("controls/autopilot/settings/vssetflag", 0)  ;
            }
            if   ( getprop("controls/autopilot/settings/altflag") == 1  ){
               setprop("autopilot/locks/altitude", "gs1-hold")  ;
            }
            gui.popupTip("GS-hold");   
         }
       
        # Vs-set  mode     
         if ( dhc6_ALTMODE == 2 ) {
                 setprop("controls/autopilot/settings/vssetflag",1)  ;
               setprop("/autopilot/locks/altitude", "vertical-speed-hold")  ;
               setprop("controls/autopilot/settings/altsetflag",0);
               setprop("controls/autopilot/settings/gssetflag",0)  ;
               setprop("/controls/autopilot/settings/iasflag", 0)  ;
                 gui.popupTip("VS-hold");                    
        }
                       
             dhc6_ALTMODE = dhc6_ALTMODE + 1;
             if (dhc6_ALTMODE == 3) {dhc6_ALTMODE = 0;}
       }         
       </script>
  </binding>     
  </button> 


7) IAS
Code: Select all
# ======================================================================== 
# dhc6  IAS    on off Speed
# ========================================================================
<button n="5">
    <repeatable type="bool">false</repeatable>
    <desc>IAS</desc>
   
 # 3: dhc6  IAS    on off Speed change nur wenn Airplane fliegt
 
    <binding>
       <command>nasal</command>
       <script>
      print("dhc6  IAS");

       if ( (AirCraftType == 3)
       and 
       ( getprop("controls/autopilot/settings/apflag") == 1 )) {
             
         if ( getprop("controls/autopilot/settings/iasflag") == 0 ) {
            Dhc6_AP_Speed();
                   
            #gui.popupTip("IAS Speed on");
         } else {
            #setprop("controls/autopilot/settings/iasflag",0)  ;
            Dhc6_AP_Speed();
            #gui.popupTip("IAS Speed  off");
         }
      }
       </script>
 </binding>       
 </button>


8) dhc6 AP Vertical Speed # dhc6 AP Vertical Speed -100
Code: Select all
    <binding>
        <command>property-adjust</command>
        <property>autopilot/settings/vertical-speed-fpm</property>
        <factor>-100</factor>
        <min>-6000</min>
        <max>6000</max>
        <wrap>false</wrap>       
     </binding>       


# dhc6 AP Vertical Speed +100
Code: Select all
# dhc6 AP Vertical Speed
    <binding>
        <command>property-adjust</command>
        <property>autopilot/settings/vertical-speed-fpm</property>
        <factor>100</factor>
        <min>-6000</min>
        <max>6000</max>
        <wrap>false</wrap>       
     </binding>   


9) # dhc6 alt.dwn interval 0.2 sec
Code: Select all
# dhc6 alt.dwn
 <interval-sec>0.2</interval-sec>
      <binding>
        <command>property-adjust</command>
        <property>autopilot/settings/target-altitude-ft</property>
        <step>-100/</step>
            <min>1000</min>         
            <max>30000</max>
        <wrap>false</wrap>
      </binding>
       
     <binding>
            <command>nasal</command>
             <script>
            # showroll();
          </script>
     </binding>


# dhc6 alt.up interval 0.2 sec
Code: Select all
# dhc6 alt.up
<interval-sec>0.2</interval-sec>
      <binding>
        <command>property-adjust</command>
        <property>autopilot/settings/target-altitude-ft</property>
        <step>100</step>
        <min>1000</min>         
        <max>30000</max>
        <wrap>false</wrap>
      </binding>
powoflight
 
Posts: 212
Joined: Fri Mar 25, 2016 11:04 am
Location: LOWW
Callsign: OE-POW
Version: 2020.4
OS: win7 Ubuntu 18.04

Re: listen to property to trigger DHC6 autopilot xml

Postby powoflight » Fri Sep 10, 2021 8:57 am

Maybe that version is better (2 Vers) . pls tell me your experience.
Code: Select all
   # =========================================================
   # dhc6 
   # =========================================================
   var Dhc6_AP_Hdg1=func() {
 
   setprop("autopilot/locks/heading", "wing-leveler")  ;
   if  ( getprop("controls/autopilot/settings/hdgflag") == 0  ) {   
         setprop("autopilot/locks/heading", "")  ; 
   }

   if  ( getprop("controls/autopilot/settings/hdgflag") == 0 ){
      setprop("autopilot/locks/heading", "")  ;
   }
   setprop("controls/autopilot/settings/hdgsetflag", 0)  ; 
   setprop("controls/autopilot/settings/navsetflag", 0)  ; 
   
   setprop("autopilot/locks/passive-mode", 0)  ;           
   }

   # =========================================================
   var Dhc6_AP_Altitude1=func() {
   
      print("Dhc6_AP_Altitude=func");
      if  ( getprop("controls/autopilot/settings/iasflag") == 0) {
         setprop("autopilot/locks/altitude", "");   
      }
      setprop("controls/autopilot/settings/altsetflag", 0)  ;
      setprop("controls/autopilot/settings/vssetflag", 0)  ;
      setprop("controls/autopilot/settings/gssetflag", 0)  ;
      setprop("autopilot/locks/passive-mode", 0)  ;
   }   


# ======================================================================== 
#                          DHC6 ALT ON OFF
# ========================================================================
 # dhc6 ALT  on off
    <binding>
       <command>nasal</command>
       <script>
        if ( (AirCraftType == 3)
       and 
      ( getprop("controls/autopilot/settings/apflag") == 1 ) ) {
         if (getprop("controls/autopilot/settings/altflag") == 0 ) {
            setprop("controls/autopilot/settings/altflag",1);
            Dhc6_AP_Altitude1();
            gui.popupTip("AP Altitude on");
         }  else if (getprop("controls/autopilot/settings/altflag") == 1 ) {
            setprop("controls/autopilot/settings/altflag",0)  ;
            Dhc6_AP_Altitude1();
            gui.popupTip("AP Altitude off");
         } else {
            gui.popupTip("dhc6 AP Altitude Wrong");
        }
      } 
       </script>
 </binding>    

# ========================================================================
#                         DHC6 alt hold
# ======================================================================      
   <binding>
       <command>nasal</command>
       <script>
         if (  (AirCraftType == 3)  and 
                 ( getprop("controls/autopilot/settings/apflag") == 1 )
                and
                   ( getprop("controls/autopilot/settings/altflag") == 1 )
              ) {
             
             setprop("controls/autopilot/settings/altsetflag",1);
             setprop("controls/autopilot/settings/vssetflag",0);
             setprop("controls/autopilot/settings/gssetflag",0);
             setprop("controls/autopilot/settings/iasflag",0);
 
            if ( getprop("controls/autopilot/settings/altsetflag") == 1  ) {
               setprop("autopilot/locks/altitude", "altitude-hold")  ;
               gui.popupTip("ALT-hold ON");
             }   
           
    }         
       </script>
  </binding>

# ========================================================================
#                           DHC6 gs hold
# ========================================================================

   <binding>
       <command>nasal</command>
       <script>
         if (  (AirCraftType == 3)  and 
                 ( getprop("controls/autopilot/settings/apflag") == 1 )
                and
                   ( getprop("controls/autopilot/settings/altflag") == 1 )
                and   
                   ( getprop("instrumentation/nav[0]/gs-in-range") == 1 )
              ) {
             
            setprop("controls/autopilot/settings/gssetflag",1);      
             gui.popupTip("GS-hold ON");
             
            if ( getprop("instrumentation/nav[0]/gs-catched") == 1  ) {
               setprop("controls/autopilot/settings/altsetflag",0);
            }

            if ( getprop("instrumentation/nav[0]/gs-catched") == 1  ) {
               setprop("controls/autopilot/settings/iasflag",0);
            }

            if ( getprop("instrumentation/nav[0]/gs-catched") == 1  ) {
               setprop("controls/autopilot/settings/vssetflag",0);
            }

            if ( getprop("controls/autopilot/settings/altflag") == 1  ) {
               setprop("autopilot/locks/altitude","gs1-hold");
            }
    }           
       </script>
  </binding>
   
# ========================================================================
#                         DHC6 vs hold
# ========================================================================
   <binding>
       <command>nasal</command>
       <script>
         if ( (AirCraftType == 3)  and 
              ( getprop("controls/autopilot/settings/apflag") == 1 )
                and
                ( getprop("controls/autopilot/settings/altflag") == 1 )
           ) {
             setprop("controls/autopilot/settings/vssetflag",1);
             setprop("controls/autopilot/settings/altsetflag",0);
             
             setprop("controls/autopilot/settings/gssetflag",0);
             setprop("controls/autopilot/settings/iasflag",0);
             gui.popupTip("VS-hold ON");
           
            if ( getprop("controls/autopilot/settings/altsetflag") == 1  ) {
               setprop("autopilot/locks/altitude", "vertical-speed-hold")  ;
             }               
     }         
       </script>
  </binding>   

# ========================================================================
# DHC6  HDG ON OFF
# ========================================================================
   # dhc6 hdg ON  OFF
     <binding>
       <command>nasal</command>
       <script>
         if ( (AirCraftType == 3) and  ( getprop("controls/autopilot/settings/apflag") == 1 ) ) {
            if ( getprop("controls/autopilot/settings/hdgflag") == 0 ) {
               setprop("controls/autopilot/settings/hdgflag",1);
               Dhc6_AP_Hdg1();
               gui.popupTip("HDG ON");
            } else if ( getprop("controls/autopilot/settings/hdgflag") == 1 ) {
               setprop("controls/autopilot/settings/hdgflag",0)  ;
               Dhc6_AP_Hdg1();
               gui.popupTip("HDG OFF");
            }
         }     
       </script>
  </binding>   

# ========================================================================
# DHC6  hdg
# ========================================================================      
   # dhc6 SWITCH hdg  Mode   
   <binding>
       <command>nasal</command>
       <script>
      if ( (AirCraftType == 3)
         and 
         ( getprop("controls/autopilot/settings/apflag") == 1 )
         and
         ( getprop("controls/autopilot/settings/hdgflag") == 1 )    ) {
         
         if ( getprop("controls/autopilot/settings/hdgsetflag") == 0 ) {
            setprop("controls/autopilot/settings/hdgsetflag",1);
            setprop("autopilot/locks/heading", "dg-heading-hold") ;
            setprop("controls/autopilot/settings/navsetflag",0)  ;
              gui.popupTip("HDG-set Mode ON");
              print("HDG-set Mode ON");
        }   
        else if   ( getprop("controls/autopilot/settings/hdgsetflag") == 1 ) {
            setprop("controls/autopilot/settings/hdgsetflag",0);
            setprop("autopilot/locks/heading", "wing-leveler") ;
            setprop("controls/autopilot/settings/navsetflag",0)  ;
              gui.popupTip("HDG-set Mode OFF");
              print("HDG-set Mode OFF");
        }     
       }
        </script>
  </binding>         

# ========================================================================
# DHC6 nav
# ========================================================================    
    <binding>
       <command>nasal</command>
       <script>
      if ( (AirCraftType == 3)
         and 
         ( getprop("controls/autopilot/settings/apflag") == 1 )
         and
         ( getprop("controls/autopilot/settings/hdgflag") == 1 )    ) {
         
         if ( getprop("controls/autopilot/settings/navsetflag") == 0 ) {
         setprop("controls/autopilot/settings/navsetflag",1);
            setprop("autopilot/locks/heading", "nav1-hold") ;
            ##setprop("controls/autopilot/settings/hdgsetflag",0)  ;
            if  ( getprop("instrumentation/nav[0]/crs-catched") == 1 ){
               setprop("controls/autopilot/settings/hdgsetflag", 0)  ;
            }
          if  ( getprop("controls/autopilot/settings/hdgflag") == 1 ){
               setprop("autopilot/locks/heading", "nav1-hold")  ;
          }
          gui.popupTip("NAV-set Mode ON");
          print("NAV-set Mode ON");
        }   
        else if   ( getprop("controls/autopilot/settings/navsetflag") == 1 ) {
         setprop("controls/autopilot/settings/hdgsetflag",0);
            setprop("controls/autopilot/settings/navsetflag",0) ;
            setprop("autopilot/locks/heading", "wing-leveler") ;
              gui.popupTip("NAV-set Mode OFF");
              print("NAV-set Mode OFF");
        }     
      }
        </script>
  </binding>   





powoflight
 
Posts: 212
Joined: Fri Mar 25, 2016 11:04 am
Location: LOWW
Callsign: OE-POW
Version: 2020.4
OS: win7 Ubuntu 18.04

Re: listen to property to trigger DHC6 autopilot xml

Postby Volador » Fri Sep 10, 2021 10:02 am

Thanks for your code Bernhard, it may be a few days (or weeks) before I'll have time to try it out. It's also made me realise that my current methods of using my Arduino interface could be optimised (the aircraft type parameter) but that's a bigger project I'll need to give it some thought and find time.
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: listen to property to trigger DHC6 autopilot xml

Postby powoflight » Mon Sep 13, 2021 6:47 am

Dear volador
Here is the joystick_pow.nas inc file
You dont need to develop the wheel once again. I need it because i have more than one arduino...

Code: Select all
var powo_test = func() {
   print("Nasal powo include  joystick ");
}

var aircraftversion = func() {
      print("Nasal powo include  aircraftversion ");

     var aircraft =  getprop("sim/aircraft");
     var aircraftversion = getprop("sim/aircraft-version");
     var FGversion = getprop("sim/version/flightgear");
     var AirCraftType = 0;
       
      var F16  = left(aircraft, 3);   # print(F16);
      var A320 = left(aircraft, 4);   # print(A320);
      var c172p = A320;
       
      print("NASAL FGversion:       ",FGversion);
      print("NASAL Aircraft:        ",aircraft );
      print("NASAL Aircraftversion: ", (aircraftversion));
 
      #if (aircraft=="c172p") {
      if (c172p == "c172"            ) {   
           print("FIND c172p AP: KAP140 ");
           AirCraftType=1;
        } elsif (getprop("sim/aircraft")=="SenecaII") {
           print("FIND SenecaII CENTURYIII ");
           AirCraftType=2;
        } elsif ( (getprop("sim/aircraft")=="dhc6") or (getprop("sim/aircraft")=="dhc6F")  ) {
           print("FIND dhc6 ");
           AirCraftType=3;
        } elsif (getprop("sim/aircraft")=="Cessna337") {
           print("FIND Cessna337  ");
           AirCraftType=4;
        } elsif (getprop("sim/aircraft")=="citationx") {
           print("FIND CitationX  ");
           AirCraftType=5;
        } elsif (F16=="f16") {
           print("FIND   F16 ");
           AirCraftType=6;
      } elsif (A320=="A320") {
           print("FIND   A320 idx   ");
           AirCraftType=7;
        }
      return AirCraftType;
}


powoflight
 
Posts: 212
Joined: Fri Mar 25, 2016 11:04 am
Location: LOWW
Callsign: OE-POW
Version: 2020.4
OS: win7 Ubuntu 18.04

Re: listen to property to trigger DHC6 autopilot xml

Postby powoflight » Mon Sep 13, 2021 7:15 am

I have put the joystick_pow.nas in /home/bernhard/.fgfs/Nasal.
The arduino xml files in /home/bernhard/.fgfs/Input/Joysticks.

So the files can be read from different FG versions like stable / next etc, if you compile it by your own.
powoflight
 
Posts: 212
Joined: Fri Mar 25, 2016 11:04 am
Location: LOWW
Callsign: OE-POW
Version: 2020.4
OS: win7 Ubuntu 18.04

Re: listen to property to trigger DHC6 autopilot xml

Postby Volador » Mon Sep 13, 2021 8:28 am

@Powoflight, that is very generous of you, thank you for sharing. I suspect I'll be coming to you with more questions to implement things as it all looks complex to me at the moment - I had a lot of help to get me to where I am with my arduino interface (and I also don't know how to compile FG if that's a step I'll need to take). So I'll apologise in advance for the questions, until then I'll make a copy and keep it in a safe place. Thanks again.
User avatar
Volador
 
Posts: 1140
Joined: Tue Sep 01, 2020 4:58 pm
Callsign: Volador, G-VLDR
Version: 2020.4
OS: Windows 10, 64 bit

Re: listen to property to trigger DHC6 autopilot xml

Postby powoflight » Mon Sep 13, 2021 1:53 pm

@Volador
No problem. you can write me a PM. I can response faster ( I dont look to much in the forum) and we can use jitsi. Sometimes its faster by voice communication. Compiling fg is not a problem if you use Linux.
powoflight
 
Posts: 212
Joined: Fri Mar 25, 2016 11:04 am
Location: LOWW
Callsign: OE-POW
Version: 2020.4
OS: win7 Ubuntu 18.04


Return to Interfacing

Who is online

Users browsing this forum: No registered users and 4 guests