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.

  1. Open the Hohmann Transfer exercise you saved from the previous tutorial.
  2. 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

  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 the Show Scripting Tool button.

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.

  1. Create a new Parameter.
  2. Name the new parameter, initial_a.
  3. Set the Type to Quantity.
  4. Ensure the units are 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. Create a New Object Property.
  2. Name the new Property, a0.
  3. Set the Object to Inner Orbit in the Initial State segment.
  4. Keep the default ReadOnlyProperty to false.
  5. Set the Attribute to use InitialState.Keplerian.sma.

Create a Second Object Property

  1. Create a second Object Property.
  2. Name the new Property, a1
  3. Set the Object to the Start Transfer () Target Sequence.
  4. Keep the default ReadOnlyProperty to false.
  5. 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.

  1. Set a0 to initial_a.
  2. 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

  1. Create a new Calc Object.
  2. Name the new Calc Object, mu.
  3. 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.

  1. Create a new Object Property.
  2. Name the new Objectdv1_guess.
  3. Select the Start Transfer.DV1 segment.
  4. Keep the default ReadOnlyProperty to false.
  5. Select the ImpulsiveMnvr.Cartesian.X attribute.
  6. Set the dv1_guess value to be what you computed dv1 to be.
  7. Your completed Scripting Tool GUI should look like this:

  8. Reset all values in the Start Transfer () Target Sequence.
  9. 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. Name the new Objectdv2.
  3. Select the Finish Transfer.DV2 segment.
  4. Keep the default ReadOnlyProperty to false.
  5. Select the ImpulsiveMnvr.Cartesian.X attribute.
  6. Add the computations of dv2 and set it equal to dv2_guess.
  7. 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

  8. Reset both Target Sequences ().
  9. 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.