Properties and Methods with a State

Top  Previous  Next

There are a set of FreeFlyer object properties and methods that "have a state." This means that the property or method contains historical data. The most straightforward example of this is the Spacecraft.ElapsedTime property - this property internally stores the time at which it was first called, and returns the current time minus that original time. For a complete list of the Properties and Methods with a State available in FreeFlyer, see the List of Properties and Methods with a State in the Appendix. Note that this list includes all Interval Methods and Stop-Propagation Properties and Methods.

 

This page covers the following topics:

 

Usage with For Loops

Initialization of New States

Resetting Methods with State

 

 

Usage with For Loops


FreeFlyer is commonly used to conduct parametric studies, in which one or more input property is changed over many iterations of an analysis. For example, a finite burn duration might be incremented by intervals of 5 seconds, and the impact on a Spacecraft orbit is observed. Sometimes, at the beginning of each iteration of a For loop, it is desirable to "start fresh" and reset any historical data. For example, if you are gathering information and reporting the ElapsedTime corresponding to that data, you may want the ElapsedTime to reset to 0 at the beginning of each iteration.

 

FreeFlyer contains two separate timing precision modes, and properties and methods with a state are handled differently in For loops in each timing precision mode. As of FreeFlyer 7.3, the default timing precision mode is nanosecond precision mode.

 

Note: There are several other differences between the nanosecond and millisecond modes. See the timing precision mode page for more information.

 

Nanosecond Timing Precision Mode

 

In nanosecond timing precision mode, properties and methods with a state are not automatically reset at the start of each iteration of a For loop. However, the "with reset" keywords can be used to force these properties and methods to reset their state at the start of each iteration of a For loop.

 

// Nanosecond mode Mission Plan

For Variable1 = 1 to 10;

    Step Spacecraft1;

    Report Spacecraft1.ElapsedTime;

End;

 

The historical data is maintained through the iterations through the For loop, as seen in the output below:

 

Spacecraft1.ElapsedTime

   0.000000000

   0.003472222

   0.006944444

   0.010416667

   0.013888889

   0.017361111

   0.020833333

   0.024305556

   0.027777778

   0.031250000

 

If you are using a For loop in a parametric study, and you would like to reset the historical data at the start of each iteration, you can use the "with reset" option, as shown below.

 

For Variable1 = 1 to 10 with reset;

     Step Spacecraft1;

     Report Spacecraft1.ElapsedTime;

End;

 

Now, the output becomes:

 

Spacecraft1.ElapsedTime

   0.000000000

   0.000000000

   0.000000000

   0.000000000

   0.000000000

   0.000000000

   0.000000000

   0.000000000

   0.000000000

   0.000000000

 

Millisecond Timing Precision Mode

 

In millisecond timing precision mode, properties and methods with a state are automatically reset at the start of each iteration of a For loop; the "without reset" keywords can be used to prevent the state from being reset.

 

// Millisecond mode Mission Plan

For Variable1 = 1 to 10;

    Step Spacecraft1;

    Report Spacecraft1.ElapsedDays;

End;

 

The output will simply be 0 for each iteration, because of the reset FreeFlyer enforces:

 

Spacecraft1.ElapsedDays

   0.000000000

   0.000000000

   0.000000000

   0.000000000

   0.000000000

   0.000000000

   0.000000000

   0.000000000

   0.000000000

   0.000000000

 

If you are using a For loop outside the context of a parametric study, and you would like to prevent this reset of historical data, you can use the "without reset" option, as shown below. Another option is to use a While loop with a manually incremented "counter" variable.

 

For Variable1 = 1 to 10 without reset;

     Step Spacecraft1;

     Report Spacecraft1.ElapsedDays;

End;

 

Now, the output becomes:

 

Spacecraft1.ElapsedDays

   0.000000000

   0.003472222

   0.006944444

   0.010416667

   0.013888889

   0.017361111

   0.020833333

   0.024305556

   0.027777778

   0.031250000

 

A more practical use case for the "without reset" keywords would be reporting an interval method inside a For loop in order to perform an analysis with a List of objects (e.g. reporting the PassData interval method between a Spacecraft and a List of GroundStations, as shown below).

 

Note: Properties and Methods with a State are also reset inside of Target loops.

 

 

Initialization of New States


Another important note regarding properties or methods with a state is that they are initialized separately each time they are used. In the example below, each instance of Spacecraft1.ElapsedTime is separate, with its own internal reference point for its historical data which is maintained independently from other instances. So, this example will propagate a Spacecraft for a total of two consecutive days:

 

While (Spacecraft1.ElapsedTime < TIMESPAN(1 days));   // Each "Spacecraft1.ElapsedTime" is a separate instance

     Step Spacecraft1;

End;

 

While (Spacecraft1.ElapsedTime < TIMESPAN(1 days));   // Each "Spacecraft1.ElapsedTime" is a separate instance

     Step Spacecraft1;

End;

 

FreeFlyer will also keep a separate internal reference point for historical data if any key arguments being passed to a property or method with state are changed. For example, you may want to loop through a List of GroundStations and report pass data between a Spacecraft and each GroundStation in the List, as shown in the example below. Each time the GroundStation argument passed to the PassData interval method is changed, FreeFlyer keeps track of this internally as a new state.

 

Nanosecond Timing Precision Mode

 

Variable i;

Spacecraft sc;

List<GroundStation> gsList;

gsList.Count = 3;

 

While (sc.ElapsedTime < TIMESPAN(1 days));

     For i = 0 to gsList.Count-1;

           Report sc.PassData(gsList[i]) to "PassDataReport.txt"; // Each "Spacecraft1.PassData(gsList[i])" is a separate instance

     End;

     Step sc;

End;

 

Run "notepad.exe PassDataReport.txt";

 

Millisecond Timing Precision Mode

In millisecond precision mode, the "without reset" keywords must be used in this use case, so that the historical data tracked within the interval method is not reset at the start of each iteration of the For loop, as explained above.

 

Variable i;

Spacecraft sc;

List<GroundStation> gsList;

gsList.Count = 3;

 

While (sc.ElapsedDays < 1);

     For i = 0 to gsList.Count-1 without reset;

           Report sc.PassData(gsList[i]) to "PassDataReport.txt"; // Each "Spacecraft1.PassData(gsList[i])" is a separate instance

     End;

     Step sc;

End;

 

Run "notepad.exe PassDataReport.txt";

 

Note: Because they are initialized separately each time they are used, Properties and Methods with a State may display unexpected values when evaluated in the Inspector.

 

 

Resetting Methods with State


You can call the ResetMethodStates() method on an object in order to reset the internally stored historical data for any methods associated with that object. For example:

 

Spacecraft sc;

 

// Reset any method states associated with the calling Spacecraft object

sc.ResetMethodStates();

 

 

See Also


List of Properties and Methods with a State

Interval Methods

Stepping the Spacecraft