ST K Tutorial
ST K Tutorial
This tutorial shows how to use the STK Object Model in a custom application to
accomplish many of the tasks for which you might otherwise use Connect or the STK
GUI. Source code is given in C# and Visual Basic.NET. Familiarity with Microsoft
Visual Studio and STK are presumed.
Source Code Location: The source code for this tutorial can be found in the following
text file:
<INSTALL DIR>\Help\ObjectModel\text\ObjectModelTutorial.txt
The code is broken into sections corresponding to the sections in this tutorial. Within
each section, the C# and VB.NET code are presented in separate subsections.
CONTENTS
Where to Get Help .............................................................................................................. 1
Start Visual Studio and Create your Project ............................................... 3
Change the Project Configuration to x86 if you are Targeting 32-bit ........ 4
Add STK X Controls to your Form ............................................................ 4
Scenario Setup .................................................................................................................... 6
Add the Core of the STK ObjectModel to your Project ............................. 6
Create a New Scenario ................................................................................ 7
Set Time Period & Unit Preferences ........................................................... 7
Add Animation Controls ............................................................................. 8
Creating Objects & Setting Their Properties ...................................................................... 9
Create a Facility .......................................................................................... 9
Set Some Facility Properties ..................................................................... 11
Create a Target .......................................................................................... 12
Create a Ship ............................................................................................. 13
Create Some Satellites .............................................................................. 15
Computing & Constraining Access .................................................................................. 19
Compute Access........................................................................................ 19
Create Some Sensors................................................................................. 22
Control Display Intervals .......................................................................... 27
Apply Access Constraints ......................................................................... 30
1 of 31
In the Contents tab of the Help system, navigate to Using Core Libraries STK Object
Model STK Objects.
In addition to these introductory sections, the Library Reference for STK Objects is
broken down into subsections for the various types in the library.
Try this: To find help for the AgStkObjectRoot class discussed above, click Library
ReferenceSTK Object ModelSTK Objects and scroll down the alphabetical list until
you find the entry entitled "AgStkObjectRoot". Click AgStkObjectRoot to display a page
containing a diagram with several links, including a link to Root (IAgStkObjectRoot
Object). From that page you can access a page that lists all the members (methods and
properties) of the interface associated with the AgStkObjectRoot object. Similarly, you
Analytical Graphics, Inc. (AGI)
2 of 31
can find help for any other object or interface, as well as any method, property or
enumeration.
A quick way to find help on a given type is to use the Search tab of the Help system. For
example, suppose you are interested in the AgECoordinateSystem enum. If you enter
"AgECoordinateSystem" in the search field and click List Topics, a list of pages
containing that term appears. Click on the Title heading to order the list alphabetically,
and the entry for AgECoordinateSystem will appear at the top. Select that entry to
display a page defining the enum and listing its members.
TIP: Keep the STK Programming Interface Help system open to the Search tab
while you are working through this tutorial. Then you can copy and paste the
names of interfaces, enumerations, etc. into the search field to learn more about
their meaning and usage.
NOTE: It is not necessary to have STK running to display the Help system. To
launch Help, simply open the Windows Start Menu and navigate to All Programs
STK 10 Help STK 10 STK 10 Programming Interface.
In addition to the Object Model (STK Objects and STK Util), you may find it useful to
refer to help on STK X controls.
One final note on the STK Programming Interface help: In addition to help on
programming issues, the help provides information about the real-world context in which
the application is to be used. For example, the help page for the SpinAxisConeAngle
property tells you that it is writable, is of the Variant data type, and belongs to the
IAgSnPtSpinning interface. In addition, it tells you that the property represents "the cone
angle used in defining the spin axis; i.e., the angle between the spin axis and the sensor
boresight." This latter information is useful in deciding whether and how to use the
property in your application, but it is necessarily somewhat sketchy, since the help is
mainly intended to provide guidance on programming issues. However, in the STK Help
System, there is generally more information. For example, the help page for Spinning
Sensor Pointing not only gives more detailed context information but also includes a
drawing of spin axis geometry that illustrates the spin axis cone angle quite clearly.
TIP: For real-world context information on the Object Model types that you use
in your application, do not rely solely on the brief definitions in the Object Model
help. Refer also to the STK Help System.
3 of 31
STK X - a collection of COM components and ActiveX controls that use AGI's
After you have added a reference to AGI STK Objects 10, you will notice that reference
to its dependent libraries AGI.STKUtil, AGI.STKGraphics and AGI.STKVgt are also
automatically added.
4 of 31
The application that you create will allow the user to:
Create a Scenario and display it in 2D and 3D windows,
Control the animation of the scenario.
Select various actions from a combo box: populate the scenario with objects,
compute access and impose access constraints.
Here are the steps to create the GUI:
1. Display the automatically-generated Form1 in design view and stretch the form so
that it is approximately square and substantially fills the available workspace
(with Visual Studio maximized). Display its properties page and change
the Text property from Form1 to STK Object Model Tutorial.
2. If the Toolbox is not already in your workspace, then add it by clicking
on ViewToolbox from the menu. Right-click on a blank area in the General
section of the toolbox (i.e. neither a control nor the Toolbox title bar), and
select Choose Items from the drop-down menu.
3. From the dialog, select the COM Components tab and add the following
components to your project by selecting the checkboxes next to their entries:
AGI Globe Control 10
AGI Map Control 10
Click OK to close the dialog.
T
5 of 31
4. From the Form1 design view, find AGI Globe Control 10 in the Toolbox, and
draw a rectangular shape in the upper left region of your form. Do the same thing
with the AGI Map Control 10 in the lower left region of the form.
5. Place a ComboBox in the upper right corner of the form.
6. Display the properties page for the ComboBox and change its Text property to
"Select Action" and set its Enabled property to False.
7. Place a button below the ComboBox and change its Text property to "New
Scenario".
8. Place a GroupBox below the "New Scenario" button and stretch it so that it will
accommodate 6 buttons, arranged vertically. Change its Text property to
"Animation".
9. Arrange 6 buttons vertically in the GroupBox. Starting with the top button and
working down, set the Text properties of the buttons to:
Play Scenario
Pause Scenario
Rewind Scenario
Play Backward
Slower
Faster
This completes the artistic part of this exercise. Now, on to coding with the Object
Model.
T
Scenario Setup
Add the Core of the STK ObjectModel to your Project
Refer to ObjectModelTutorial.txt for the code segments to be added in this section.
Begin by adding statements at the beginning of the code (using in C#, Imports in
VB.NET) to gain access to the types defined in the STK Objects and STK Util libraries.
Next, define and initialize an instance of AgStkObjectRoot, the top level object in the
Object Model hierarchy, which exposes a set of methods and properties that you will find
indispensable in implementing the Object Model in your application. To name just 3
examples, this class includes the following methods:
NewScenario(): creates a new STK scenario.
LoadScenario(): loads a scenario file on a specified path.
ExecuteCommand(): takes a string representing a Connect command as an
argument and executes the command.
Finally, add OnFormClosing to close STK Object root properly, as indicated in
ObjectModelTutorial.txt.
6 of 31
7 of 31
In the Object Model, you can use the SetCurrentUnit() method to set the any of these
units explicitly. Here you will use it to change the preferred unit for Temperature from
Kelvin (K) to degrees Celsius (degC).
TIP: If you are in doubt about the available unit abbreviations for a given
dimension, launch STK, open the Basic Units page, and display the combo box
for the dimension in question.
Play Scenario
Pause
Rewind
Play Backward
Faster
Slower
If you are coding in C#, of course, you need to add a semicolon (;) to each of those
method statements.
8 of 31
In the above example, the facility is defined using the Geodetic position type.
Now refer to the CreateFacilities() method in the accompanying text file. It begins by
creating a facility named "Baikonur" and acquiring an interface to the IAgFacility object.
position type that you get via a conversion method made available by the IAgPosition
interface (through the Position property of the IAgFacility interface). Using the
IAgGeodetic interface, set latitude, longitude and altitude values. Then, using the
Assign() method of the IAgPosition interface, assign the IAgGeodetic interface back into
the facility object.
NOTE: If the latter assignment is not done, the facility's position will not update.
You will encounter this technicality in other interfaces as well, including any
interface that inherits from IAgOrientation.
Additional code lets you add short and long descriptions to the facility object, emulating
the functionality of the facility's Basic Description page in STK.
The next block of code in the CreateFacilities() method creates and positions the Perth
and Wallops facilities. Since you are setting all the position properties at once, it makes
sense to use a one-step method made available by the IAgPosition interface,
AssignGeodetic(). In addition to letting us assign latitude, longitude and altitude in one
line of code, this method eliminates the steps of acquiring the IAgGeodetic interface and
assigning it back into the facility object.
TIP: This coarse-grained approach, which is available for all position types, is
ideal where, as here, you are setting all the position properties at once. The finer-
9 of 31
grained approach that you used (unnecessarily) for the Baikonur facility is better
suited to cases in which only one or a small subset of properties is being tweaked.
Another way to create and position a facility in STK is to use the From Standard Object
Database:
The above example illustrates a search of the database using Name (Seoul) as the search
criteria.
The above process is captured by the Connect command ImportFromDB, which, in turn,
can be leveraged by the Object Model via the ExecuteCommand method of the
AgStkObjectRoot class. The CreateFacilities() method uses this approach to add two
facilities to the scenario: Seoul and WhiteSands. A helper function, GetSTKDataDir(),
takes database type as an argument (e.g., Facility, Satellite, City) and executes the
GetSTKHomeDir Connect command and returns a string representing the location of the
desired database directory.
The variables representing the facilities need to be added to the Form1 class, where they
will be available for use by other methods in that class.
In our application, operations affecting the scenario adding objects, computing access,
setting constraints are triggered by selections from a combo box. Referring again to the
text file, you will find code to populate the ComboBox and to call the CreateFacilities()
method when the appropriate selection is made.
Analytical Graphics, Inc. (AGI)
10 of 31
11 of 31
The above illustration shows how to change the color in which the facility displays in the
2D and 3D windows.
Similarly, when you create an object using the Object Model and acquire the
corresponding interface, you expose a variety of properties for the programmer to
configure. As noted above, you declared the variables representing the facilities at the
Form1 level, so that they are now available for a new method that changes their display
colors. Referring to the accompanying text file, the ChangeFacilitiesColor() method
consists of 5 statements one for each facility invoking the Color property of
IAgFaGraphics interface (via the Graphics property of the IAgFacility interface). Each
statement assigns to the Color property a system-defined color.
Additional code updates the SelectedIndexChanged() method.
To try out the newly added code, build and run your application, create a scenario, and
select Create Facilities and Change Facilities Color from the combo box.
Create a Target
The code for this section should look familiar, since the AssignGeodetic() method used in
CreateTarget() is to the same as that which was used to create the Perth and Wallops
facilities.
Update the SelectedIndexChanged() method, then build and run your application, create a
scenario, and select Create Target from the combo box:
12 of 31
Create a Ship
A ship object in STK is one of 3 objects (the others are the aircraft and ground vehicle
objects) that use the Great Arc propagator. For a Great Arc vehicle, you define the route
by specifying waypoints, and in the STK GUI, this is done on the Basic Route page:
13 of 31
Each row in the table represents a waypoint, with the specified latitude, longitude,
altitude, speed, acceleration, time and turn radius. You may notice that two of the
columns those for acceleration and time are grayed out. Those values are read-only,
because the Route Calculation Method is set to Smooth Rate, which derives acceleration
and time from speed and position.
The above functionality is captured in the Object Model through the
IAgVeWaypointsCollection, IAgVeWaypointsElement and IAgVePropagatorGreatArc
interfaces. Here are the highlights:
A convenience method, AddWaypoint(), lets you add a waypoint to the list,
represented by an instance of the IAgVeWaypointsCollection interface. The
waypoint - represented by an instance of IAgVeWaypointsElement has the 5
properties needed for waypoint definition using the Smooth Rate method.
The CreateShip() method creates a ship object and instantiates the IAgShip
interface.
The IAgVePropagatorGreatArc interface is acquired and used to set a start time,
to select the Smooth Rate method (known in the Object Model as
eDetermineTimeAccFromVel), and via its Waypoints property - to collect the
waypoints that are added by the convenience method.
Attitude and 2D Graphics properties are set using the IAgShip interface.
The Propagate() method of IAgVePropagatorGreatArc is used to propagate the
ship's path.
For more details, it is recommended that you consult the Help pages for the interfaces
involved in the above process.
Now update the SelectedIndexChanged() method, then build and run your application,
create a scenario, and select Create Ship from the combo box:
14 of 31
Here you can use the mouse to rotate and zoom in on the 3D view, taking advantage of
functionality that became available as soon as you dragged the AGI Globe Control onto
the form.
15 of 31
In the above example, the satellite is propagated using the TwoBody propagator, and the
orbit is defined using Classical (Keplerian) elements, with Period and Eccentricity
defining the orbit's size and shape; Inclination, Argument of Perigee and Longitude of
Ascending Node defining its orientation; and True Anomaly defining the location of the
satellite in the orbit.
These choices are reflected in the way in which the TDRS satellite is defined using the
Object Model in CreateSatellites(). After creating the satellite, selecting the TwoBody
propagator, the Classical coordinate type, and the J2000 coordinate system, and setting
some time properties (acquiring the necessary interfaces, of course, at each stage) the
CreateSatellites() method turns to the task of configuring the 3 categories of orbital
elements: size/shape, orientation and location.
Here is how CreateSatellites() defines size and shape:
Using the IAgOrbitStateClassical interface, it assigns to the SizeShape property
an enum value representing the option of using Period and Eccentricity to define
orbit size and shape.
The SizeShape property of that same interface is used to initialize the
IAgClassicalSizeShapePeriod interface.
Using the latter interface, values are assigned for Eccentricity and Period.
Orientation and location elements are handled similarly.
The orbital elements are then assigned back to the propagator object, and the orbit is
propagated.
The TDRS_3 satellite is loaded from the Satellite Database, using code similar to what
you saw above for the Facility Database, including the ExecuteCommand() method and
the helper function GetSTKDataDir(). An SGP4 propagator is assigned to the satellite
and used to set the time period.
Analytical Graphics, Inc. (AGI)
16 of 31
The J4 Perturbation propagator is used to propagate the ERS1 and Shuttle satellites. As
with the TDRS satellite, the orbits of these satellites are defined using Classical orbital
elements, but different choices of elements are used for defining size/shape and
orientation.
Commented code for the ERS1 satellite implements an option that the STK GUI makes
available via the satellite's 2D Graphics Pass page:
Among other things, that page lets you opt to display only the Ascending (south-tonorth), or Descending (north-to-south) portion of each orbit pass (or both or neither). The
commented code line selects the Descending option.
NOTE: If you uncomment this code line to try it out, be sure to re-comment or
remove it, since full path display of the ERS1 satellite is needed for some later
activities.
Variable declarations are needed at the Form1 level for the ERS1 and Shuttle satellites,
since they are used in other methods of that class.
Update the SelectedIndexChanged() method, build and run your application, create a
scenario and select Create Satellites from the combo box:
17 of 31
Another method in this section, ModifyShuttleDisplay(), lets us tweak and enhance the
2D Graphics properties of the Shuttle. After using the IAgVeGfxAttributesOrbit interface
to change the satellite's marker and line style, the method draws elevation contours
around it.
In the STK GUI, elevation contours are added and configured on the 2D Graphics
Contours page:
In the above example, you have selected Start, Stop, Step as the Add Method and set the
corresponding values to define 6 contour levels spaced 10 degrees apart. Use the Remove
Analytical Graphics, Inc. (AGI)
18 of 31
All button to get rid of any existing contour graphics, and then click Add to populate the
Level Attributes list with our newly defined contours. After increasing the LineWidth and
disabling the ShowLabel option of each contour, select the Show checkbox to display the
contours.
Here is how to perform all the above steps in the Object Model:
Acquire the IAgVeGfxElevContours interface, which exposes general settings for
elevation contours.
Acquire the IAgVeGfxElevationsCollection interface, which makes several
methods available for building and managing the set of contour levels.
Use that interface's RemoveAll() method to get rid of any existing contours.
Use its AddLevelRange() method to add 6 contours using the Start, Stop, Step
method.
Use its Count property to set up a loop in which you use the
IAgVeGfxElevationsElement interface to disable label display and increase line
width for each contour level.
Use the IsVisible property of the IAgVeGfxElevContours interface to display the
contours.
Update the SelectedIndexChanged() method, then build and run the application, create a
scenario, and select Create Satellites and Modify Shuttle Display from the combo box:
Now animate the scenario and observe the results in your 2D and 3D displays.
19 of 31
In this example, the Pattern Area Type is selected to define the boundary (the other
option is Ellipse). Latitude and longitude values for boundary points are added to a list,
and the boundary is created by drawing Great Arc lines between those points.
The definition of an area target using the Object Model largely parallels the GUI
approach. After using the IAgATGraphics interface to set some of the 2D Graphics
properties of the area target, the CreateAreaTarget() method defines the boundary as
follows:
An enum value representing the Pattern area type is assigned to the area target
object.
The IAgAreaTypePatternCollection interface is acquired and initialized.
The Add() method of that interface is used to add boundary points.
Additional code uses a course-grained method to position the area target's centroid.
Access is computed in STK by an object-level tool that provides a mechanism for the
selection of 'to' objects, as well as various setup and output options:
20 of 31
In the illustration, the Access tool has been launched from the ERS1 satellite the 'from'
object and the area target has been selected as the 'to' object. Access is computed when
someone clicks the Compute button or selects one of the report, graph or display options.
Access computation is carried out in a roughly similar fashion in the Object Model:
The IAgStkAccess interface is instantiated and initialized with the ERS1
satellite's GetAccessToObject() method, which takes the intended 'to' object
here, the area target as an argument.
The AgStkAccess interface's ComputeAccess() method is called.
The IAgDataPrvInterval interface is acquired and instantiated using the access
object's DataProviders property, which returns a list of available data providers
for the access.
The latter interface's Exec() method is used to compute the data for a specified
time period and assign it to an instance of the IAgDrResult interface.
The data thus returned is available for further use in the application.
The variables representing the area target and the access object are declared at the Form1
level, so that they are available to other methods in that class.
Update the SelectedIndexChanged() method, build and run the application, create a
scenario, and select Create Satellites, Create Area Target and Access (in that order)
from the combo box. You will notice a series of thick lines overlaid on the ERS1 ground
Analytical Graphics, Inc. (AGI)
21 of 31
track, representing intervals of access from ERS1 to the area target. Animate the scenario
to observe further graphic effects:
To remove access computations and graphics, the RemoveAccess() method uses the
IAgStkAccess interface's method of the same name. To test it, update the
SelectedIndexChanged() method, set up the access computation described above, and
then select RemoveAccess from the combo box.
This indicates that the new satellite is being created as a child of the current scenario.
Now compare the corresponding sequence in the code line that creates the Horizon
sensor:
root.CurrentScenario.Children["ERS1"].Children.
New(AgESTKObjectType.eSensor, "Horizon")
22 of 31
Here the Children property is used twice: once to indicate that the ERS1 satellite is a
child of the scenario, and another time to indicate that the new sensor is a child of ERS1.
Since the Definition properties of the Horizon and Downlink sensors are handled in a
fairly straightforward way by the STK GUI and by the Object Model, you can focus here
on the Pointing properties.
For the Horizon sensor, the Pointing Type is Fixed and the Orientation Method is
azimuth-elevation:
The code that implements these choices in CreateSensors(), except for the names of the
interfaces, should look familiar by now. The important thing to note is that after you use
the IAgOrientationAzEl interface to set the Elevation and AboutBoresight properties, it
all must be assigned back into the Orientation property of the interface representing the
Fixed pointing type (using the IAgOrientation interface's Assign() method).
The Downlink sensor uses the Targeted Pointing Type, with all the facilities in the
scenario assigned as targets:
23 of 31
24 of 31
The FiveDegElev sensor, attached to the Wallops facility, is of the Complex Conic
Sensor Type. The outer cone half-angle is set to 85 deg to limit the sensor's visibility to
objects at an elevation of 5 degrees or higher:
25 of 31
NOTE: The effect of setting a 90 deg Elevation here, where the sensor is attached
to a facility, is to point the sensor upward, while it had the opposite effect for the
Horizon sensor, which is attached to a satellite.
The 2D Graphics Projection properties of the FiveDegElev sensor have been modified to
impose a 785.248 km limit on the sensor's projection in the Map window:
26 of 31
You can further restrict the sensor's field of view by decreasing the outer cone half angle.
For example, reduce it to 75 deg to impose a 15 degree elevation requirement.
27 of 31
28 of 31
The settings in the Modify Access Attributes dialog disable display of the orbit and
ground markers during periods of no access.
Similarly, you can use the 2D Graphics Display Times page for the Downlink sensor to
confine its display to periods of facility access:
29 of 31
which is then used to disable the display of certain graphics attributes of the satellite,
including orbit and ground track display, during periods of no access.
For the sensor, you acquire the IAgDisplayTm interface and use its
SetDisplayStatusType() method to opt for display during periods of access. The
DisplayTimesData property of this interface is used to initialize the IAgDuringAccess
interface, which, in turn, is used to initialize the IAgObjectLinkCollection interface. That
interface provides the machinery to build up the collection of access objects.
The EnlargeTimePeriod() method extends the time period of the ERS1 satellite, giving us
24 hours of data to work with.
Update the SelectedIndexChanged() method, build and run your application, and try out
each of these display controls in turn. To see the effect of CustomDisplayIntervals(),
create a scenario and select Create Satellites, Enlarge Time Period and Custom Display
Intervals from the combo box. In the 2D window, the width and color of the ground track
for ERS1 are altered during the half-hour intervals preceding noon and midnight:
To see the effect of AccessDisplayIntervals(), create a new scenario, and then select
Create Facilities, Create Satellites, Create Sensors and Access Display Intervals.
Animate the scenario and observe how the ERS1 satellite and its sensors disappear from
view in the 2D and 3D windows except when there is access to a facility.
30 of 31
Commented code in both constraint methods invite you to experiment with other values
for the respective constraint.
31 of 31