Working with Objects
|Top Previous Next|
Some facts about objects:
This guide covers the following topics:
In order to create a basic object within a FreeForm Script Editor, the simple <Object Type> <Object Name> format, or "constructor", is used, as shown here:
However, to create some of FreeFlyer's more complex objects, you may want to specify input arguments when creating the object. The constructor format for creating an object using input arguments is <Object Type> <Object Name>(Input1, Input2, ...). For example:
Custom descriptions of objects can be created using the following syntax. The custom description will show up in the tooltip mouse-over.
FreeFlyer supports constant Variables and Strings. The value of a String or Variable that is created using the Constant keyword can not be changed later in the Mission Plan. The value of the Variable or String is assigned in-line with the creation of the object, as seen in the examples below.
FreeFlyer also supports global objects, which can be accessed from a Procedure without having to be included in the list of arguments passed to the Procedure. An object that is declared as Global is available in all Procedures that are called from the scope in which the Global Object is defined.
The Global and Constant keywords can be used in conjunction. To specify a Variable or String as a Global Constant, the Global identifier must be declared before the Constant identifier, as seen in the example below.
Global Objects in Procedures
The example below demonstrates how Global objects can be accessed in Procedures without being passed in as input arguments to the Procedure. If an object is not Global, it must be passed as an argument in order to be accessible within a Procedure.
In the Mission Plan:
In the Procedure:
Note: Procedures referring to Global Objects will only work with Mission Plans that contain the required global objects.
Always Available Global Object Instances
Global instances of the following objects exist in every Mission Plan. With the exception of the ConsoleWindow object and StarField object, these objects are not creatable by the user. In the case of the ConsoleWindow and StarField objects, the user can create any number of ConsoleWindows or StarFields in addition to the built-in global instances. Through these objects, you can edit FreeFlyer properties relating to display, data files, and more. The following table lists the global object types and their instance names.
Examples of editing these objects through script are given below.
Many of the object types in FreeFlyer are base types, which can refer to several different object types when used in FreeForm script. For example, a Spacecraft's Propagator could be a Two-Body, Runge-Kutta, Ephemeris, or any other type of propagator. The AsType, IsType, and TypeOf operators allow users to interact with base types, as shown in the examples below.
While we will use the "Propagator" example to illustrate how to work with base types and the type casting operators, these concepts also apply to other object types.
FreeFlyer base object types provide sets of commonly needed properties to other objects. An object type that derives from a base type will inherit all the properties and methods of its base object type(s). For example, at the highest level, the Object base type provides a property called "ObjectId" to all objects. The inheritance tree for all the FreeFlyer objects and base types is given on the Object Hierarchy page.
Instances of base object types can not be created via the Object Browser or through FreeFlyer script, but they can be passed to a Procedure. In the following example, a Procedure called "PropType" receives a Propagator base object from a Mission Plan, and assigns a tolerance to the Propagator based on its sub-type. In this example, only two possible types are called out: RK45 and RK89. If the Propagator were a different type, its tolerance would not be changed by this script. This example uses the TypeOf, IsType, and AsType operators, which are discussed in further detail below.
The TypeOf operator can be used to convert any type in FreeFlyer script into a string containing the name of that type. This allows you to use the autocomplete menu when typing the object type, and helps avoid runtime errors due to typos.
For example, the Spacecraft.SetPropagatorType method expects a string as input. The TypeOf operator can be used to convert a Propagator Type, such as RK45, to string format for use with this method, as demonstrated in the example above. This operator can be used with any object type:
The IsType operator can be used to determine the type of an object in FreeForm script. This operator returns a 1 or 0, depending on whether the condition is true or false, making it useful when working with the If and While statements. This can be useful when the type of an object is unknown, perhaps because it has been passed into a generic Procedure which is used by multiple Mission Plans. The example below demonstrates using the IsType Operator to check whether a Spacecraft is being propagated with an Ephemeris.
The AsType operator can be used to cast an object to the desired object type in order to access properties that are only available at the sub-type level. This is especially useful when an object has been passed to a Procedure as a base type or when the object type has been set in script.
While we have thus far used the "Propagator" example to illustrate these type casting operators, the concepts also apply to other object types:
The inheritance tree for all the FreeFlyer objects and base types, which shows all the objects that can be cast to other object types, is given on the Object Hierarchy page.