Structs

Top  Previous  Next

FreeFlyer script allows users to define Structs, which are collections of related FreeFlyer objects. Unlike Lists, Structs can contain many objects of different types. Structs can be passed as arguments into Procedures, effectively passing several related objects into the Procedure as a single argument. FreeFlyer Structs are also designed to allow users to easily import and export JSON data.

 

There are a variety of Sample Mission Plans (included with your FreeFlyer installation) that demonstrate the use of Structs. Continue to one of the Mission Plans listed below to view descriptions and images of these examples.

 

FreeFlyer Scripting Samples

Struct Example

 

 

Defining a Struct


When working with Structs, the first step is to specify the Struct definition. This sets the type name for the Struct and the types and names of the member data held by the Struct. The general syntax for defining a Struct is:

 

Struct StructName;

 

     <Object Type> InstanceName1; // repeat as needed

 

End;

 

A more specific syntax example is shown below. This example shows how to define a Struct called "SpacecraftWithMetaData" that contains an instance of a Spacecraft object, several Variable objects, and a String object. Structs can contain instances of any type of FreeFlyer object. Structs can also contain Lists of FreeFlyer objects.

 

// The Struct type "SpacecraftWithMetaData" represents a Spacecraft object plus some additional metadata

 

Struct SpacecraftWithMetaData;

 

      Spacecraft SC;

 

      Variable ObsAvailable; 

      Variable ObsUsed;

      Variable ResidualsAccepted;

      Variable WeightedRMS; 

 

      String Comments; 

 

End;

 

You can define a Struct that will contain other types of Structs. The example below shows the definition for a "ConjunctionDataStruct" that will contain two instances of the "SpacecraftWithMetaData" Struct.

 

// The Struct type "ConjunctionDataStruct" represents a simulation with two Spacecraft plus their metadata, plus some simulation-level metadata

 

Struct ConjunctionDataStruct;

 

      String Filename;

 

      TimeSpan TCA;

      Variable MissDistance;

 

      SpacecraftWithMetaData Object1;

      SpacecraftWithMetaData Object2;

 

End;

 

You can also define a Struct that derives off of another type of Struct, using the "extends" keyword. The example below shows how to define a "HighInterestConjunction" Struct that extends the "ConjunctionDataStruct" type.

 

Struct HighInterestConjunction extends ConjunctionDataStruct;

 

 TimeSpan ManeuverDecisionDeadline;

 

End;

 

You can also define Structs in a separate file, and include the file in your Mission Plan using the Include command or the "Externals" tab, similar to defining FreeFlyer Procedures in an external file.

 

 

Creating an Instance of a Struct


Once you've defined a Struct type, you can create one or more instances of it. This is similar to creating any other type of object in FreeFlyer script. The example below shows how to create two instances of the "SpacecraftWithMetaData" Struct defined above:

 

SpacecraftWithMetaData LEO1;

SpacecraftWithMetaData LEO2;

 

You can also create a List of instances of a Struct. After creating the List, simply set the List.Count as usual:

 

List<SpacecraftWithMetaData> catalog;

catalog.Count = 900;

 

 

Working with Struct Instances


After creating one or more instances of your Struct type, you can access the various objects contained within the Struct, just like working with other types of objects that are built-in to FreeFlyer. Some syntax examples are shown below:

 

// Access the Spacecraft objects' semi-major axis

LEO1.SC.A = 7000;      

LEO2.SC.A = 7050;      

 

// Access the Variables and Strings contained in the Struct

LEO1.ObsAvailable = 95;  

LEO1.ObsUsed = 93;

LEO1.Comments = "primary";

LEO2.Comments = "secondary";

 

// Access a method on the Spacecraft object in Struct #1 to compute the range to the Spacecraft object in Struct #2

Report LEO1.SC.Range(LEO2.SC);

 

You can use the assignment operator (=) to assign two instances of the same type of Struct, so long as all the object types contained within the Struct are assignable.

 

SpacecraftWithMetaData LEO3;

 

LEO3 = LEO1;

 

You can also use reference assignment (the := operator) to configure an object contained within a Struct to refer to another object that you created separately. This will cause any references to that Struct element to refer to the specified object. The example below demonstrates using reference assignment with a Spacecraft contained in a Struct:

 

Spacecraft SpacecraftCreatedEarlier;

 

SpacecraftWithMetaData LEO3;

 

// Any references to LEO3.SC will now point to the SpacecraftCreatedEarlier object

LEO3.SC := SpacecraftCreatedEarlier;

 

 

Working with JSON Data


FreeFlyer Structs are designed to allow users to easily import and export JSON data. JSON, or JavaScript Object Notation, is a data file format that contains attribute-value pairs. You can specify annotations (using the @ symbol) for individual objects contained in a Struct to indicate how that object's data should be handled when serializing to JSON format, or deserializing from JSON format. For more information on working with JSON data in FreeFlyer, see the JSON-Formatted Data page.

 

For an example of using Structs to import JSON Data, see the Close Approach Maneuver Sample Mission Plan.

 

See Also


JSON-Formatted Data page in the Interfacing with External Resources Guide

Using Procedures Guide

Struct script element

Include Command

Script Operators Guide

Lists page