Implementing VNAV support in FlightGear: Difference between revisions

Jump to navigation Jump to search
m
Line 394: Line 394:


Scripts are loaded via '''bool FGScript::LoadScript()'''
Scripts are loaded via '''bool FGScript::LoadScript()'''
=== A test profile ===
We will need a test profile with different waypoints and altitude constraints to perform various test flights, and PID tuning.
<syntaxhighlight lang="xml">
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="http://jsbsim.sf.net/JSBSimScript.xsl"?>
<runscript xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://jsbsim.sf.net/JSBSimScript.xsd"
    name="C310-01A ksfo approach run" flightgear-version="2.99.0"
    creation-date="2013-12-07T18:39:39">
<!-- this is an automatically created JSBSim FGScript XML file, see $FG_ROOT/gui/dialogs/route-manager.xml
    DO NOT EDIT MANUALLY - edit $FG_ROOT/gui/dialogs/jsbsim-fgscript.template instead
-->
  <description>For basic VNAV experiments</description>
  <!-- fdm we are using, and name of XML file we use to initialize our position  -->
  <use aircraft="c310" initialize="ksfo-approach"/>
 
  <run start="0.0" end="3600" dt="0.008333333">
    <property value="0"> simulation/notify-trigger </property>
    <event name="Standard Notify" persistent="true">
      <description>Output message at periodic intervals</description>
      <condition> simulation/notify-trigger ge 0.5 </condition>
      <set name="simulation/notify-trigger" value="0"/>
      <notify>
<!-- list of properties we want to inspect during each notification -->
        <property>ap/active-waypoint</property>
<property>guidance/wp-distance</property>
        <property>guidance/target_wp_latitude_rad</property>
        <property>guidance/target_wp_longitude_rad</property>
  <property>ap/altitude_setpoint</property>
        <property>position/h-agl-ft</property>
        <property>velocities/vt-fps</property>
<!--
        <property>propulsion/engine[0]/propeller-rpm</property>
        <property>propulsion/engine[1]/propeller-rpm</property>
        <property>propulsion/engine[0]/power-hp</property>
        <property>propulsion/engine[1]/power-hp</property>
        <property>propulsion/engine[0]/thrust-lbs</property>
        <property>propulsion/engine[1]/thrust-lbs</property>
        <property>propulsion/engine[0]/blade-angle</property>
        <property>propulsion/engine[1]/blade-angle</property>
        <property>fcs/rudder-pos-rad</property>
        <property>fcs/mixture-pos-norm[1]</property>
        <property>fcs/yaw-trim-sum</property>
-->
      </notify>
    </event>
<!-- Strict typing: Since the units system (XML) isn't exposed/enforced via properties, some sanity checks here
Best practice: add this to each system/component for I/O properties
-->
<event name="is_valid_azimuth_check failed">
<description>ERROR:Ensure that property value is within valid range</description>
<condition logic="OR">
ap/heading_setpoint gt 360
ap/heading_setpoint lt 0.00
</condition>
<set name="simulation/terminate" value="1"/>
<notify>
<property>ap/heading_setpoint</property>
</notify>
</event>
<event name="is_valid_radian_check failed">
<description>ERROR:Ensure that property value is within valid range</description>
<condition logic="OR">
guidance/target_wp_latitude_rad gt 1.6
guidance/target_wp_latitude_rad lt -1.6
guidance/target_wp_longitude_rad gt 3.15
guidance/target_wp_longitude_rad lt -3.15
</condition>
<set name="simulation/terminate" value="1"/>
<notify>
<property>guidance/target_wp_latitude_deg</property>
<property>guidance/target_wp_longitude_rad</property>
</notify>
</event>
<!-- basic aircraft setup FIXME: trim in-air instead or do a proper takeoff from KSFO 100L-->
    <event name="Start engine">
      <description>
        Start engine and set initial heading and waypoints, turn on heading-hold mode.
      </description>
      <condition>simulation/sim-time-sec  ge  0.25</condition>
      <set name="fcs/mixture-cmd-norm[0]" value="1"/>
      <set name="fcs/mixture-cmd-norm[1]" value="1"/>
      <set name="fcs/advance-cmd-norm[0]" value="1.0"/>
      <set name="fcs/advance-cmd-norm[1]" value="1.0"/>
      <set name="propulsion/magneto_cmd" value="3"/>
      <set name="fcs/throttle-cmd-norm[0]" value="1.0"/>
      <set name="fcs/throttle-cmd-norm[1]" value="1.0"/>
      <set name="propulsion/starter_cmd" value="1"/>
      <set name="ap/attitude_hold" value="0"/>
<!-- initial waypoint: BARTN -->
      <set name="guidance/target_wp_latitude_rad" value="0.65534383642553"/>
      <set name="guidance/target_wp_longitude_rad" value="-2.130765632268315"/>
      <set name="ap/heading_setpoint" value="100"/>
      <set name="ap/heading-setpoint-select" value="0"/>
      <set name="ap/heading_hold" value="1"/>
      <set name="ap/yaw_damper" value="1"/>
      <set name="ap/active-waypoint" value="0"/>
      <set name="ap/altitude_setpoint" action="exp" value="5000.0" tc="10"/>
      <set name="simulation/notify-trigger" value="1"/>
      <notify>
<property>ap/altitude_setpoint</property>
      </notify>
    </event>
    <event name="Raise landing gear">
      <condition>position/h-agl-ft  ge  40</condition>
      <set name="gear/gear-cmd-norm" value="0"/>
      <set name="fcs/advance-cmd-norm[0]" action="exp" value="0.85" tc="1.0"/>
      <set name="fcs/advance-cmd-norm[1]" action="exp" value="0.85" tc="1.0"/>
      <notify/>
    </event>
    <event name="Full Throttle">
      <condition>velocities/vc-fps ge 300</condition>
      <set name="fcs/throttle-cmd-norm[0]" value="1"/>
      <set name="fcs/throttle-cmd-norm[1]" value="1"/>
      <set name="simulation/notify-trigger" value="1"/>
      <set name="ap/altitude_setpoint" value="5000.0" tc="1.0"/>
      <set name="ap/altitude_hold" value="1"/>
      <notify>
<property>ap/altitude_setpoint</property>
      </notify>
    </event>
    <event name="fly to first waypoint">
      <description>
        Set heading hold to selected waypoint (setpoint) instead of
        previously specified heading
      </description>
      <condition>simulation/sim-time-sec  ge  .5</condition>
      <set name="ap/heading-setpoint-select" value="1"/>
      <set name="ap/active-waypoint" value="1"/>
      <set name="simulation/notify-trigger" value="1"/>
      <notify>
        <property>guidance/wp-distance</property>
      </notify>
    </event>
  <event name="Terminate">
      <description> terminate
      </description>
      <condition>
        ap/active-waypoint eq 9
      </condition>
      <set name="simulation/terminate" value="1"/>
      <set name="simulation/notify-trigger" value="1"/>
      <notify>
        <property>guidance/wp-distance</property>
<property>ap/altitude_setpoint</property>
      </notify>
    </event>
<!-- end of predefined dependencies -->
<!-- begin of automatically inserted waypoint events, see $FG_ROOT/gui/dialogs/route-manager.xml -->
<event name="Waypoint:8" continuous="false" persistent="false">
<description>Waypoint #8 </description>
<!-- set up condition to trigger this waypoint -->
<condition logic="AND">
ap/active-waypoint eq 8
guidance/wp-distance lt 1000
</condition>
<!-- waypoint lat:37.70824999999999/lon:-122.5996669999999 -->
<!-- coordinates in radians according to GNCUtilities.xml -->
<set name="guidance/target_wp_latitude_rad" type="value"  value="0.6581331169131249"/>
<set name="guidance/target_wp_longitude_rad" type="value" value="-2.139767848553598"/>
<!-- add altitude TODO: speed constraints here -->
<set name="ap/altitude_setpoint" type="value" value="0"/>
<!-- leg stuff here (not yet used)-->
<!--
<set name="guidance/leg/wp1/latitude-rad"  type="value" value="0.6581331169131249"/>
<set name="guidance/leg/wp1/longitude-rad" type="value" value="-2.139767848553598"/>
<set name="guidance/leg/wp1/altitude-ft" type="value" value="0"/>
-->
<!-- now, set signal to activate next waypoint -->
<set name="ap/active-waypoint" type="value" value="9"/>
<set name="simulation/notify-trigger" type="value" value="1"/>
<notify>
<property>guidance/wp-distance</property>
<property>ap/altitude_setpoint</property>
</notify>
</event>
<event name="Waypoint:7" continuous="false" persistent="false">
<description>Waypoint #7 </description>
<!-- set up condition to trigger this waypoint -->
<condition logic="AND">
ap/active-waypoint eq 7
guidance/wp-distance lt 1000
</condition>
<!-- waypoint lat:37.571778/lon:-122.257861 -->
<!-- coordinates in radians according to GNCUtilities.xml -->
<set name="guidance/target_wp_latitude_rad" type="value"  value="0.655751231179065"/>
<set name="guidance/target_wp_longitude_rad" type="value" value="-2.133802208457343"/>
<!-- add altitude TODO: speed constraints here -->
<set name="ap/altitude_setpoint" type="value" value="5500"/>
<!-- leg stuff here (not yet used)-->
<!--
<set name="guidance/leg/wp1/latitude-rad"  type="value" value="0.655751231179065"/>
<set name="guidance/leg/wp1/longitude-rad" type="value" value="-2.133802208457343"/>
<set name="guidance/leg/wp1/altitude-ft" type="value" value="5500"/>
-->
<!-- now, set signal to activate next waypoint -->
<set name="ap/active-waypoint" type="value" value="8"/>
<set name="simulation/notify-trigger" type="value" value="1"/>
<notify>
<property>guidance/wp-distance</property>
<property>ap/altitude_setpoint</property>
</notify>
</event>
<event name="Waypoint:6" continuous="false" persistent="false">
<description>Waypoint #6 </description>
<!-- set up condition to trigger this waypoint -->
<condition logic="AND">
ap/active-waypoint eq 6
guidance/wp-distance lt 1000
</condition>
<!-- waypoint lat:37.53594399999999/lon:-122.172889 -->
<!-- coordinates in radians according to GNCUtilities.xml -->
<set name="guidance/target_wp_latitude_rad" type="value"  value="0.65512580989562"/>
<set name="guidance/target_wp_longitude_rad" type="value" value="-2.132319167287033"/>
<!-- add altitude TODO: speed constraints here -->
<set name="ap/altitude_setpoint" type="value" value="1800"/>
<!-- leg stuff here (not yet used)-->
<!--
<set name="guidance/leg/wp1/latitude-rad"  type="value" value="0.65512580989562"/>
<set name="guidance/leg/wp1/longitude-rad" type="value" value="-2.132319167287033"/>
<set name="guidance/leg/wp1/altitude-ft" type="value" value="1800"/>
-->
<!-- now, set signal to activate next waypoint -->
<set name="ap/active-waypoint" type="value" value="7"/>
<set name="simulation/notify-trigger" type="value" value="1"/>
<notify>
<property>guidance/wp-distance</property>
<property>ap/altitude_setpoint</property>
</notify>
</event>
<event name="Waypoint:5" continuous="false" persistent="false">
<description>Waypoint #5 </description>
<!-- set up condition to trigger this waypoint -->
<condition logic="AND">
ap/active-waypoint eq 5
guidance/wp-distance lt 1000
</condition>
<!-- waypoint lat:37.503528/lon:-122.096139 -->
<!-- coordinates in radians according to GNCUtilities.xml -->
<set name="guidance/target_wp_latitude_rad" type="value"  value="0.6545600439659401"/>
<set name="guidance/target_wp_longitude_rad" type="value" value="-2.130979627087658"/>
<!-- add altitude TODO: speed constraints here -->
<set name="ap/altitude_setpoint" type="value" value="3000"/>
<!-- leg stuff here (not yet used)-->
<!--
<set name="guidance/leg/wp1/latitude-rad"  type="value" value="0.6545600439659401"/>
<set name="guidance/leg/wp1/longitude-rad" type="value" value="-2.130979627087658"/>
<set name="guidance/leg/wp1/altitude-ft" type="value" value="3000"/>
-->
<!-- now, set signal to activate next waypoint -->
<set name="ap/active-waypoint" type="value" value="6"/>
<set name="simulation/notify-trigger" type="value" value="1"/>
<notify>
<property>guidance/wp-distance</property>
<property>ap/altitude_setpoint</property>
</notify>
</event>
<event name="Waypoint:4" continuous="false" persistent="false">
<description>Waypoint #4 </description>
<!-- set up condition to trigger this waypoint -->
<condition logic="AND">
ap/active-waypoint eq 4
guidance/wp-distance lt 1000
</condition>
<!-- waypoint lat:37.461694/lon:-121.996528 -->
<!-- coordinates in radians according to GNCUtilities.xml -->
<set name="guidance/target_wp_latitude_rad" type="value"  value="0.6538299029274951"/>
<set name="guidance/target_wp_longitude_rad" type="value" value="-2.12924108716844"/>
<!-- add altitude TODO: speed constraints here -->
<set name="ap/altitude_setpoint" type="value" value="4500"/>
<!-- leg stuff here (not yet used)-->
<!--
<set name="guidance/leg/wp1/latitude-rad"  type="value" value="0.6538299029274951"/>
<set name="guidance/leg/wp1/longitude-rad" type="value" value="-2.12924108716844"/>
<set name="guidance/leg/wp1/altitude-ft" type="value" value="4500"/>
-->
<!-- now, set signal to activate next waypoint -->
<set name="ap/active-waypoint" type="value" value="5"/>
<set name="simulation/notify-trigger" type="value" value="1"/>
<notify>
<property>guidance/wp-distance</property>
<property>ap/altitude_setpoint</property>
</notify>
</event>
<event name="Waypoint:3" continuous="false" persistent="false">
<description>Waypoint #3 </description>
<!-- set up condition to trigger this waypoint -->
<condition logic="AND">
ap/active-waypoint eq 3
guidance/wp-distance lt 1000
</condition>
<!-- waypoint lat:37.812167/lon:-121.747083 -->
<!-- coordinates in radians according to GNCUtilities.xml -->
<set name="guidance/target_wp_latitude_rad" type="value"  value="0.6599468107098476"/>
<set name="guidance/target_wp_longitude_rad" type="value" value="-2.124887450620778"/>
<!-- add altitude TODO: speed constraints here -->
<set name="ap/altitude_setpoint" type="value" value="9000"/>
<!-- leg stuff here (not yet used)-->
<!--
<set name="guidance/leg/wp1/latitude-rad"  type="value" value="0.6599468107098476"/>
<set name="guidance/leg/wp1/longitude-rad" type="value" value="-2.124887450620778"/>
<set name="guidance/leg/wp1/altitude-ft" type="value" value="9000"/>
-->
<!-- now, set signal to activate next waypoint -->
<set name="ap/active-waypoint" type="value" value="4"/>
<set name="simulation/notify-trigger" type="value" value="1"/>
<notify>
<property>guidance/wp-distance</property>
<property>ap/altitude_setpoint</property>
</notify>
</event>
<event name="Waypoint:2" continuous="false" persistent="false">
<description>Waypoint #2 </description>
<!-- set up condition to trigger this waypoint -->
<condition logic="AND">
ap/active-waypoint eq 2
guidance/wp-distance lt 1000
</condition>
<!-- waypoint lat:37.548436/lon:-122.083878 -->
<!-- coordinates in radians according to GNCUtilities.xml -->
<set name="guidance/target_wp_latitude_rad" type="value"  value="0.65534383642553"/>
<set name="guidance/target_wp_longitude_rad" type="value" value="-2.130765632268315"/>
<!-- add altitude TODO: speed constraints here -->
<set name="ap/altitude_setpoint" type="value" value="7500"/>
<!-- leg stuff here (not yet used)-->
<!--
<set name="guidance/leg/wp1/latitude-rad"  type="value" value="0.65534383642553"/>
<set name="guidance/leg/wp1/longitude-rad" type="value" value="-2.130765632268315"/>
<set name="guidance/leg/wp1/altitude-ft" type="value" value="7500"/>
-->
<!-- now, set signal to activate next waypoint -->
<set name="ap/active-waypoint" type="value" value="3"/>
<set name="simulation/notify-trigger" type="value" value="1"/>
<notify>
<property>guidance/wp-distance</property>
<property>ap/altitude_setpoint</property>
</notify>
</event>
<event name="Waypoint:1" continuous="false" persistent="false">
<description>Waypoint #1 </description>
<!-- set up condition to trigger this waypoint -->
<condition logic="AND">
ap/active-waypoint eq 1
guidance/wp-distance lt 1000
</condition>
<!-- waypoint lat:37.62084548290601/lon:-122.3810480192308 -->
<!-- coordinates in radians according to GNCUtilities.xml -->
<set name="guidance/target_wp_latitude_rad" type="value"  value="0.6566076203104624"/>
<set name="guidance/target_wp_longitude_rad" type="value" value="-2.13595222753618"/>
<!-- add altitude TODO: speed constraints here -->
<set name="ap/altitude_setpoint" type="value" value="4000"/>
<!-- leg stuff here (not yet used)-->
<!--
<set name="guidance/leg/wp1/latitude-rad"  type="value" value="0.6566076203104624"/>
<set name="guidance/leg/wp1/longitude-rad" type="value" value="-2.13595222753618"/>
<set name="guidance/leg/wp1/altitude-ft" type="value" value="4000"/>
-->
<!-- now, set signal to activate next waypoint -->
<set name="ap/active-waypoint" type="value" value="2"/>
<set name="simulation/notify-trigger" type="value" value="1"/>
<notify>
<property>guidance/wp-distance</property>
<property>ap/altitude_setpoint</property>
</notify>
</event>
<!--end of waypoints/events -->
  </run>
</runscript>
</syntaxhighlight>


=== Adding new Functions ===
=== Adding new Functions ===

Navigation menu