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 LoopsFreeFlyer 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 ModeIn 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.
The historical data is maintained through the iterations through the For loop, as seen in the output below:
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.
Now, the output becomes:
Millisecond Timing Precision ModeIn 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.
The output will simply be 0 for each iteration, because of the reset FreeFlyer enforces:
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.
Now, the output becomes:
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 StatesAnother 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:
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
Millisecond Timing Precision ModeIn 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.
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 StateYou 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:
See Also•List of Properties and Methods with a State
|