STKTutorial
STKTutorial
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:
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
Add STK X Controls to your Form ............................................................ 4
Scenario Setup .................................................................................................................... 5
Add the Core of the STK ObjectModel to your Project ............................. 5
Create a New Scenario ................................................................................ 6
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
In the Contents tab of the Help system, navigate to Using Core Libraries STK Object
Model STK Objects.
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
can find help for any other object or interface, as well as any method, property or
enumeration.
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 12 Help STK 12 – STK 12 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.
2. Under the Installed templates, navigate to Templates, select either Visual Basic or
T T
C#, then in the Windows page choose Windows Forms Application . Configure the
T T
rest of your project settings as you see fit. In this tutorial, OMTutorial is used as
T
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.
of the toolbox (i.e. neither a control nor the Toolbox title bar), and select Choose
T
a rectangular shape in the upper left region of your form. Do the same thing with
the AxAgUiAx2DCntrl in the lower left region of the form.
6. Place a ComboBox in the upper right corner of the form.
7. Display the properties page for the ComboBox and change its Text property to
"Select Action…".
8. Place a button below the ComboBox and change its Text property to "New
Scenario".
9. 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".
If the Embed Interop Types property is set to True, select False from the menu.
10. 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
Reset Scenario
Play Backward
Slower
Faster
This completes the artistic part of this exercise. Now, on to coding with the Object
Model.
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.
Next, define and initialize an instance of AgStkObjectRoot, the top level object in the
Object Model hierarchy within the public partial class, 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.
In “Section: Add the Core of the STK Object Model to your Project”:
1. Add the code from the ObjectModelTutorial.txt file.
At this point you should be able to build and run your application. Click the New
Scenario button to display the 3D Globe and 2D Map:
The default units used by the STK GUI are shown on the scenario Basic Units page,
which lets you select among available alternative units from a combo box:
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.
In the above example, the facility is defined using the Geodetic position type, make sure
the terrain is turned off.
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
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-
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.
Build and run the application, create a scenario, and select Create Facilities from the
combo box:
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.
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:
Now update the SelectedIndexChanged() method, then build and run your application,
create a scenario, and select Create Ship from the combo box:
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.
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.
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-to-
north), 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:
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
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.
The boundary of an area target is defined in the STK GUI via the Basic Boundary page:
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:
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
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.
root.CurrentScenario.Children.New(AgESTKObjectType.eSatellite,
"ERS1")
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")
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:
The variable representing the Downlink sensor needs to be declared at the Form1 level,
so that it can be used by other methods in that class.
Now update the SelectedIndexChanged() method, then build an run the application,
create a scenario, and select Create Facilities, Create Satellites and Create Sensors from
the combo box. Animate the scenario and observe the sensor pattern as the Downlink
sensor on ERS1 acquires its targets:
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:
Update the SelectedIndexChanged() method, then build and run the application, create a
scenario and select Create Facilities and Limit Sensor Visibility from the combo box:
One option is to set up custom intervals and alter the display of an object during those
intervals. For example, on the 2D Graphics Attributes page for the ERS1 satellite, you
can select the Custom Intervals option and alter the display of the satellite and its ground
track during selected time intervals:
Another option for controlling the display of objects in the 2D and 3D windows is to limit
their display to defined access periods. For example, you can limit the display of the orbit
and ground markers for the ERS1 satellite to periods when it has access to one or more
facilities:
Similarly, you can use the 2D Graphics Display Times page for the Downlink sensor to
confine its display to periods of facility access:
For the satellite, you begin as you did in CustomDisplayIntervals(), by selecting the 2D
graphics attributes type, except that here you select access intervals instead of custom
intervals. Then you acquire the IAgVeGfxAttributesAccess interface and use its
AccessObjects property to build up a collection of access objects (facilities). Use the
NoAccess property of that interface to initialize the IAgVeGfxAttributesOrbit interface,
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.
For example, you can use the Horizon sensor's Constraints Basic page to constrain access
from that sensor to occur only when the range to the 'to' object does not exceed 2000 km:
To help test these constraints, the FacilityAccess() method computes access from the
Horizon sensor to Baikonur.
Update the SelectedIndexChanged() method, then build and run your application, and
create a scenario. To test the range constraint, select Create Facilities , Create Satellites ,
T T T T
Create Sensors , Facility Access and Range Constraint from the combo box. To test the
T T T T T T
sun elevation angle constraint, create a new scenario and select Create Facilities , Create
T T T
Commented code in both constraint methods invite you to experiment with other values
for the respective constraint.