1
0
Fork 0

Roy Vegard Ovesen:

Here is the KAP140 Two Axis Autopilot.

Aircraft/Instruments/KAP140TwoAxis.xml
Is of course the instrument config file.

Aircraft/Instruments/Textures/KAP140.rgb
The texture.

Nasal/kap140.nas
Most of the work is done here. Without Nasal I don't see how I could implement
the NAV-ARM modes and the flashing annunciators.

Aircraft/c172p/Systems/KAP140.xml
The autopilot PID controllers configuration file. Maybe this file should be in
a more accessible directory and not hidden deep inside c172p!?

I've also attached the changes to the default C172 to include this autopilot
in the 3d-cockpit panel and the 2d vfr panel. Or at least I hope that I've
managed to include all that is needed.
This commit is contained in:
curt 2004-04-16 21:59:51 +00:00
parent b5f834b6e7
commit 0dda4feaa0
6 changed files with 1190 additions and 2 deletions

View file

@ -0,0 +1,459 @@
<?xml version="1.0"?>
<!--
_______________________________________________________________________________
KAP140 Two Axis autopilot instrument.
Started 2004 by Roy Vegard Ovesen, rvovesen@tiscali.no.
This is an instrument configuration file for the open-source flight
simulator FlightGear (www.flightgear.org). The file is an XML-encoded
FlightGear property list defining the instrument's layers and actions.
Each instrument is composed of layers stacked on top of each other.
A layer may be a texture (with transparent parts to show the layers
underneath), text, or a special layer that switches between two
others (say, to turn an indicator light on or off). Each layer can
move independently in proportion to a property value, and text
can be generated from property values as well: all of the layer's
movements are defined as transformations.
Actions are hotspots on the instrument that will respond to a mouse
click. Actions always modify the values of properties, either by
adjusting them, toggling them, or swaping them with other
properties' values.
-->
<PropertyList>
<name>KAP140TwoAxis</name>
<w-base>512</w-base>
<h-base>133</h-base>
<!-- Layers -->
<layers>
<layer>
<name>background</name>
<texture>
<path>Aircraft/Instruments/Textures/KAP140.rgb</path>
<x1>0.0</x1>
<x2>1.0</x2>
<y1>0.265625</y1>
<y2>0.529296875</y2>
</texture>
<w>512</w>
<h>133</h>
</layer>
<layer>
<name>AP Anunciator</name>
<condition>
<equals>
<property>/autopilot/KAP140/annunciators/ap</property>
<value>on</value>
</equals>
</condition>
<texture>
<path>Aircraft/Instruments/Textures/KAP140.rgb</path>
<x1>0.32421875</x1>
<x2>0.392578125</x2>
<y1>0.802734375</y1>
<y2>0.845703125</y2>
</texture>
<w>35</w>
<h>21</h>
<transformations>
<transformation>
<type>x-shift</type>
<offset>-160</offset>
</transformation>
<transformation>
<type>y-shift</type>
<offset>40</offset>
</transformation>
</transformations>
</layer>
<layer>
<name>ROL Anunciator</name>
<condition>
<equals>
<property>/autopilot/KAP140/annunciators/rol</property>
<value>on</value>
</equals>
</condition>
<texture>
<path>Aircraft/Instruments/Textures/KAP140.rgb</path>
<x1>0.0</x1>
<x2>0.09765625</x2>
<y1>0.802734375</y1>
<y2>0.845703125</y2>
</texture>
<w>50</w>
<h>21</h>
<transformations>
<transformation>
<type>x-shift</type>
<offset>-152</offset>
</transformation>
<transformation>
<type>y-shift</type>
<offset>40</offset>
</transformation>
</transformations>
</layer>
<layer>
<name>HDG Anunciator</name>
<condition>
<equals>
<property>/autopilot/KAP140/annunciators/hdg</property>
<value>on</value>
</equals>
</condition>
<texture>
<path>Aircraft/Instruments/Textures/KAP140.rgb</path>
<x1>0.1015625</x1>
<x2>0.205078125</x2>
<y1>0.802734375</y1>
<y2>0.845703125</y2>
</texture>
<w>52</w>
<h>21</h>
<transformations>
<transformation>
<type>x-shift</type>
<offset>-150</offset>
</transformation>
<transformation>
<type>y-shift</type>
<offset>40</offset>
</transformation>
</transformations>
</layer>
<layer>
<name>NAV Anunciator</name>
<condition>
<equals>
<property>/autopilot/KAP140/annunciators/nav</property>
<value>on</value>
</equals>
</condition>
<texture>
<path>Aircraft/Instruments/Textures/KAP140.rgb</path>
<x1>0.2109375</x1>
<x2>0.31640625</x2>
<y1>0.802734375</y1>
<y2>0.845703125</y2>
</texture>
<w>53</w>
<h>21</h>
<transformations>
<transformation>
<type>x-shift</type>
<offset>-150</offset>
</transformation>
<transformation>
<type>y-shift</type>
<offset>40</offset>
</transformation>
</transformations>
</layer>
<layer>
<name>NAV ARM Anunciator</name>
<condition>
<equals>
<property>/autopilot/KAP140/annunciators/nav-arm</property>
<value>on</value>
</equals>
</condition>
<texture>
<path>Aircraft/Instruments/Textures/KAP140.rgb</path>
<x1>0.0</x1>
<x2>0.12890625</x2>
<y1>0.939453125</y1>
<y2>1.0</y2>
</texture>
<w>64</w>
<h>30</h>
<transformations>
<transformation>
<type>x-shift</type>
<offset>-145</offset>
</transformation>
<transformation>
<type>y-shift</type>
<offset>15</offset>
</transformation>
</transformations>
</layer>
<layer>
<name>APR Anunciator</name>
<condition>
<equals>
<property>/autopilot/KAP140/annunciators/apr</property>
<value>on</value>
</equals>
</condition>
<texture>
<path>Aircraft/Instruments/Textures/KAP140.rgb</path>
<x1>0.32421875</x1>
<x2>0.4296875</x2>
<y1>0.802734375</y1>
<y2>0.845703125</y2>
</texture>
<w>53</w>
<h>21</h>
<transformations>
<transformation>
<type>x-shift</type>
<offset>-150</offset>
</transformation>
<transformation>
<type>y-shift</type>
<offset>40</offset>
</transformation>
</transformations>
</layer>
<layer>
<name>VS Anunciator</name>
<condition>
<equals>
<property>/autopilot/KAP140/annunciators/vs</property>
<value>on</value>
</equals>
</condition>
<texture>
<path>Aircraft/Instruments/Textures/KAP140.rgb</path>
<x1>0.732421875</x1>
<x2>0.787109375</x2>
<y1>0.802734375</y1>
<y2>0.845703125</y2>
</texture>
<w>28</w>
<h>21</h>
<transformations>
<transformation>
<type>x-shift</type>
<offset>-47</offset>
</transformation>
<transformation>
<type>y-shift</type>
<offset>40</offset>
</transformation>
</transformations>
</layer>
<layer>
<name>FPM Anunciator</name>
<condition>
<equals>
<property>/autopilot/KAP140/annunciators/fpm</property>
<value>on</value>
</equals>
</condition>
<texture>
<path>Aircraft/Instruments/Textures/KAP140.rgb</path>
<x1>0.91015625</x1>
<x2>0.955078125</x2>
<y1>0.978515625</y1>
<y2>0.998046875</y2>
</texture>
<w>23</w>
<h>10</h>
<transformations>
<transformation>
<type>x-shift</type>
<offset>70</offset>
</transformation>
<transformation>
<type>y-shift</type>
<offset>20</offset>
</transformation>
</transformations>
</layer>
<layer>
<name>VS Number</name>
<condition>
<equals>
<property>/autopilot/KAP140/annunciators/vs-number</property>
<value>on</value>
</equals>
</condition>
<type>text</type>
<font>led</font>
<point-size>11</point-size>
<color>
<red>1.0</red>
<green>0.5</green>
<blue>0.0</blue>
</color>
<chunks>
<chunk>
<type>number-value</type>
<property>/autopilot/KAP140/settings/target-pressure-rate</property>
<scale>-58000</scale>
<format>%03.0f</format>
</chunk>
</chunks>
<transformations>
<transformation>
<type>x-shift</type>
<offset>50</offset>
</transformation>
<transformation>
<type>y-shift</type>
<offset>30</offset>
</transformation>
</transformations>
</layer>
<layer>
<name>ALT Anunciator</name>
<condition>
<equals>
<property>/autopilot/KAP140/annunciators/alt</property>
<value>on</value>
</equals>
</condition>
<texture>
<path>Aircraft/Instruments/Textures/KAP140.rgb</path>
<x1>0.623046875</x1>
<x2>0.724609375</x2>
<y1>0.802734375</y1>
<y2>0.845703125</y2>
</texture>
<w>52</w>
<h>21</h>
<transformations>
<transformation>
<type>x-shift</type>
<offset>-60</offset>
</transformation>
<transformation>
<type>y-shift</type>
<offset>40</offset>
</transformation>
</transformations>
</layer>
</layers>
<!-- Actions -->
<actions>
<action>
<name>AP Button</name>
<button>0</button>
<x>-239</x>
<y>-54</y>
<w>30</w>
<h>20</h>
<binding>
<command>nasal</command>
<script>
kap140.ap_button();
</script>
</binding>
</action>
<action>
<name>HDG Button</name>
<button>0</button>
<x>-149</x>
<y>-54</y>
<w>30</w>
<h>20</h>
<binding>
<command>nasal</command>
<script>
kap140.hdg_button();
</script>
</binding>
</action>
<action>
<name>NAV Button</name>
<button>0</button>
<x>-90</x>
<y>-54</y>
<w>30</w>
<h>20</h>
<binding>
<command>nasal</command>
<script>
kap140.nav_button();
</script>
</binding>
</action>
<action>
<name>APR Button</name>
<button>0</button>
<x>-30</x>
<y>-54</y>
<w>30</w>
<h>20</h>
<binding>
<command>nasal</command>
<script>
kap140.apr_button();
</script>
</binding>
</action>
<action>
<name>ALT Button</name>
<button>0</button>
<x>80</x>
<y>-54</y>
<w>30</w>
<h>20</h>
<binding>
<command>nasal</command>
<script>
kap140.alt_button();
</script>
</binding>
</action>
<action>
<name>DN Button</name>
<button>0</button>
<x>128</x>
<y>-48</y>
<w>30</w>
<h>20</h>
<binding>
<command>nasal</command>
<script>
kap140.dn_button();
</script>
</binding>
</action>
<action>
<name>UP Button</name>
<button>0</button>
<x>128</x>
<y>-8</y>
<w>30</w>
<h>20</h>
<binding>
<command>nasal</command>
<script>
kap140.up_button();
</script>
</binding>
</action>
</actions>
</PropertyList>

Binary file not shown.

View file

@ -257,7 +257,7 @@ Legacy 2D instruments and actions for the 3D C172P cockpit.
<instrument include="../../Instruments/dme.xml">
<name>DME</name>
<x>880</x>
<y>16</y>
<y>-50</y>
</instrument>
<!--
@ -267,6 +267,13 @@ Legacy 2D instruments and actions for the 3D C172P cockpit.
<y>-20</y>
</instrument>
-->
<instrument include="../../Instruments/KAP140TwoAxis.xml">
<name>KAP140 Autopilot</name>
<x>880</x>
<y>20</y>
<w>256</w>
<h>64</h>
</instrument>
<!-- end radio stack -->

View file

@ -0,0 +1,233 @@
<?xml version="1.0"?>
<!-- KAP 140 Autopilot Configuration -->
<!-- Each component is evaluated in the order specified. You can make up -->
<!-- property names to pass the result of one component on to a subsequent -->
<!-- component. -->
<PropertyList>
<!-- =============================================================== -->
<!-- Roll Axis Modes -->
<!-- =============================================================== -->
<!-- Nav hold (NAV) Mode-->
<pid-controller>
<name>Nav hold (NAV) Mode</name>
<debug>false</debug>
<enable>
<prop>/autopilot/KAP140/locks/nav-hold</prop>
<value>nav</value>
</enable>
<input>
<prop>/radios/nav/heading-needle-deflection</prop>
</input>
<reference>
<value>0.0</value>
</reference>
<output>
<prop>/autopilot/KAP140/settings/target-intercept-angle</prop>
</output>
<config>
<Kp>7.0</Kp> <!-- proportional gain -->
<beta>1.0</beta> <!-- input value weighing factor -->
<alpha>0.1</alpha> <!-- low pass filter weighing factor -->
<gamma>0.0</gamma> <!-- input value weighing factor for -->
<!-- unfiltered derivative error -->
<Ti>10.0</Ti> <!-- integrator time -->
<Td>0.0</Td> <!-- derivator time -->
<u_min>-45.0</u_min> <!-- minimum output clamp -->
<u_max>45.0</u_max> <!-- maximum output clamp -->
</config>
</pid-controller>
<!-- Approach hold (APR) Mode-->
<pid-controller>
<name>Approach hold (APR) Mode</name>
<debug>true</debug>
<enable>
<prop>/autopilot/KAP140/locks/apr-hold</prop>
<value>apr</value>
</enable>
<input>
<prop>/radios/nav/heading-needle-deflection</prop>
</input>
<reference>
<value>0.0</value>
</reference>
<output>
<prop>/autopilot/KAP140/settings/target-intercept-angle</prop>
</output>
<config>
<Kp>7.0</Kp> <!-- proportional gain -->
<beta>1.0</beta> <!-- input value weighing factor -->
<alpha>0.1</alpha> <!-- low pass filter weighing factor -->
<gamma>0.0</gamma> <!-- input value weighing factor for -->
<!-- unfiltered derivative error -->
<Ti>10.0</Ti> <!-- integrator time -->
<Td>0.0</Td> <!-- derivator time -->
<u_min>-45.0</u_min> <!-- minimum output clamp -->
<u_max>45.0</u_max> <!-- maximum output clamp -->
</config>
</pid-controller>
<!-- Heading Select (HDG) Mode -->
<pid-controller>
<name>Heading Select (HDG) Mode</name>
<debug>false</debug>
<enable>
<prop>/autopilot/KAP140/locks/hdg-hold</prop>
<value>hdg</value>
</enable>
<input>
<prop>/autopilot/internal/heading-bug-error-deg</prop>
</input>
<reference>
<prop>/autopilot/KAP140/settings/target-intercept-angle</prop>
</reference>
<output>
<prop>/autopilot/KAP140/settings/target-turn-rate</prop>
</output>
<config>
<Kp>-0.05</Kp> <!-- proportional gain -->
<beta>1.0</beta> <!-- input value weighing factor -->
<alpha>0.1</alpha> <!-- low pass filter weighing factor -->
<gamma>0.0</gamma> <!-- input value weighing factor for -->
<!-- unfiltered derivative error -->
<Ti>15.0</Ti> <!-- integrator time -->
<Td>0.0</Td> <!-- derivator time -->
<u_min>-0.9</u_min> <!-- minimum output clamp -->
<u_max>0.9</u_max> <!-- maximum output clamp -->
</config>
</pid-controller>
<!-- Wing leveler (ROL) Mode -->
<pid-controller>
<name>Wing Leveler (ROL) Mode</name>
<debug>false</debug>
<enable>
<prop>/autopilot/KAP140/locks/roll-axis</prop>
<value>trn</value>
</enable>
<input>
<prop>/instrumentation/turn-indicator/indicated-turn-rate</prop>
</input>
<reference>
<prop>/autopilot/KAP140/settings/target-turn-rate</prop>
</reference>
<output>
<prop>/controls/flight/aileron-trim</prop>
</output>
<config>
<Kp>0.15</Kp> <!-- proportional gain -->
<beta>1.0</beta> <!-- input value weighing factor -->
<alpha>0.1</alpha> <!-- low pass filter weighing factor -->
<gamma>0.0</gamma> <!-- input value weighing factor for -->
<!-- unfiltered derivative error -->
<Ti>15.0</Ti> <!-- integrator time -->
<Td>0.0</Td> <!-- derivator time -->
<u_min>-0.25</u_min> <!-- minimum output clamp -->
<u_max>0.25</u_max> <!-- maximum output clamp -->
</config>
</pid-controller>
<!-- =============================================================== -->
<!-- Pitch Axis Modes -->
<!-- =============================================================== -->
<!-- Altitude Hold (ALT) Mode -->
<pid-controller>
<name>Altitude Hold (ALT) Mode</name>
<debug>false</debug>
<enable>
<prop>/autopilot/KAP140/locks/alt-hold</prop>
<value>alt</value>
</enable>
<input>
<prop>/systems/static[0]/pressure-inhg[0]</prop>
</input>
<reference>
<prop>/autopilot/KAP140/settings/target-alt-pressure</prop>
</reference>
<output>
<prop>/autopilot/KAP140/settings/target-pressure-rate</prop>
</output>
<config>
<Kp>0.125</Kp> <!-- proportional gain -->
<beta>1.0</beta> <!-- input value weighing factor -->
<alpha>0.1</alpha> <!-- low pass filter weighing factor -->
<gamma>0.0</gamma> <!-- input value weighing factor for -->
<!-- unfiltered derivative error -->
<Ti>12.0</Ti> <!-- integrator time -->
<Td>0.0</Td> <!-- derivator time -->
<u_min>-0.007</u_min> <!-- minimum output clamp -->
<u_max>0.007</u_max> <!-- maximum output clamp -->
</config>
</pid-controller>
<!-- Glideslope Hold (GS) Mode -->
<pid-controller>
<name>Glideslope Hold (GS) Mode</name>
<debug>true</debug>
<enable>
<prop>/autopilot/KAP140/locks/gs-hold</prop>
<value>gs</value>
</enable>
<input>
<prop>/radios/nav/gs-needle-deflection</prop>
</input>
<reference>
<value>0.0</value>
</reference>
<output>
<prop>/autopilot/KAP140/settings/target-pressure-rate</prop>
</output>
<config>
<Kp>0.025</Kp> <!-- proportional gain -->
<beta>1.0</beta> <!-- input value weighing factor -->
<alpha>0.1</alpha> <!-- low pass filter weighing factor -->
<gamma>0.0</gamma> <!-- input value weighing factor for -->
<!-- unfiltered derivative error -->
<Ti>15.0</Ti> <!-- integrator time -->
<Td>0.0</Td> <!-- derivator time -->
<u_min>-0.001</u_min> <!-- minimum output clamp -->
<u_max>0.017</u_max> <!-- maximum output clamp -->
</config>
</pid-controller>
<!-- Vertical Speed (VS) Mode -->
<pid-controller>
<name>Vertical Speed (VS) Mode</name>
<debug>false</debug>
<enable>
<prop>/autopilot/KAP140/locks/pitch-axis</prop>
<value>vs</value>
</enable>
<input>
<prop>/autopilot/internal/pressure-rate</prop>
</input>
<reference>
<prop>/autopilot/KAP140/settings/target-pressure-rate</prop>
</reference>
<output>
<prop>/controls/flight/elevator-trim</prop>
</output>
<config>
<Kp>5.0</Kp> <!-- proportional gain -->
<beta>1.0</beta> <!-- input value weighing factor -->
<alpha>0.1</alpha> <!-- low pass filter weighing factor -->
<gamma>0.0</gamma> <!-- input value weighing factor for -->
<!-- unfiltered derivative error -->
<Ti>4.0</Ti> <!-- integrator time -->
<Td>0.0</Td> <!-- derivator time -->
<u_min>-0.5</u_min> <!-- minimum output clamp -->
<u_max>0.5</u_max> <!-- maximum output clamp -->
</config>
</pid-controller>
</PropertyList>

View file

@ -40,7 +40,7 @@ Started October 23 2001 by John Check, fgpanels@rockfish.net
<systems>
<autopilot>
<path>Aircraft/Generic/generic-autopilot.xml</path>
<path>Aircraft/c172p/Systems/KAP140.xml</path>
</autopilot>
<electrical>
<path>Aircraft/c172/c172-electrical.xml</path>

489
Nasal/kap140.nas Normal file
View file

@ -0,0 +1,489 @@
##
# Bendix/King KAP140 Two Axis Autopilot System
##
Locks = "/autopilot/KAP140/locks";
Settings = "/autopilot/KAP140/settings";
Annunciators = "/autopilot/KAP140/annunciators";
Internal = "/autopilot/internal";
annunciator = "";
annunciator_state = "";
flash_interval = 0.0;
flash_count = 0.0;
flash_timer = -1.0;
flasher = func {
annunciator = arg[0];
flash_interval = arg[1];
flash_count = arg[2] + 1;
annunciator_state = arg[3];
flash_timer = 0.0;
flash_annunciator();
}
flash_annunciator = func {
#print(annunciator);
#print(flash_interval);
#print(flash_count);
##
# If flash_timer is set to -1 then flashing is aborted
if (flash_timer < -0.5)
{
setprop(Annunciators, annunciator, "off");
return;
}
if (flash_timer < flash_count)
{
#flash_timer = flash_timer + 1.0;
if (getprop(Annunciators, annunciator) == "on")
{
setprop(Annunciators, annunciator, "off");
settimer(flash_annunciator, flash_interval / 2.0);
}
else
#elsif (getprop(Annunciators, annunciator) == "off")
{
flash_timer = flash_timer + 1.0;
setprop(Annunciators, annunciator, "on");
settimer(flash_annunciator, flash_interval);
}
}
else
{
flash_timer = -1.0;
setprop(Annunciators, annunciator, annunciator_state);
}
}
ap_button = func {
#print("ap_button");
##
# Engages the autopilot in Wings level mode (ROL) and Vertical speed hold
# mode (VS).
##
if (getprop(Locks, "roll-mode") == "off" and
getprop(Locks, "pitch-mode") == "off")
{
flash_timer = -1.0;
setprop(Locks, "alt-hold", "off");
setprop(Locks, "apr-hold", "off");
setprop(Locks, "gs-hold", "off");
setprop(Locks, "hdg-hold", "off");
setprop(Locks, "nav-hold", "off");
setprop(Locks, "roll-axis", "trn");
setprop(Locks, "roll-mode", "rol");
setprop(Locks, "pitch-axis", "vs");
setprop(Locks, "pitch-mode", "vs");
setprop(Annunciators, "rol", "on");
setprop(Annunciators, "vs", "on");
setprop(Annunciators, "fpm", "on");
setprop(Annunciators, "vs-number", "on");
setprop(Settings, "target-turn-rate", 0.0);
setprop(Settings, "target-pressure-rate", getprop(Internal,
"pressure-rate"));
}
##
# Disengages all modes.
##
elsif (getprop(Locks, "roll-mode") != "off" and
getprop(Locks, "pitch-mode") != "off")
{
flash_timer = -1.0;
setprop(Locks, "alt-hold", "off");
setprop(Locks, "apr-hold", "off");
setprop(Locks, "gs-hold", "off");
setprop(Locks, "hdg-hold", "off");
setprop(Locks, "nav-hold", "off");
setprop(Locks, "roll-axis", "off");
setprop(Locks, "roll-mode", "off");
setprop(Locks, "pitch-axis", "off");
setprop(Locks, "pitch-mode", "off");
setprop(Settings, "target-alt-pressure", 0.0);
setprop(Settings, "target-intercept-angle", 0.0);
setprop(Settings, "target-pressure-rate", 0.0);
setprop(Settings, "target-turn-rate", 0.0);
setprop(Annunciators, "rol", "off");
setprop(Annunciators, "hdg", "off");
setprop(Annunciators, "nav", "off");
setprop(Annunciators, "nav-arm", "off");
setprop(Annunciators, "vs", "off");
setprop(Annunciators, "vs-number", "off");
setprop(Annunciators, "fpm", "off");
setprop(Annunciators, "alt", "off");
setprop(Annunciators, "apr", "off");
setprop(Annunciators, "gs", "off");
flasher("ap", 1.0, 5, "off");
setprop(Internal, "ft", 0.1);
}
}
hdg_button = func {
#print("hdg_button");
##
# Engages the heading mode (HDG) and vertical speed hold mode (VS). The
# commanded vertical speed is set to the vertical speed present at button
# press.
##
if (getprop(Locks, "roll-mode") == "off" and
getprop(Locks, "pitch-mode") == "off")
{
setprop(Locks, "alt-hold", "off");
setprop(Locks, "apr-hold", "off");
setprop(Locks, "gs-hold", "off");
setprop(Locks, "hdg-hold", "hdg");
setprop(Locks, "nav-hold", "off");
setprop(Locks, "roll-axis", "trn");
setprop(Locks, "roll-mode", "hdg");
setprop(Locks, "pitch-axis", "vs");
setprop(Locks, "pitch-mode", "vs");
setprop(Annunciators, "hdg", "on");
setprop(Annunciators, "alt", "off");
setprop(Annunciators, "apr", "off");
setprop(Annunciators, "gs", "off");
setprop(Annunciators, "nav", "off");
setprop(Annunciators, "vs", "on");
setprop(Annunciators, "vs-number", "on");
setprop(Annunciators, "fpm", "on");
setprop(Settings, "target-intercept-angle", 0.0);
setprop(Settings, "target-pressure-rate", getprop(Internal,
"pressure-rate"));
}
##
# Switch to HDG mode, but don't change pitch mode.
##
elsif (getprop(Locks, "roll-mode") == "rol" or
getprop(Locks, "roll-mode") == "nav" or
getprop(Locks, "roll-mode") == "nav-arm" or
getprop(Locks, "roll-mode") == "rev")
{
#setprop(Locks, "alt-hold", "off");
setprop(Locks, "apr-hold", "off");
setprop(Locks, "gs-hold", "off");
setprop(Locks, "hdg-hold", "hdg");
setprop(Locks, "nav-hold", "off");
setprop(Locks, "roll-axis", "trn");
setprop(Locks, "roll-mode", "hdg");
#setprop(Locks, "pitch-axis", "off");
#setprop(Locks, "pitch-mode", "off");
setprop(Annunciators, "apr", "off");
setprop(Annunciators, "gs", "off");
setprop(Annunciators, "hdg", "on");
setprop(Annunciators, "nav", "off");
setprop(Annunciators, "rol", "off");
setprop(Settings, "target-intercept-angle", 0.0);
}
##
# If we already are in HDG mode switch to ROL mode. Again don't touch pitch
# mode.
##
elsif (getprop(Locks, "roll-mode") == "hdg")
{
#setprop(Locks, "alt-hold", "off");
setprop(Locks, "apr-hold", "off");
setprop(Locks, "gs-hold", "off");
setprop(Locks, "hdg-hold", "off");
setprop(Locks, "nav-hold", "off");
setprop(Locks, "roll-axis", "trn");
setprop(Locks, "roll-mode", "rol");
#setprop(Locks, "pitch-axis", "off");
#setprop(Locks, "pitch-mode", "off");
setprop(Annunciators, "apr", "off");
setprop(Annunciators, "gs", "off");
setprop(Annunciators, "hdg", "off");
setprop(Annunciators, "nav", "off");
setprop(Annunciators, "rol", "on");
setprop(Settings, "target-turn-rate", 0.0);
}
##
# If we are in APR mode we also have to change pitch mode.
# TODO: Should we switch to VS or ALT mode? (currently VS)
##
elsif (getprop(Locks, "roll-mode") == "apr" and
getprop(Locks, "pitch-mode") == "gs")
{
setprop(Locks, "alt-hold", "off");
setprop(Locks, "apr-hold", "off");
setprop(Locks, "gs-hold", "off");
setprop(Locks, "hdg-hold", "hdg");
setprop(Locks, "nav-hold", "off");
setprop(Locks, "roll-axis", "trn");
setprop(Locks, "roll-mode", "hdg");
setprop(Locks, "pitch-axis", "vs");
setprop(Locks, "pitch-mode", "vs");
setprop(Annunciators, "alt", "off");
setprop(Annunciators, "apr", "off");
setprop(Annunciators, "gs", "off");
setprop(Annunciators, "hdg", "on");
setprop(Annunciators, "nav", "off");
setprop(Annunciators, "vs", "on");
setprop(Annunciators, "vs-number", "on");
setprop(Annunciators, "fpm", "on");
setprop(Settings, "target-intercept-angle", 0.0);
setprop(Settings, "target-pressure-rate", getprop(Internal,
"pressure-rate"));
}
}
nav_button = func {
#print("nav_button");
if (getprop(Locks, "roll-mode") == "hdg")
{
flasher("hdg", 0.5, 8, "off");
setprop(Locks, "apr-hold", "off");
setprop(Locks, "gs-hold", "off");
setprop(Locks, "hdg-hold", "hdg");
setprop(Locks, "nav-hold", "off");
setprop(Locks, "roll-axis", "trn");
setprop(Locks, "roll-mode", "nav-arm");
nav_arm_from_hdg();
}
elsif (getprop(Locks, "roll-mode") == "rol")
{
flasher("hdg", 0.5, 8, "off");
setprop(Locks, "apr-hold", "off");
setprop(Locks, "gs-hold", "off");
setprop(Locks, "hdg-hold", "off");
setprop(Locks, "nav-hold", "off");
setprop(Locks, "roll-axis", "trn");
setprop(Locks, "roll-mode", "nav-arm");
nav_arm_from_rol();
}
elsif (getprop(Locks, "roll-mode") == "apr" and
getprop(Locks, "pitch-mode") == "gs")
{
setprop(Locks, "alt-hold", "off");
setprop(Locks, "apr-hold", "off");
setprop(Locks, "gs-hold", "off");
setprop(Locks, "hdg-hold", "hdg");
setprop(Locks, "nav-hold", "nav");
setprop(Locks, "roll-axis", "trn");
setprop(Locks, "roll-mode", "nav");
setprop(Locks, "pitch-axis", "vs");
setprop(Locks, "pitch-mode", "vs");
setprop(Settings, "target-pressure-rate", getprop(Internal,
"pressure-rate"));
}
}
nav_arm_from_hdg = func
{
if (getprop(Locks, "roll-mode") != "nav-arm")
{
setprop(Annunciators, "nav-arm", "off");
return;
}
setprop(Annunciators, "nav-arm", "on");
if (flash_timer > -0.5)
{
print("flashing...");
settimer(nav_arm_from_hdg, 2.5);
return;
}
setprop(Locks, "nav-hold", "nav");
deviation = getprop("/radios/nav/heading-needle-deflection");
if (abs(deviation) > 3.0)
{
print("deviation");
settimer(nav_arm_from_hdg, 5);
return;
}
elsif (abs(deviation) < 3.1)
{
print("capture");
setprop(Annunciators, "nav-arm", "off");
setprop(Annunciators, "nav", "on");
}
}
nav_arm_from_rol = func
{
if (getprop(Locks, "roll-mode") != "nav-arm")
{
setprop(Annunciators, "nav-arm", "off");
return;
}
setprop(Annunciators, "nav-arm", "on");
if (flash_timer > -0.5)
{
print("flashing...");
setprop(Annunciators, "rol", "off");
settimer(nav_arm_from_rol, 2.5);
return;
}
setprop(Annunciators, "rol", "on");
setprop(Locks, "roll-axis", "trn");
setprop(Settings, "target-turn-rate", 0.0);
deviation = getprop("/radios/nav/heading-needle-deflection");
if (abs(deviation) > 3.0)
{
print("deviation");
settimer(nav_arm_from_rol, 5);
return;
}
elsif (abs(deviation) < 3.1)
{
print("capture");
setprop(Annunciators, "rol", "off");
setprop(Annunciators, "nav-arm", "off");
setprop(Annunciators, "nav", "on");
setprop(Locks, "apr-hold", "off");
setprop(Locks, "gs-hold", "off");
setprop(Locks, "hdg-hold", "hdg");
setprop(Locks, "nav-hold", "nav");
setprop(Locks, "roll-axis", "trn");
setprop(Locks, "roll-mode", "nav");
}
}
apr_button = func {
#print("apr_button");
if (getprop(Locks, "roll-mode") == "hdg" or
getprop(Locks, "roll-mode") == "rol" or
getprop(Locks, "roll-mode") == "rev" or
#getprop(Locks, "roll-mode") == "apr" or
getprop(Locks, "pitch-mode") == "nav")
{
setprop(Locks, "alt-hold", "off");
setprop(Locks, "apr-hold", "apr");
setprop(Locks, "gs-hold", "gs");
setprop(Locks, "hdg-hold", "off");
setprop(Locks, "nav-hold", "off");
setprop(Locks, "roll-axis", "trn");
setprop(Locks, "roll-mode", "apr");
setprop(Locks, "pitch-axis", "vs");
setprop(Locks, "pitch-mode", "gs");
}
elsif (getprop(Locks, "roll-mode") == "apr" and
getprop(Locks, "pitch-mode") == "gs")
{
setprop(Locks, "alt-hold", "off");
setprop(Locks, "apr-hold", "off");
setprop(Locks, "gs-hold", "off");
setprop(Locks, "hdg-hold", "hdg");
setprop(Locks, "nav-hold", "nav");
setprop(Locks, "roll-axis", "trn");
setprop(Locks, "roll-mode", "nav");
setprop(Locks, "pitch-axis", "vs");
setprop(Locks, "pitch-mode", "vs");
setprop(Settings, "target-pressure-rate", getprop(Internal,
"pressure-rate"));
}
}
alt_button = func {
#print("alt_button");
if (getprop(Locks, "pitch-mode") == "alt")
{
setprop(Locks, "alt-hold", "off");
#setprop(Locks, "apr-hold", "apr");
#setprop(Locks, "gs-hold", "gs");
#setprop(Locks, "hdg-hold", "off");
#setprop(Locks, "nav-hold", "off");
#setprop(Locks, "roll-axis", "trn");
#setprop(Locks, "roll-mode", "apr");
setprop(Locks, "pitch-axis", "vs");
setprop(Locks, "pitch-mode", "vs");
setprop(Annunciators, "alt", "off");
setprop(Annunciators, "vs", "on");
setprop(Annunciators, "vs-number", "on");
setprop(Annunciators, "fpm", "on");
setprop(Settings, "target-pressure-rate", getprop(Internal,
"pressure-rate"));
}
elsif (getprop(Locks, "pitch-mode") == "vs")
{
setprop(Locks, "alt-hold", "alt");
#setprop(Locks, "apr-hold", "off");
#setprop(Locks, "gs-hold", "off");
#setprop(Locks, "hdg-hold", "hdg");
#setprop(Locks, "nav-hold", "nav");
#setprop(Locks, "roll-axis", "trn");
#setprop(Locks, "roll-mode", "nav");
setprop(Locks, "pitch-axis", "vs");
setprop(Locks, "pitch-mode", "alt");
setprop(Annunciators, "alt", "on");
setprop(Annunciators, "vs", "off");
setprop(Annunciators, "vs-number", "off");
setprop(Annunciators, "fpm", "off");
setprop(Settings, "target-alt-pressure",
getprop("/systems/static/pressure-inhg"));
}
}
dn_button = func {
#print("dn_button");
if (getprop(Locks, "pitch-mode") == "vs")
{
Target_VS = getprop(Settings, "target-pressure-rate");
setprop(Settings, "target-pressure-rate", Target_VS +
0.0017241379310345);
}
elsif (getprop(Locks, "pitch-mode") == "alt")
{
Target_Pressure = getprop(Settings, "target-alt-pressure");
setprop(Settings, "target-alt-pressure", Target_Pressure + 0.0206);
}
}
up_button = func {
#print("up_button");
if (getprop(Locks, "pitch-mode") == "vs")
{
Target_VS = getprop(Settings, "target-pressure-rate");
setprop(Settings, "target-pressure-rate", Target_VS -
0.0017241379310345);
}
elsif (getprop(Locks, "pitch-mode") == "alt")
{
Target_Pressure = getprop(Settings, "target-alt-pressure");
setprop(Settings, "target-alt-pressure", Target_Pressure - 0.0206);
}
}
ap_button();