Working with Objects |
Top Previous Next |
When working within FreeFlyer, you will create both objects and commands.
Some facts about objects:
This guide covers the following topics:
Object ConstructorsIn 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.
For a complete list of objects with constructors that have input arguments, see the List of Object Constructors in the Appendix.
Constant and Global KeywordsFreeFlyer 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 ProceduresThe 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 InstancesGlobal 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.
Type CastingMany 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.
Base TypesFreeFlyer 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.
TypeOf OperatorThe 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:
Output report:
IsType OperatorThe 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.
AsType OperatorThe 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:
Example: Tanks
Example: Burns
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.
See Also |