Board index FlightGear Development Spaceflight

Space Shuttle - Mission File and Modding

Discussion about development and usage of spacecraft

Space Shuttle - Mission File and Modding

Postby GinGin » Tue Aug 20, 2019 3:43 pm

A post to share our Mission File and Modifications to some files like Trajectory, AP etc
A kind of I loaded parameters post mission specific :)

Don't forget to save the files before you touch anything of course


1) ISS Rendez Vous mission File


A mission file that will give you a good launch window for ISS.
Auto Launch activated, 125 seconds after start of simulation to reach ISS with a Relative Inclination around 0.1 ° max. You need to hurry up for APU activations ;)
Also in the mission file some DAP deadbands closer to reality ( wider and less RCS consuming)
And some Stage 2 lofting to have a Shallower second stage path than original one.


Image


Code: Select all
<?xml version="1.0" ?>

<PropertyList>

<configuration>
  <section-defined type="bool">false</section-defined>
  <external-tank type="string">standard weight</external-tank>
  <payload-explicit type="bool">false</payload-explicit>
  <payload type="string">TDRS demo</payload>
  <payload-weight-lbs>5000.0</payload-weight-lbs>
  <oms-kit type="string">false</oms-kit>
</configuration>

<launch>
  <section-defined type="bool">true</section-defined>
  <target-inclination type="double">51.0</target-inclination>
  <target-apoapsis-miles type="double">120.0</target-apoapsis-miles>
  <select-north type="bool">true</select-north>
  <tal-site-index type="int">7</tal-site-index>
  <rtls-site-index type="int">1</rtls-site-index>
  <roll-to-heads-up type="bool">false</roll-to-heads-up>
  <throttle-down-time-s type="double">28.0</throttle-down-time-s>
  <throttle-up-time-s type="double">62.0</throttle-up-time-s>
  <throttle-down-to-percent type="double">69.0</throttle-down-to-percent>
  <oms-assist-burn type="bool">false</oms-assist-burn>
  <oms-assist-duration-s type="double">0.0</oms-assist-duration-s>
  <srb-climbout-ang-bias-deg type="double">-4.0</srb-climbout-ang-bias-deg>
  <ballistic-climb-ang-bias-deg type="double">-4.0</ballistic-climb-ang-bias-deg>
  <trajectory-loft-ft type="double">-40000.0</trajectory-loft-ft>
  <inclination-targeting type="int">1</inclination-targeting>
</launch>

<countdown>
   <section-defined type="bool">true</section-defined>
   <ignition-time-s type="double">115.0</ignition-time-s>
   <automatic-ignition type="bool">true</automatic-ignition>
</countdown>

<abort>
  <section-defined type="bool">true</section-defined>
  <enable-yaw-steering type="bool">true</enable-yaw-steering>
  <yaw-steering-target type="double">45.0</yaw-steering-target>
  <ato-v-mssn-cntn type="double">12000.0</ato-v-mssn-cntn>
  <ato-v-lin type="double">11500.0</ato-v-lin>
  <ato-v-zero type="double">18000.0</ato-v-zero>
</abort>

<post-meco>
  <section-defined type="bool">true</section-defined>
  <automatic-fuel-dump type="bool">true</automatic-fuel-dump>
  <auto-oms1-burn type="bool">false</auto-oms1-burn>
  <auto-oms1-burn-peg4 type="bool">false</auto-oms1-burn-peg4>
  <oms1-dvx type="double">80.0</oms1-dvx>
  <oms1-dvy type="double">0.0</oms1-dvy>
  <oms1-dvz type="double">0.0</oms1-dvz>
  <oms1-theta-T type="double">207.0</oms1-theta-T>
  <oms1-H type="double">185.0</oms1-H>
  <oms1-tig-s type="double">690.0</oms1-tig-s>
  <orbiter-weight type="double">411468.0</orbiter-weight>
</post-meco>


<dap>
  <section-defined type="bool">true</section-defined>
  <dap-A-PRI-rot-rate type="double">2.0</dap-A-PRI-rot-rate>
  <dap-B-PRI-rot-rate type="double">0.5</dap-B-PRI-rot-rate>
  <dap-A-VRN-rot-rate type="double">0.1</dap-A-VRN-rot-rate>
  <dap-B-VRN-rot-rate type="double">0.05</dap-B-VRN-rot-rate>
  <dap-A-PRI-att-db type="double">0.05</dap-A-PRI-att-db>
  <dap-B-PRI-att-db type="double">0.10</dap-B-PRI-att-db>
  <dap-A-VRN-att-db type="double">0.12</dap-A-VRN-att-db>
  <dap-B-VRN-att-db type="double">0.15</dap-B-VRN-att-db>
  <dap-A-PRI-rate-db type="double">0.07</dap-A-PRI-rate-db>
  <dap-B-PRI-rate-db type="double">0.1</dap-B-PRI-rate-db>
  <dap-A-VRN-rate-db type="double">0.001</dap-A-VRN-rate-db>
  <dap-B-VRN-rate-db type="double">0.005</dap-B-VRN-rate-db>
  <dap-A-ALT-rate-db type="double">0.2</dap-A-ALT-rate-db>
  <dap-B-ALT-rate-db type="double">0.2</dap-B-ALT-rate-db>
  <dap-A-PRI-rot-pls type="double">0.1</dap-A-PRI-rot-pls>
  <dap-B-PRI-rot-pls type="double">0.05</dap-B-PRI-rot-pls>
  <dap-A-VRN-rot-pls type="double">0.01</dap-A-VRN-rot-pls>
  <dap-B-VRN-rot-pls type="double">0.002</dap-B-VRN-rot-pls>
  <dap-A-PRI-comp type="double">0.0</dap-A-PRI-comp>
  <dap-B-PRI-comp type="double">0.0</dap-B-PRI-comp>
  <dap-A-VRN-comp type="double">0.0</dap-A-VRN-comp>
  <dap-B-VRN-comp type="double">0.0</dap-B-VRN-comp>
  <dap-A-PRI-p-opt type="int">0</dap-A-PRI-p-opt>
  <dap-B-PRI-p-opt type="int">0</dap-B-PRI-p-opt>
  <dap-A-PRI-y-opt type="int">0</dap-A-PRI-y-opt>
  <dap-B-PRI-y-opt type="int">0</dap-B-PRI-y-opt>
  <dap-A-PRI-tran-pls type="double">0.100</dap-A-PRI-tran-pls>
  <dap-B-PRI-tran-pls type="double">0.100</dap-B-PRI-tran-pls>
  <dap-A-ALT-n-jets type="int">3</dap-A-ALT-n-jets>
  <dap-B-ALT-n-jets type="int">3</dap-B-ALT-n-jets>
</dap>

<entry>
  <section-defined type="bool">true</section-defined>
  <landing-site-index type="int">1</landing-site-index>
</entry>


<failures>
  <section-defined type="bool">false</section-defined>

  <mode n="0">
  <node  type="string">/fdm/jsbsim/systems/failures/mps/ssme1-condition</node>
  <occurs-met-s  type="double">135.0</occurs-met-s>
  <probability  type="double">1.0</probability>
  <value  type="double">0.0</value>
  </mode>

  <mode n="1">
  <node  type="string">/fdm/jsbsim/systems/failures/mps/ssme2-condition</node>
  <occurs-met-s  type="double">130.0</occurs-met-s>
  <probability  type="double">0.0</probability>
  <value  type="double">0.0</value>
  </mode>
</failures>

<orbital-targets>
  <section-defined type="bool">true</section-defined>
  <object-label type="string">ISS</object-label>
  <inclination-deg type="double">51.0</inclination-deg>
  <alt-km type="double">340.0</alt-km>
  <node-lon-deg type="double">255.40</node-lon-deg>
  <anomaly-deg type="double">25.</anomaly-deg>
</orbital-targets>

<rms-auto-sequences>
  <section-defined type="bool">true</section-defined>
  <num-sequences type="int">1</num-sequences>
  <sequence>
   <num-points type="int">4</num-points>
   <point>
      <x type="double">12.0</x>
      <y type="double">2.0</y>
      <z type="double">0.0</z>
      <pitch type="double">0.0</pitch>
      <yaw type="double">0.0</yaw>
      <roll type="double">0.0</roll>
      <delay type="double">0.0</delay>
   </point>
   <point n="1">
      <x type="double">10.0</x>
      <y type="double">2.0</y>
      <z type="double">0.0</z>
      <pitch type="double">0.0</pitch>
      <yaw type="double">0.0</yaw>
      <roll type="double">0.0</roll>
      <delay type="double">0.0</delay>
   </point>
   <point n="2">
      <x type="double">10.0</x>
      <y type="double">2.0</y>
      <z type="double">0.0</z>
      <pitch type="double">3.0</pitch>
      <yaw type="double">0.0</yaw>
      <roll type="double">0.0</roll>
      <delay type="double">0.0</delay>
   </point>
   <point n="3">
      <x type="double">13.0</x>
      <y type="double">1.0</y>
      <z type="double">0.0</z>
      <pitch type="double">0.0</pitch>
      <yaw type="double">0.0</yaw>
      <roll type="double">0.0</roll>
      <delay type="double">0.0</delay>
   </point>
  </sequence>
</rms-auto-sequences>

</PropertyList>






2) Throttle modification : 104 % Nominal



A quick modification of Throttle.xml located in SpaceShuttle/Systems/Throttle.xml
It will give 104 % nominally instead of 100 % ( it was the case after the first few test flights)

Copy/Paste and overwrite in Throttle.xml

Code: Select all
<?xml version="1.0"?>

<system>

   <channel name="Throttle mapping">

      <!-- main engine throttle is mapped from 65% to (up to) 109% of rated power -->

      <switch name="systems/throttle/throttle-factor">
         <default value="1.0"/>
         <test value="1.09">
            systems/throttle/throttle-mode == 1   
         </test>
         <test value="1.06">
            systems/throttle/throttle-mode == 2   
         </test>
         <test  value="1.04">
            systems/throttle/throttle-mode == 3   
         </test>
      </switch>

      <fcs_function name="systems/throttle/ssme1-throttle-norm">
      <function>
         <product>
            <sum>
               <value>0.65</value>
               <product>
                  <property>fcs/throttle-pos-norm[0]</property>
                  <value>0.35</value>
               </product>
            </sum>            
            <property>systems/throttle/throttle-factor</property>
         </product>
      </function>
      <output>fcs/throttle-pos-norm[0]</output>
      </fcs_function>

      <fcs_function name="systems/throttle/ssme2-throttle-norm">
      <function>
         <product>
            <sum>
               <value>0.65</value>
               <product>
                  <property>fcs/throttle-pos-norm[1]</property>
                  <value>0.35</value>
               </product>
            </sum>   
            <property>systems/throttle/throttle-factor</property>
         </product>
      </function>
      <output>fcs/throttle-pos-norm[1]</output>
      </fcs_function>

      <fcs_function name="systems/throttle/ssme3-throttle-norm">
      <function>
         <product>
            <sum>
               <value>0.65</value>
               <product>
                  <property>fcs/throttle-pos-norm[2]</property>
                  <value>0.35</value>
               </product>
            </sum>   
            <property>systems/throttle/throttle-factor</property>
         </product>
      </function>
      <output>fcs/throttle-pos-norm[2]</output>
      </fcs_function>


   </channel>
</system>





3) Shuttle Basic Weight changes

A quick change to the equipment weight in SpaceShuttle/Shuttle.xml Line 63
You can put it from 40000 to 5000 pounds to have a more realistic weight in Orbit ( it now takes account of just the cryogenic stuff, O2 H2 etc)
After many tests, it is closer to real weight datas and without impact on the Shuttle Code

Image






4)Ascent Auto Pilot

Some changes to first stage and second stage AP to have a shallower path and closer to reality data ( closer to how shuttle was flown during latest flights)
It will give also some bigger margin regarding wing bending moments with an angle of attack below -2 ° during Max Q bar

You have for that to copy paste and Overwrite the auto launch.nas located in SpaceShuttle/Nasal
It is recommended to use the three first point for optimal profile ( Iss mission file, throttle 104 % at least)
Profile will be close to that:

Image


Code: Select all
# auto launch guidance for the Space Shuttle
# Thorsten Renk 2016


var auto_launch_stage = 0;
var auto_launch_timer = 0.0;
var aux_flag = 0;

var auto_launch_throttle_down = 18.0;
var auto_launch_throttle_up = 42.0;
var auto_launch_throttle_to = 0.0;

var auto_launch_traj_loft = 0.0;
var auto_launch_mps_climbout_bias = 0.0;
var auto_launch_srb_climbout_bias = 0.0;

var xtrack_refloc = geo.Coord.new();
xtrack_refloc.last_xtrack = 0.0;
xtrack_refloc.correction = 0.0;


xtrack_refloc.approach_speed = 0.0;
xtrack_refloc.last_app_speed = 0.0;
xtrack_refloc.buffer = 0.0;

var auto_launch_loop = func {

var shuttle_pos = geo.aircraft_position();

#var actual_course = SpaceShuttle.peg4_refloc.course_to(shuttle_pos);
#var dist = SpaceShuttle.peg4_refloc.distance_to(shuttle_pos);

var actual_course = SpaceShuttle.xtrack_refloc.course_to(shuttle_pos);
var dist = SpaceShuttle.xtrack_refloc.distance_to(shuttle_pos);

var launch_azimuth = getprop("/fdm/jsbsim/systems/ap/launch/launch-azimuth");

var xtrack = SpaceShuttle.sgeo_crosstrack(actual_course, launch_azimuth, dist)  * 0.0005399568;

# compute speed by a running average

xtrack_refloc.approach_speed = (xtrack_refloc.last_xtrack - xtrack)/ 0.1; # using loop time constant
xtrack_refloc.buffer = (xtrack_refloc.approach_speed + xtrack_refloc.last_app_speed)/2.0;
xtrack_refloc.last_app_speed = xtrack_refloc.approach_speed;
xtrack_refloc.approach_speed = xtrack_refloc.buffer;



xtrack_refloc.last_xtrack = xtrack;


setprop("/fdm/jsbsim/systems/ap/launch/cross-track", xtrack);
setprop("/fdm/jsbsim/systems/ap/launch/cross-track-approach-speed", xtrack_refloc.approach_speed);

if (auto_launch_stage == 0)
   {
   # check for clear gantry, then initiate rotation to launch course
   
   if (getprop("/fdm/jsbsim/velocities/vtrue-fps") > 120.0)
      {
      auto_launch_stage = 1;
      setprop("/fdm/jsbsim/systems/ap/launch/stage", 1);
      aux_flag = 0;
      }
   }
else if (auto_launch_stage == 1)
   {

   # enable throttling already during rotation to azimuth

   #print ("Auto launch timer: ", auto_launch_timer);

   if ((auto_launch_timer > auto_launch_throttle_down) and (auto_launch_timer < auto_launch_throttle_up))
      {
      if (aux_flag == 0)
         {
         if (getprop("/fdm/jsbsim/systems/ap/automatic-sb-control") == 1)
            {
            if (SpaceShuttle.failure_cmd.ssme1 == 1)
               {setprop("/controls/engines/engine[0]/throttle", auto_launch_throttle_to);}
            if (SpaceShuttle.failure_cmd.ssme2 == 1)
               {setprop("/controls/engines/engine[1]/throttle", auto_launch_throttle_to);}
            if (SpaceShuttle.failure_cmd.ssme3 == 1)
               {setprop("/controls/engines/engine[2]/throttle", auto_launch_throttle_to);}
            }
         aux_flag = 1;
         }
      # throttle up if we lose an engine

      if (getprop("/fdm/jsbsim/systems/mps/number-engines-operational") < 3.0)
         {
         if (getprop("/fdm/jsbsim/systems/ap/automatic-sb-control") == 1)
            {
            if (SpaceShuttle.failure_cmd.ssme1 == 1)
               {setprop("/controls/engines/engine[0]/throttle", 1.0);}
            if (SpaceShuttle.failure_cmd.ssme2 == 1)
               {setprop("/controls/engines/engine[1]/throttle", 1.0);}
            if (SpaceShuttle.failure_cmd.ssme3 == 1)
               {setprop("/controls/engines/engine[2]/throttle", 1.0);}
            }
         }

      }
   else if (auto_launch_timer > auto_launch_throttle_up)
      {
      if (aux_flag == 1)
         {
      
         if (getprop("/fdm/jsbsim/systems/ap/automatic-sb-control") == 1)
            {
            if (SpaceShuttle.failure_cmd.ssme1 == 1)         
               {setprop("/controls/engines/engine[0]/throttle", 1.0);}
            if (SpaceShuttle.failure_cmd.ssme2 == 1)         
               {setprop("/controls/engines/engine[1]/throttle", 1.0);}
            if (SpaceShuttle.failure_cmd.ssme3 == 1)         
               {setprop("/controls/engines/engine[2]/throttle", 1.0);}
            }
         aux_flag = 2;
         }
      }


   # check for launch course reached, then initiate pitch down assuming we're high enough

   if (math.abs(getprop("/fdm/jsbsim/systems/ap/launch/stage1-course-error")) < 0.1)
      {
      auto_launch_stage = 2;
      setprop("/fdm/jsbsim/systems/ap/launch/stage", 2);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 70.0);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.25);
      aux_flag = 0;
      }

   

   }
else if (auto_launch_stage == 2)
   {

   if ((auto_launch_timer > auto_launch_throttle_down) and (auto_launch_timer < auto_launch_throttle_up))
      {
      if (aux_flag == 0)
         {
         if (getprop("/fdm/jsbsim/systems/ap/automatic-sb-control") == 1)
            {
            if (SpaceShuttle.failure_cmd.ssme1 == 1)
               {setprop("/controls/engines/engine[0]/throttle", auto_launch_throttle_to);}
            if (SpaceShuttle.failure_cmd.ssme2 == 1)
               {setprop("/controls/engines/engine[1]/throttle", auto_launch_throttle_to);}
            if (SpaceShuttle.failure_cmd.ssme3 == 1)
               {setprop("/controls/engines/engine[2]/throttle", auto_launch_throttle_to);}
            }
         aux_flag = 1;
         }
      # throttle up if we lose an engine

      if (getprop("/fdm/jsbsim/systems/mps/number-engines-operational") < 3.0)
         {
         if (getprop("/fdm/jsbsim/systems/ap/automatic-sb-control") == 1)
            {
            if (SpaceShuttle.failure_cmd.ssme1 == 1)
               {setprop("/controls/engines/engine[0]/throttle", 1.0);}
            if (SpaceShuttle.failure_cmd.ssme2 == 1)
               {setprop("/controls/engines/engine[1]/throttle", 1.0);}
            if (SpaceShuttle.failure_cmd.ssme3 == 1)
               {setprop("/controls/engines/engine[2]/throttle", 1.0);}
            }
         }

      }
   else if (auto_launch_timer > auto_launch_throttle_up)
      {
      if (aux_flag == 1)
         {
      
         if (getprop("/fdm/jsbsim/systems/ap/automatic-sb-control") == 1)
            {
            if (SpaceShuttle.failure_cmd.ssme1 == 1)         
               {setprop("/controls/engines/engine[0]/throttle", 1.0);}
            if (SpaceShuttle.failure_cmd.ssme2 == 1)         
               {setprop("/controls/engines/engine[1]/throttle", 1.0);}
            if (SpaceShuttle.failure_cmd.ssme3 == 1)         
               {setprop("/controls/engines/engine[2]/throttle", 1.0);}
            }
         aux_flag = 2;
         }
      }

   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 571.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 69.4);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.04);
      }

   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 678.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 68.6);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.04);
      }
      
    if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 747.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 67.8);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.04);
      }
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 846.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 66.2);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.04);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 932.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 64.4);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.04);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 1068.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 62.1);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.04);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 1149.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 61.1);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.04);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 1304.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 59.0);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.06);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 1382.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 58.2);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.06);
      }

   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 1463.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 57.8);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.06);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 1550.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 57.1);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.06);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 1693.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 54.7);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.06);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 1797.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 52.9);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.06);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 2027.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 48.7);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.06);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 2154.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 46.4);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.06);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 2286))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 43.0);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.06);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 2353.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 42.0);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.06);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 2421.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 41.6);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.06);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 2746.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 38.6);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.06);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 3019.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 36.3);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.06);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 3157.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 35.3);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.06);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 3350.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 33.9);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.06);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 3573.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 32.4);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.06);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 3950.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 29.8);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.1);
      }   
      
   if ((getprop("/fdm/jsbsim/velocities/vtrue-fps") > 5000.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 22.6);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.1);
      }   
      
   if ((getprop("/controls/shuttle/SRB-static-model") == 0) and (getprop("/fdm/jsbsim/systems/failures/shuttle-destroyed") == 0))
      {
      auto_launch_stage = 3;
   
      meco_time.init(26000.0);   

      setprop("/fdm/jsbsim/systems/ap/launch/stage", 3);
      var payload_factor = getprop("/fdm/jsbsim/inertia/pointmass-weight-lbs[5]") /53700.00;
      payload_factor =  payload_factor +  (getprop("/fdm/jsbsim/inertia/pointmass-weight-lbs[1]") - 29250.0) / 26850.00;
      
      # OMS kit
      payload_factor = payload_factor + getprop("/fdm/jsbsim/propulsion/tank[27]/contents-lbs")/53700.0;
      payload_factor = payload_factor + getprop("/fdm/jsbsim/propulsion/tank[26]/contents-lbs")/53700.0;

      var throttle_factor = 10.0 * (getprop("/fdm/jsbsim/systems/throttle/throttle-factor") - 1.0);

      var lat = getprop("/position/latitude-deg") * math.pi/180.0;
      var heading = getprop("/orientation/heading-deg") * math.pi/180.0;
      var geo_factor = math.sin(heading) * math.cos(lat);


      var v_up_tgt = 920.0 + auto_launch_srb_climbout_bias * 8.0;

      var delta_vspeed = (v_up_tgt - 42.0 * payload_factor) + 0.3048 * getprop("/fdm/jsbsim/velocities/v-down-fps");

      var delta_alt = delta_vspeed * 895.0;
      var loft_factor = delta_alt / 7000.0;

      if (loft_factor > 5.0) {loft_factor = 5.0;}
      if (loft_factor < -2.0) {loft_factor = -2.0;}

      var pitch_target = 5.0 + 5.0 * payload_factor + 4.0 - 6.0 * geo_factor - 8.0 * throttle_factor + auto_launch_mps_climbout_bias + loft_factor;

      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", pitch_target);

      # fire an OMS assist burn if requested


      if (getprop("/fdm/jsbsim/systems/ap/launch/oms-assist-burn") == 1)
         {

         var oms_assist_time = getprop("/fdm/jsbsim/systems/ap/launch/oms-assist-duration-s");

         settimer ( func {

            setprop("/controls/engines/engine[5]/throttle", 1.0);
            setprop("/controls/engines/engine[6]/throttle", 1.0);

            }, 10.0 );
         

         settimer ( func {

             if (getprop("/fdm/jsbsim/systems/oms/oms-dump-cmd") == 1) {return;}

            setprop("/controls/engines/engine[5]/throttle", 0.0);
            setprop("/controls/engines/engine[6]/throttle", 0.0);

            }, 10.0 + oms_assist_time );
         }


      aux_flag = 0;
      }

   }
else if (auto_launch_stage == 3)
   {

   var guidance = getprop("/fdm/jsbsim/systems/entry_guidance/guidance-mode");

   if (guidance == 2) # TAL abort requires different guidance after SRB sep
      {
      print ("TAL abort declared, switching to TAL guidance...");
      auto_TAL_init();
      return;
      }

   meco_time.run();

   var alt = getprop("/position/altitude-ft");


   if (alt > 400000.0 + auto_launch_traj_loft) # we're getting too high and need to pitch down
      {
      var payload_factor = getprop("/fdm/jsbsim/inertia/pointmass-weight-lbs[5]") /53700.00;
      payload_factor =  payload_factor +  (getprop("/fdm/jsbsim/inertia/pointmass-weight-lbs[1]") - 29250.0) / 26850.00;
      # OMS kit
      payload_factor = payload_factor + getprop("/fdm/jsbsim/propulsion/tank[27]/contents-lbs")/53700.0;
      payload_factor = payload_factor + getprop("/fdm/jsbsim/propulsion/tank[26]/contents-lbs")/53700.0;

      var lat = getprop("/position/latitude-deg") * math.pi/180.0;
      var heading = getprop("/orientation/heading-deg") * math.pi/180.0;
      var geo_factor = math.sin(heading) * math.cos(lat);

      var pitch_target = 5.0 + 5.0 * payload_factor + 4.0 - 6.0 * geo_factor;

      var pitch_corr = (alt - 400000 - auto_launch_traj_loft)/1000.0;

      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", pitch_target - pitch_corr);
      aux_flag = 2;
      }


   if ((getprop("/fdm/jsbsim/velocities/v-down-fps") > -300.0) and (aux_flag == 0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 10.0);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.1);
      aux_flag = 1;
      }
   else if ((getprop("/fdm/jsbsim/velocities/v-down-fps") > -100.0) and (aux_flag == 1))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", 10.0);
      aux_flag = 2;
      }
   else if ((getprop("/fdm/jsbsim/velocities/v-down-fps") >  20.0) and (aux_flag == 2))
      {
      auto_launch_stage = 4;
      setprop("/fdm/jsbsim/systems/ap/launch/stage", 4);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.05);
      setprop("/fdm/jsbsim/systems/ap/launch/hdot-target", 0.0);
      droop_guidance.init();
      aux_flag = 0;
      }   
   
   }
else if (auto_launch_stage == 4)
   {

   # if we're off the trajectory too much, try to steer back to it

   var alt = getprop("/position/altitude-ft");
   var mach = getprop("/fdm/jsbsim/velocities/mach");

   droop_guidance.run (alt);
   meco_time.run();

   if ((alt < 420000.0 + auto_launch_traj_loft) and (mach < 23.0))
      {
      var hdot_tgt = 50.0 - (420000.0 - alt)/150.0;
      setprop("/fdm/jsbsim/systems/ap/launch/hdot-target", hdot_tgt);
      }
   else if ((alt > 470000.0 + auto_launch_traj_loft) and (mach < 23.0))
      {
      var hdot_tgt = 50.0 + (alt - 470000.0)/150.0;
      setprop("/fdm/jsbsim/systems/ap/launch/hdot-target", hdot_tgt);
      }


   # dynamically throttle back when we reach acceleration limit
   
   if (getprop("/fdm/jsbsim/accelerations/n-pilot-x-norm") > 2.85)
      {

      SpaceShuttle.meco_time.set_mode(1);

      # an engine can be in electric lockup, so we may need to look at more engines
      # to determine current throttle value

      var current_throttle = 1;

      if (SpaceShuttle.failure_cmd.ssme1 == 1)
         {current_throttle = getprop("/controls/engines/engine[0]/throttle");}
      else if (SpaceShuttle.failure_cmd.ssme2 == 1)
         {current_throttle = getprop("/controls/engines/engine[1]/throttle");}
      else
         {current_throttle = getprop("/controls/engines/engine[2]/throttle");}

      var new_throttle = current_throttle * 0.99;

      #if (new_throttle < 0.61) {new_throttle = 0.61;}

      if (getprop("/fdm/jsbsim/systems/ap/automatic-sb-control") == 1)
         {
         if (SpaceShuttle.failure_cmd.ssme1 == 1)
            {setprop("/controls/engines/engine[0]/throttle", new_throttle);}
         if (SpaceShuttle.failure_cmd.ssme2 == 1)
            {setprop("/controls/engines/engine[1]/throttle", new_throttle);}
         if (SpaceShuttle.failure_cmd.ssme3 == 1)
            {setprop("/controls/engines/engine[2]/throttle", new_throttle);}
         }

      }


   # automatic roll to heads up attitude

   if ((aux_flag == 0) and (mach > 13.0))
      {
      if ((getprop("/fdm/jsbsim/systems/ap/launch/rthu-enable") == 1) and (getprop("/fdm/jsbsim/systems/fcs/control-mode") != 13))
         {
         var inc_acquire_sign = getprop("/fdm/jsbsim/systems/ap/launch/inc-acquire-sign");
         setprop("/fdm/jsbsim/systems/ap/launch/inc-acquire-sign", -inc_acquire_sign);

         setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.07);
         setprop("/fdm/jsbsim/systems/ap/launch/rthu-cmd", 1);
         }
      aux_flag = 1;
      }
   else if ((aux_flag == 1) and (getprop("/fdm/jsbsim/systems/ap/launch/stage4-rthu-in-in-progress") == 0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.1);
      aux_flag = 2;
      }


   # change hdot target to 200 prior to MECO 

   if ((aux_flag == 2) and (mach > 23.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/hdot-target", 150.0);
      aux_flag = 1;
      }

   # increase pitch maneuverability as centrifugal force builds up

   if ((aux_flag == 3) and (getprop("/fdm/jsbsim/systems/orbital/periapsis-km") > -500.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.15);
      aux_flag = 2;
      }


   # null all rates prior to MECO

   if ((aux_flag == 4) and (getprop("/fdm/jsbsim/systems/orbital/periapsis-km") > 0.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/stage", 5);
      aux_flag = 5;
      }



   # MECO if apoapsis target is met

   if (getprop("/fdm/jsbsim/systems/orbital/apoapsis-km") > getprop("/fdm/jsbsim/systems/ap/launch/apoapsis-target"))
      {

      SpaceShuttle.meco_time.set_mode(2);

      if (getprop("/fdm/jsbsim/systems/ap/automatic-sb-control") == 1)
         {   
         if (SpaceShuttle.failure_cmd.ssme1 == 1)
            {setprop("/controls/engines/engine[0]/throttle", 0.0);}
         if (SpaceShuttle.failure_cmd.ssme2 == 1)
            {setprop("/controls/engines/engine[1]/throttle", 0.0);}
         if (SpaceShuttle.failure_cmd.ssme3 == 1)
            {setprop("/controls/engines/engine[2]/throttle", 0.0);}

             setprop("/fdm/jsbsim/systems/mps/engine[0]/run-cmd", 0);
             setprop("/fdm/jsbsim/systems/mps/engine[1]/run-cmd", 0);
             setprop("/fdm/jsbsim/systems/mps/engine[2]/run-cmd", 0);

         }

      setprop("/fdm/jsbsim/systems/ap/launch/regular-meco-condition",1);





      print ("MECO - auto-launch guidance signing off!");
      print ("Thank you for flying with us!");

      # use RCS to null residual rates, disengage launch AP

      settimer( func {
         setprop("/fdm/jsbsim/systems/fcs/control-mode",20);
         controls.centerFlightControls();

         setprop("/fdm/jsbsim/systems/ap/css-pitch-control", 1);
         setprop("/fdm/jsbsim/systems/ap/automatic-pitch-control", 0);   
         setprop("/fdm/jsbsim/systems/ap/css-roll-control", 1);
         setprop("/fdm/jsbsim/systems/ap/automatic-roll-control", 0);


         }, 2.0);
      
      # prepare ETsep and MM 104 transition

      settimer( func {
         setprop("/fdm/jsbsim/systems/dps/major-mode", 104);
         SpaceShuttle.dk_listen_major_mode_transition(104);
         SpaceShuttle.ops_transition_auto("p_dps_mnvr");
         }, 23.0);

      settimer( func {
         external_tank_separate();
         mission_auto_OMS1();

         }, 20.0);

      # start main orbital loop
      orbital_loop_init();

      SpaceShuttle.mission_post_meco();   

      return;
      }

   }


auto_launch_timer = auto_launch_timer + 0.1;


settimer(auto_launch_loop, 0.1);

}


var auto_TAL_init = func {

if (auto_launch_stage == 3)
   {
   # we need to pitch up more on the ballistic climb to get into a good trajectory

   var lat = getprop("/position/latitude-deg") * math.pi/180.0;
   var heading = getprop("/orientation/heading-deg") * math.pi/180.0;

   var payload_factor = getprop("/fdm/jsbsim/inertia/pointmass-weight-lbs[5]") /53700.00;
   payload_factor =  payload_factor +  (getprop("/fdm/jsbsim/inertia/pointmass-weight-lbs[1]") - 29250.0) / 26850.00;
   # OMS kit
   payload_factor = payload_factor + getprop("/fdm/jsbsim/propulsion/tank[27]/contents-lbs")/53700.0;
   payload_factor = payload_factor + getprop("/fdm/jsbsim/propulsion/tank[26]/contents-lbs")/53700.0;

   var geo_factor = math.sin(heading) * math.cos(lat);

   # during the ballistic ascent, pitch target depends on number of good engines
   # to allow 3 engine TAL

   var pitch_tgt = 35.0 + 12.0 * payload_factor + 12.0 - 15.0 * geo_factor;

   var num_engines = getprop("/fdm/jsbsim/systems/mps/number-engines-operational");
   if (num_engines == 3)
      {pitch_tgt = 5.0 + 5.0 * payload_factor + 4.0 - 6.0 * geo_factor;}

   setprop("/fdm/jsbsim/systems/ap/launch/pitch-target",pitch_tgt) ;

   }

auto_TAL_loop();

}



var auto_TAL_loop = func {


var abort_mode = getprop("/fdm/jsbsim/systems/abort/abort-mode");

if (abort_mode > 4) # a contingency abort has been called
   {return;}

if (auto_launch_stage == 3)
   {

   var shuttle_pos = geo.aircraft_position();
   
   var course_tgt = shuttle_pos.course_to (SpaceShuttle.landing_site);
   setprop("/fdm/jsbsim/systems/ap/launch/course-target", course_tgt);


   # compute MECO target
   # ballistic impact range approx. range to site

   var a = getprop("/fdm/jsbsim/systems/orbital/semimajor-axis-length-ft");
   var epsilon = getprop("/fdm/jsbsim/systems/orbital/epsilon");
   var R = getprop("/position/sea-level-radius-ft");
   
   var A = -a*a * epsilon * epsilon;
   var B = -2.0 * a * a * a * epsilon;
   var C = a*a * (R*R - a*a );

   var x = 1.0/(2.0 * A) * (-B - math.sqrt(B*B - 4.0 * A * C)) + a * epsilon;
   
   var arg = x/R;

   var dist_ballistic = math.acos(arg) * R * 0.3048;
   var dist = shuttle_pos.distance_to (SpaceShuttle.landing_site);

   setprop("/fdm/jsbsim/systems/ap/launch/distance-ballistic-km", dist_ballistic/1000.0);
   setprop("/fdm/jsbsim/systems/ap/launch/distance-site-km", dist/1000.0);

   # during the ballistic ascent, pitch target depends on number of good engines
   # to allow 3 engine TAL

   var num_engines = getprop("/fdm/jsbsim/systems/mps/number-engines-operational");
   var pitch_tgt = 30.0;
   if (num_engines == 3) {pitch_tgt = 10.0;}

   var alt = getprop("//position/altitude-ft");

   if (alt > 480000.0)
      {
      var pitch_corr = (alt - 480000)/1000.0;
      pitch_tgt = pitch_tgt - pitch_corr;
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", pitch_tgt);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.15);
      aux_flag = 1;
      }


   if (((getprop("/fdm/jsbsim/velocities/v-down-fps") > -500.0) or (alt > 508530.0)) and (aux_flag == 0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-target", pitch_tgt);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.1);
      aux_flag = 1;
      }
   else if ((getprop("/fdm/jsbsim/velocities/v-down-fps") >  120.0) and (aux_flag == 1))
      {
      auto_launch_stage = 4;
      setprop("/fdm/jsbsim/systems/ap/launch/stage", 4);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.1);
      setprop("/fdm/jsbsim/systems/ap/launch/hdot-target", 50.0);
      droop_guidance.init();
      aux_flag = 0;
      }   
   
   }
else if (auto_launch_stage == 4)
   {

   var shuttle_pos = geo.aircraft_position();
   
   var course_tgt = shuttle_pos.course_to (SpaceShuttle.landing_site);
   setprop("/fdm/jsbsim/systems/ap/launch/course-target", course_tgt);

   var alt = getprop("/position/altitude-ft");
   var mach = getprop("/fdm/jsbsim/velocities/mach");
   droop_guidance.run (alt);


   if ((alt < 420000.0) and (mach < 23.0))
      {
      var hdot_tgt = 50.0 - (420000.0 - alt)/150.0;
      setprop("/fdm/jsbsim/systems/ap/launch/hdot-target", hdot_tgt);
      }
   else if ((alt > 470000.0) and (mach < 23.0))
      {
      var hdot_tgt = 50.0 + (alt - 470000.0)/150.0;
      setprop("/fdm/jsbsim/systems/ap/launch/hdot-target", hdot_tgt);
      }

   
   # dynamically throttle back when we reach acceleration limit
   
   if (getprop("/fdm/jsbsim/accelerations/n-pilot-x-norm") > 2.85)
      {


      # an engine can be in electric lockup, so we may need to look at more engines
      # to determine current throttle value

      var current_throttle = 1;

      if (SpaceShuttle.failure_cmd.ssme1 == 1)
         {current_throttle = getprop("/controls/engines/engine[0]/throttle");}
      else if (SpaceShuttle.failure_cmd.ssme2 == 1)
         {current_throttle = getprop("/controls/engines/engine[1]/throttle");}
      else
         {current_throttle = getprop("/controls/engines/engine[2]/throttle");}

      var new_throttle = current_throttle * 0.99;

      #if (new_throttle < 0.61) {new_throttle = 0.61;}

      if (getprop("/fdm/jsbsim/systems/ap/automatic-sb-control") == 1)
         {
         if (SpaceShuttle.failure_cmd.ssme1 == 1)
            {setprop("/controls/engines/engine[0]/throttle", new_throttle);}
         if (SpaceShuttle.failure_cmd.ssme2 == 1)
            {setprop("/controls/engines/engine[1]/throttle", new_throttle);}
         if (SpaceShuttle.failure_cmd.ssme3 == 1)
            {setprop("/controls/engines/engine[2]/throttle", new_throttle);}
         }

      }

   # we need to pitch up briskly, but then reduce sensitivity to avoid oscillations
   # insert a Mach cut in case the TAL init happens late and we never pitch up so much

   if ((aux_flag == 0) and ((mach > 10.0) or (getprop("/orientation/pitch-deg") > 40.0)))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.05);
      aux_flag = 1;
      }

   # automatic roll to heads up attitude

   if ((aux_flag == 1) and (mach > 14.0))
      {
      #if (getprop("/fdm/jsbsim/systems/ap/launch/rthu-enable") == 1)
      if ((getprop("/fdm/jsbsim/systems/ap/launch/rthu-enable") == 1) and (getprop("/fdm/jsbsim/systems/fcs/control-mode") != 13))
         {
         setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.15);
         setprop("/fdm/jsbsim/systems/ap/launch/rthu-cmd", 1);
         }
      aux_flag = 2;
      }
   else if ((aux_flag == 2) and (getprop("/fdm/jsbsim/systems/ap/launch/stage4-rthu-in-in-progress") == 0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.05);
      aux_flag = 3;
      }


   # change hdot target to 0 prior to MECO

   if ((aux_flag == 3) and (mach > 23.0))
      {
      setprop("/fdm/jsbsim/systems/ap/launch/hdot-target", 0.0);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.03);
      aux_flag = 4;
      }

   # compute MECO target
   # ballistic impact range approx. range to site

   var a = getprop("/fdm/jsbsim/systems/orbital/semimajor-axis-length-ft");
   var epsilon = getprop("/fdm/jsbsim/systems/orbital/epsilon");
   var R = getprop("/position/sea-level-radius-ft");
   
   var A = -a*a * epsilon * epsilon;
   var B = -2.0 * a * a * a * epsilon;
   var C = a*a * (R*R - a*a );

   var x = 1.0/(2.0 * A) * (-B - math.sqrt(B*B - 4.0 * A * C)) + a * epsilon;
   
   var arg = SpaceShuttle.clamp(x/R, 0.0, 1.0);

   var dist_ballistic = math.acos(arg) * R * 0.3048;
   var dist = shuttle_pos.distance_to (SpaceShuttle.landing_site);

   setprop("/fdm/jsbsim/systems/ap/launch/ballistic-distance-km", dist_ballistic/1000.0);

   # MECO if apoapsis target is met

   if (dist_ballistic >  (dist - 700000.0))
      {


      if (getprop("/fdm/jsbsim/systems/ap/automatic-sb-control") == 1)
         {   
         if (SpaceShuttle.failure_cmd.ssme1 == 1)
            {setprop("/controls/engines/engine[0]/throttle", 0.0);}
         if (SpaceShuttle.failure_cmd.ssme2 == 1)
            {setprop("/controls/engines/engine[1]/throttle", 0.0);}
         if (SpaceShuttle.failure_cmd.ssme3 == 1)
            {setprop("/controls/engines/engine[2]/throttle", 0.0);}

             setprop("/fdm/jsbsim/systems/mps/engine[0]/run-cmd", 0);
             setprop("/fdm/jsbsim/systems/mps/engine[1]/run-cmd", 0);
             setprop("/fdm/jsbsim/systems/mps/engine[2]/run-cmd", 0);

         }

      setprop("/fdm/jsbsim/systems/ap/launch/regular-meco-condition",1);
      print ("MECO - auto-TAL guidance signing off!");
      print ("Have a good entry and remember to close umbilical doors!");

      # use RCS to null residual rates and disengage launch AP

      settimer( func {
         setprop("/fdm/jsbsim/systems/fcs/control-mode",20);
         controls.centerFlightControls();

         setprop("/fdm/jsbsim/systems/ap/css-pitch-control", 1);
         setprop("/fdm/jsbsim/systems/ap/automatic-pitch-control", 0);   
         setprop("/fdm/jsbsim/systems/ap/css-roll-control", 1);
         setprop("/fdm/jsbsim/systems/ap/automatic-roll-control", 0);

         }, 2.0);

      # prepare ETsep and MM 104 transition

      settimer( external_tank_separate, 20.0);

      settimer( func {
         setprop("/fdm/jsbsim/systems/dps/major-mode", 104);
         SpaceShuttle.dk_listen_major_mode_transition(104);
         SpaceShuttle.ops_transition_auto("p_dps_mnvr");
         }, 23.0);

      # start main orbital loop
      orbital_loop_init();

      SpaceShuttle.mission_post_meco_TAL();   


      return;
      }
   }



auto_launch_timer = auto_launch_timer + 0.1;

settimer(auto_TAL_loop, 0.1);
}



var droop_guidance = {

   droop_alt: 0.0,
   R_sea: 6700000.0,
   pitch_tgt: 74.0,
   pitch_tgt_flown: 74.0,
   pitch_tgt_set: 0,
   active: 0,
   running_engine: -1,

   init: func {

      me.R_sea = getprop("/position/sea-level-radius-ft") * 0.3048;

      me.nd_ref_v_down =  props.globals.getNode("/fdm/jsbsim/velocities/v-down-fps", 1);
      me.nd_ref_v_inrtl = props.globals.getNode("/fdm/jsbsim/velocities/eci-velocity-mag-fps", 1);
      me.nd_ref_thrust1 = props.globals.getNode("/fdm/jsbsim/propulsion/engine[0]/thrust-lbs", 1);
      me.nd_ref_thrust2 = props.globals.getNode("/fdm/jsbsim/propulsion/engine[1]/thrust-lbs", 1);
      me.nd_ref_thrust3 = props.globals.getNode("/fdm/jsbsim/propulsion/engine[2]/thrust-lbs", 1);
      me.nd_ref_mass = props.globals.getNode("/fdm/jsbsim/inertia/weight-lbs", 1);

   },

   engage: func {
      me.active = 1;
      setprop("/fdm/jsbsim/systems/ap/launch/droop-guidance-active", 1);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.15);

      
   },

   disengage: func {
      me.active = 0;
      setprop("/fdm/jsbsim/systems/ap/launch/droop-guidance-active", 0);
      setprop("/fdm/jsbsim/systems/ap/launch/pitch-max-rate-norm", 0.05);
   },


   droop_trajectory : func (t, phi, y0, vy0, vx0, T, R, Delta) {

      var phi_rad = phi * math.pi/180.0;

      var cphi = math.cos(phi_rad);
      var sphi = math.sin(phi_rad);

      var A = 0.5 * (T * sphi - 9.41 + vx0*vx0/R);
      var B = 0.333 * (T/R * vx0 * cphi + 0.5 * Delta * sphi);
      var C = 0.08333 * (T*T/R * cphi * cphi + vx0/R * Delta * cphi);
      var D = 0.05 * (T * Delta / R * math.pow(cphi, 2.0));
      var E = 0.008333 * (Delta * Delta/R * cphi * cphi);

      return y0 + vy0 * t + A* math.pow(t, 2.0) + B * math.pow(t, 3.0) + C * math.pow(t, 4.0) + D * math.pow(t, 5.0) + E * math.pow(t, 6.0);
      },

   run : func (altitude) {

      if (me.pitch_tgt < 35.0)
         {
         #if (me.active == 1) {me.disengage();}
         if (me.active == 0)
            {
            #print ("Droop guidance signing off.");
            return;
            }
         }

      #print ("Pitch tgt: ", me.pitch_tgt);

      if (me.droop_alt > 110000)
         {
         me.pitch_tgt = me.pitch_tgt - 1.0;
         if (me.pitch_tgt_set == 0)
            {
            me.pitch_tgt_flown = me.pitch_tgt;
            }
         }




      var y0 = altitude * 0.3048;
      var R = y0 + me.R_sea;


      var vy0 = -me.nd_ref_v_down.getValue() * 0.3048;
      var vx0 = me.nd_ref_v_inrtl.getValue() * 0.3048;

      var n_engines = getprop("/fdm/jsbsim/systems/mps/number-engines-operational");

      if (me.active == 1)
         {
         if (me.pitch_tgt_set == 0)
            {
            setprop("/fdm/jsbsim/systems/ap/launch/droop-pitch-target", me.pitch_tgt);
            me.pitch_tgt_flown = me.pitch_tgt;
            me.pitch_tgt_set = 1;
            }
      
         if (vy0 > 0.0)
            {
            me.disengage();
            me.pitch_tgt = 0.0;
            }
         }

      else if (me.active == 0)
         {
         if (n_engines == 1)
            {         
            me.engage();
            }
         }



      var T = me.nd_ref_thrust1.getValue();
      T = T + me.nd_ref_thrust2.getValue();
      T = T + me.nd_ref_thrust3.getValue();

      var throttle_setting = T/(n_engines * 509002.0);

      var M = me.nd_ref_mass.getValue();

      T = T /M;
      T = T/n_engines;


      T = T * 9.81;
      T = T * 0.97;



      var Delta = M/(M - (1125.0 * throttle_setting)) - 1.0;
      Delta = Delta * 9.81;

      var alt_last = 1000000.0;
      var alt = 0.0;



      for (var i=0; i< 35; i=i+1)
         {
         alt = me.droop_trajectory (i * 15.0 + 15.0, me.pitch_tgt_flown, y0, vy0, vx0, T, R, Delta);
      
         if (alt > alt_last)
            {

            me.droop_alt =  alt_last;
            return;
            }
         else if (alt < 0.0)
            {

            me.droop_alt =  0.0;
            return;
            }


         alt_last = alt;
         }
      me.droop_alt = alt;
      return;
      },


};

var meco_time = {

   
   time_to_meco: 0.0,
   inertial_target: 0.0,
   counter: 0,
   mode: 0,
   delta_met: 0,


   init: func (inertial_target) {

      me.nd_ref_v_inrtl = props.globals.getNode("/fdm/jsbsim/velocities/eci-velocity-mag-fps", 1);
      me.nd_ref_thrust1 = props.globals.getNode("/fdm/jsbsim/propulsion/engine[0]/thrust-lbs", 1);
      me.nd_ref_thrust2 = props.globals.getNode("/fdm/jsbsim/propulsion/engine[1]/thrust-lbs", 1);
      me.nd_ref_thrust3 = props.globals.getNode("/fdm/jsbsim/propulsion/engine[2]/thrust-lbs", 1);
      me.nd_ref_mass = props.globals.getNode("/fdm/jsbsim/inertia/weight-lbs", 1);

      me.inertial_target = inertial_target * 0.3048;

      me.delta_met = getprop("/fdm/jsbsim/systems/timer/delta-MET");

   },
   
   run: func {

      if (me.mode == 2) {return;}


      # don't need to execute in every guidance cycle
      if (me.counter == 5)
         {me.counter = 0;}
      else
         {
         me.counter = me.counter + 1;
         return;
         }      
         
      var n_engines = getprop("/fdm/jsbsim/systems/mps/number-engines-operational");

      var T = me.nd_ref_thrust1.getValue();
      T = T + me.nd_ref_thrust2.getValue();
      T = T + me.nd_ref_thrust3.getValue();

      var throttle_setting = T/(n_engines * 509002.0);

      var M = me.nd_ref_mass.getValue();

      var a0 = T/M;
      a0 = a0 * 9.81;

      # to SI units
      M = M * 0.45359237;
      T = T * 4.44822161526;

      #print ("Current acceleration: ", a0/9.81, " g");
      #print ("Current mass:" , M, " kg");
      #print ("Current thrust:", T, " N");

      var mdot = 1313.5 * throttle_setting;

      var v0 = me.nd_ref_v_inrtl.getValue() * 0.3048;

      var t_3g = 0.0;
      var v_3g = v0;

      if (me.mode == 0)
         {
         t_3g = (29.43 * M - T) / (29.43 * mdot );
         v_3g = v0 + 4434.12 * math.ln(M/(M - mdot * t_3g));
         }

      #print ("Time to throttling: ", t_3g, " s");
      #print ("Inertial velocity at throttling: ", v_3g, " m/s");

      me.time_to_meco = t_3g + (me.inertial_target - v_3g) / 29.43;

      #print ("Time to MECO: ", me.time_to_meco, " s");

      

   },


   set_mode: func (mode) {

      me.mode = mode;

   },

   get_mode: func () {

      return me.mode;

   },

   get: func () {

      return me.time_to_meco + me.delta_met;
   },


};

GinGin
 
Posts: 688
Joined: Wed Jul 05, 2017 10:41 am
Location: Paris
Callsign: Gingin

Re: Space Shuttle - Mission File and Modding

Postby Thorsten » Wed Aug 21, 2019 5:24 am

A warning about custom mission files - they way they're designed is not compatible across different Shuttle version - if a new parameter has been introduced, an old-format mission file will simply fail for everything beyond where it tries to read that parameter, usually giving a mixture of default and i-loaded parameters.
Thorsten
 
Posts: 10820
Joined: Mon Nov 02, 2009 8:33 am


Return to Spaceflight

Who is online

Users browsing this forum: No registered users and 3 guests