Set Initial Guess with the Astrogator Scripting Tool
Astrogator.
To do this exercise you will need to have completed the Hohmann Transfer exercise found here and the Fast Transfer exercise found here.
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.
Overview
The Astrogator Scripting Tool allows you to perform your own computations without the need for external tools. This tutorial will build on the "Hohmann Transfer Using the Targeter" exercise and will apply initial guesses for the magnitudes of the two maneuvers. The propagator converges without using the scripting tool, the point of this exercise is just to walk through a simple Scripting Tool example.
- Open the Hohmann Transfer exercise you saved from the previous tutorial.
- Re-familiarize yourself with the scenario.
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 the Show Scripting Tool button.
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, or Matlab. |
Add Parameters
Let's start by adding parameters that allow you to specify the initial and final semi-major axis.
- Create a new Parameter.
- Name the new parameter, initial_a.
- Set the Type to Quantity.
- Ensure the units are 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.
- Create a New Object Property.
- Name the new Property, a0.
- Set the Object to Inner Orbit in the Initial State segment.
- Keep the default ReadOnlyProperty to false.
- Set the Attribute to use InitialState.Keplerian.sma.
Create a Second Object Property
- Create a second Object Property.
- Name the new Property, a1
- Set the Object to the Start Transfer (
) Target Sequence.
- Keep the default ReadOnlyProperty to false.
- Set the Attribute option to use Profiles.Differential Corrector.Results.DV1:Radius Of Apoapsis.Desired.
Set the Desired Values
Now you can set your desired values in Astrogator.
- Set a0 to initial_a.
- Set a1 to final_a.
Add Calc Objects
Next, you need to compute the Δ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.
- Name the new Calc Object, mu.
- Select the Gravitational Parameter in the Constants field.
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.
- Name the new Objectdv1_guess.
- Select the Start Transfer.DV1 segment.
- Keep the default ReadOnlyProperty to false.
- Select the ImpulsiveMnvr.Cartesian.X attribute.
- 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.
Your completed Scripting Tool GUI should look like this:
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.
- Name the new Objectdv2.
- Select the Finish Transfer.DV2 segment.
- Keep the default ReadOnlyProperty to false.
- Select the ImpulsiveMnvr.Cartesian.X attribute.
- 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.