Set an Initial Guess with the Scripting Tool

STK Premium (Space) or STK Enterprise
You can obtain the necessary licenses for this tutorial by contacting AGI Support at support@agi.com or 1-800-924-7244.

The results of the tutorial may vary depending on the user settings and data enabled (online operations, terrain server, dynamic Earth data, etc.). It is acceptable to have different results.

Watch the following video. Then follow the steps below, which incorporate the systems and missions you work on (sample inputs provided).

Capabilities Covered

This lesson covers the following STK Capabilities:

  • STK Pro
  • Astrogator

Problem Statement

Engineers and operators require a quick way to design high-fidelity spacecraft trajectories for mission planning and operations, all without external tools.

Solution

Use the Scripting Tool, a utility available within STK's Astrrogator capability, to compute the initial guesses for the maneuver magnitude. The Scripting Tool allows you to perform your own computations without the need for external tools.

This lesson builds on the Hohmann Transfer (Target Sequence) lesson. Please note, the propagator converges in that lesson without using the Scripting Tool. The point of this lesson is to walk through a simple Scripting Tool example.

What You Will Learn

Upon completion of this tutorial, you will be able to:

  • Open and use the Scripting Tool
  • Use VBScript to define object properties, calc objects, and parameters (Note: you can also use JavaScript, MATLAB, or Python)
  • Use the Scripting Tool in a target sequence

Video Guidance

Watch the following video. Then follow the steps below, which incorporate the systems and missions you work on (sample inputs provided).

Setup

Open the Hohmann Transfer exercise scenario locally or from the STK install.

  1. Open the Hohmann Transfer exercise you saved from the previous tutorial. If you have not completed this exercise, open the VDF located at: <STK install folder>\Data\Resources\stktraining\VDFs\Target_Hohmann_Transfer.vdf.
  2. Re-familiarize yourself with the scenario.

This exercise continues upon the completed the Hohmann Transfer (Target Sequence) exercise found here. If you have not completed the previous exercise, there is a VDF available at:
<STK install folder>\Data\Resources\stktraining\VDFs\Target_Hohmann_Transfer.vdf

How to Access the Scripting Tool

There are several locations the scripting tool can be found:

  • From the Scripting tab of the Differential Corrector properties:
  • As its own profile in the TargetSequence:
  • As part of a Sequence:

For this exercise, you will use the Scripting tool in the Sequence segment.

Add a Sequence

  1. Add a new Sequence () segment to the beginning of the MCS.
  2. Drag all current segments into this new Sequence ().
  3. Ensure to conserve the correct order.

  4. Enable the Scripting Tool.
  5. Click Scripting Tool... .

What's in the Scripting Tool?

There are four areas in the Scripting Tool:

OptionValue
Object PropertiesAllows you to get/set values from Astrogator segments. In our example we will use this to set the desired orbits and the initial guesses for the maneuver magnitudes.
Calc ObjectsAllows you to pull a value from any calculation object into the script. Examples include the current time, current orbital elements and information about engines.
ParametersAllows you to define additional values which may be used for computations. This may be custom constants or variables which are set during the computations.
Scripting AreaLocation where the actual script is written. You can use VBScript, JavaScript, MATLAB, or Python.

Add Parameters

Let's start by adding parameters that allow you to specify the initial and final semi-major axis.

  1. Create a new Parameter ().
  2. Rename the parameter 'initial_a'.
  3. Set the Type to Quantity.
  4. Ensure the Dimension is set to DistanceUnit.
  5. Set the value to 6700.0 km to match the scenario.

Add a Second Parameter

  1. Create a second parameter for the final semi-major axis.
  2. Repeat the steps above using 'final_a', as the name and 42164.0 km as the value.
  3. Close the Scripting Tool when complete. You will see these parameters in the Sequence properties.

Apply the Desired Value

So far initial_a and final_a are just constants. You need to set the initial semimajor axes and the desired radius of apogee to use these values. Let's start with the initial one.

  1. Click Scripting Tool... .
  2. Create a New Object Property () by selecting the New button under the Object Properties list.
  3. Double-click in the field to rename the Property "a0".
  4. Click the Properties () button.
  5. Set the Object to the Inner Orbit segment.
  6. Keep the default ReadOnlyProperty to false.
  7. Set the Attribute to InitialState.Keplerian.sma.
  8. Click OK to close the window.

Create a Second Object Property

  1. Create a second Object Property.
  2. Rename the Property "a1".
  3. Click the Properties () button.
  4. Set the Object to the Start Transfer () Target Sequence.
  5. Keep the default ReadOnlyProperty to false.
  6. Set the Attribute to Profiles.Differential Corrector.Results.DV1:Radius Of Apoapsis.Desired.
  7. Click OK to close the window.

Set the Desired Values

Now you can set your desired values in Astrogator.

  1. On the Scripting window, set the Language to VBScript.
  2. Set a0 to initial_a
    • a0 = initial_a

  3. Set a1 to final_a
    • a1 = final_a

Add Calc Objects

Next, you need to compute the Delta-V required to achieve the orbits specified above. You'll use simple two-body equations of motion for that.

OptionValue
μGravitational constant
rDistance from the satellite to the center of the Earth at the time of interest.
aSemimajor axis

For the initial and final circular orbits, this reduces to:

You need to get the value of μ to perform these calculations.

Create a New Calc Object

  1. Create a new Calc Object ().
  2. Rename the Calc Object "mu".
  3. Click the Properties () button.
  4. Double-click the CalcObject field.
  5. Click Change... .
  6. Select Gravitational Parameter from the Constants folder.
  7. Click OK on the Component Link Selection, Embedded Component Link Selection, and New... windows.

Compute the Initial Guess for DV1

Now that you have all the necessary inputs, you can compute the initial guess for the first maneuver. First, you need to compute the velocity in the circular initial orbit.

    v_init = sqr(mu/initial_a)

Next, you need the semimajor axis of the transfer orbit.

    transfer_a = (initial_a + final_a) / 2.0

This allows you to determine the required initial velocity of the transfer orbit.

    v_transfer_peri = sqr(2.0*mu/initial_a - mu/transfer_a)

The maneuver magnitude is just the difference between these two velocities:

    dv1 = v_transfer_peri - v_init

You can add a message box for testing to make sure you get the correct values. The correct dv1 should be 2.4195 km/s.

Set the Value for DV1

Now that you have the initial guess for the first maneuver, you need to apply this.

  1. Create a New Object Property ().
  2. Rename the Property "dv1_guess".
  3. Click the Properties () button.
  4. Set the Object to the Start Transfer.DV1 () segment.
  5. Keep the default ReadOnlyProperty to false.
  6. Set the Attribute to ImpulsiveMnvr.Pointing.Cartesian.X.
  7. Click OK to close the window.
  8. Set the dv1_guess value to be what you computed dv1 to be.
    • dv1_guess = dv1

  9. Reset all values in the Start Transfer () Target Sequence.
  10. Propagate the satellite. The Target Sequence should now converge in just two iterations.

Repeat for DV2

Complete the same set up for dv2. This requires you to compute the value for dv2 and then set it.

  1. Create a New Object Property ().
  2. Rename the Property "dv2_guess".
  3. Click the Properties () button.
  4. Set the Object to the Finish.Transfer.DV2 () segment.
  5. Keep the default ReadOnlyProperty to false.
  6. Set the Attribute to ImpulsiveMnvr.Pointing.Cartesian.X.
  7. Click OK to close the window.
  8. Add the computations of dv2 and set it equal to dv2_guess.
    • v_transfer_apo = sqr(2.0*mu/final_a - mu/transfer_a)
      v_final = sqr(mu/final_a)
      dv2 = v_final - v_transfer_apo
      dv2_guess = dv2

  9. Reset both Target Sequences ().
  10. Propagate the satellite.

Both Target Sequences should converge quickly. Try changing the values for initial_a and final_a to make sure the script continues to work.