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.
- 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.
- 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
- Add a new Sequence () segment to the beginning of the MCS.
- Drag all current segments into this new Sequence ().
- Enable the Scripting Tool.
- Click .
Ensure to conserve the correct order.
What's in the Scripting Tool?
There are four areas in the Scripting Tool:
Option | Value |
---|---|
Object Properties | Allows 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 Objects | Allows you to pull a value from any calculation object into the script. Examples include the current time, current orbital elements and information about engines. |
Parameters | Allows 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 Area | Location 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.
- Create a new Parameter ().
- Rename the parameter 'initial_a'.
- Set the Type to Quantity.
- Ensure the Dimension is set to DistanceUnit.
- Set the value to 6700.0 km to match the scenario.
Add a Second Parameter
- Create a second parameter for the final semi-major axis.
- Repeat the steps above using 'final_a', as the name and 42164.0 km as the value.
- 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.
- Click .
- Create a New Object Property () by selecting the New button under the Object Properties list.
- Double-click in the field to rename the Property "a0".
- Click the Properties () button.
- Set the Object to the Inner Orbit segment.
- Keep the default ReadOnlyProperty to false.
- Set the Attribute to InitialState.Keplerian.sma.
- Click to close the window.
Create a Second Object Property
- Create a second Object Property.
- Rename the Property "a1".
- Click the Properties () button.
- Set the Object to the Start Transfer () Target Sequence.
- Keep the default ReadOnlyProperty to false.
- Set the Attribute to Profiles.Differential Corrector.Results.DV1:Radius Of Apoapsis.Desired.
- Click to close the window.
Set the Desired Values
Now you can set your desired values in Astrogator.
- On the Scripting window, set the Language to VBScript.
- Set a0 to initial_a
- Set a1 to final_a
a0 = initial_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.
Option | Value |
---|---|
μ | Gravitational constant |
r | Distance from the satellite to the center of the Earth at the time of interest. |
a | Semimajor 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
- Create a new Calc Object ().
- Rename the Calc Object "mu".
- Click the Properties () button.
- Double-click the CalcObject field.
- Click .
- Select Gravitational Parameter from the Constants folder.
- Click 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.
- Create a New Object Property ().
- Rename the Property "dv1_guess".
- Click the Properties () button.
- Set the Object to the Start Transfer.DV1 () segment.
- Keep the default ReadOnlyProperty to false.
- Set the Attribute to ImpulsiveMnvr.Pointing.Cartesian.X.
- Click to close the window.
- Set the dv1_guess value to be what you computed dv1 to be.
- Reset all values in the Start Transfer () Target Sequence.
- Propagate the satellite. The Target Sequence should now converge in just two iterations.
dv1_guess = dv1
Repeat for DV2
Complete the same set up for dv2. This requires you to compute the value for dv2 and then set it.
- Create a New Object Property ().
- Rename the Property "dv2_guess".
- Click the Properties () button.
- Set the Object to the Finish.Transfer.DV2 () segment.
- Keep the default ReadOnlyProperty to false.
- Set the Attribute to ImpulsiveMnvr.Pointing.Cartesian.X.
- Click to close the window.
- Add the computations of dv2 and set it equal to dv2_guess.
- Reset both Target Sequences ().
- Propagate the satellite.
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
Both Target Sequences should converge quickly. Try changing the values for initial_a and final_a to make sure the script continues to work.