How to Add an Attitude Model


Adding an Attitude Model to GMAT

Wendy C. Shoan
Goddard Space Flight Center



Introduction

GMAT provides the capability to model spacecraft attitudes.  As of R2013a, there are three attitude models included in GMAT: two kinematic models, Coordinate System Fixed and Spinner; and a SPICE Attitude class that extracts requested attitude data from user-provided SPICE CK kernels.  

This document will first give a brief design overview of the attitude code.  Then it will explain how to add a new Attitude Model to GMAT.  Due to current design, Attitude models must be added to the main GMAT base and are not suitable for plugins.  The implementation of a new Attitude model will involve, at a high level:

  • Creating a new class, derived from the main Attitude base class, or from an appropriate subclass, e.g. Kinematic
  • Implementing the required parameter access methods, other inherited methods, added methods, and the ComputeCosineMatrixAndAngularVelocity method
  • Adding your new class to the AttitudeFactory
  • Modifying the Spacecraft class to add creation of your new Attitude model, and for any additional mods that may be needed for your specific model
  • Inspecting the Attitude tab of the Spacecraft Panel and modifying as necessary

Design Overview

Each Spacecraft object in GMAT contains a pointer to one Attitude object (the Attitude object is considered an 'owned' object of the Spacecraft).  The type of this object is specified by the user (default is CoordinateSystemFixed).  Currently, all additional attitude data that can be set by the user are set through the spacecraft object, e.g.

Since other subsystems of GMAT may require attitude data from a spacecraft, and since the user may want to plot or report such data, the Spacecraft object contains methods to return its attitude (as a cosine matrix) and angular velocity at a specific epoch.  When these spacecraft methods are called, the spacecraft calls its owned attitude object to retrieve the requested data.  In addition, the pointer to its owned Attitude object may be retrieved by other subsystems or GMAT code in order to access additional Attitude methods directly.

All Attitude classes must be derived from the base Attitude class, or from an appropriate subclass of Attitude (e.g. Kinematic).  This base class declares data and methods required to retrieve spacecraft attitude and attitude rate data in different representations (currently Cosine Matrix, Quaternion, Euler Angles/Sequence, and Modified Rodriguez Parameters for attitude,  and Euler Angle Rates and Angular Velocity for rate).  The particular Attitude method that computes the cosine matrix and angular velocity is called ComputeCosineMatrixAndAngularVelocity.  It is a protected, virtual method and must be implemented in each leaf class.  

Static methods in the base Attitude class provide conversions between representations, without the need for a pointer to an Attitude object.

As mentioned above, GMAT currently has three Attitude models implemented.  The CSFixed and Spinner models are derived from an intermediate class, Kinematic, which is a child class of the base Attitude class.  The third attitude leaf class, SPICE Attitude, is derived directly from the base class.  Each of these three implements the ComputeCosineMatrixAndAngularVelocity method, as is required.

Below is a current simplified diagram representing the Attitude subsystem.

We will now discuss how to add an additional Attitude model to the GMAT code.

Steps to Add a New Attitude Model

Step 1: Implement the header

  • derive the class from the base Attitude class, Kinematic, or another subclass (as appropriate), e.g.   

  • provide a default constructor, copy constructor, operator=, and destructor
  • provide the Initialize and Clone methods
  • add protected/private data and methods as needed
  • add protected static const data, if needed
  • if you add fields that are user-settable, then:
    • add them to the protected part of the class
    • add a protected enumerated type, including the total parameter count, for the new fields, e.g. 
    • add the protected static PARAMETER_TEXT and PARAMETER_TYPE arrays for the new fields
    • add the appropriate public parameter access methods, e.g. SetRealParameter, GetRealParameter, or SetBoolean, etc.
    • add the required public methods GetParameterText, GetParameterID, GetParameterType, and GetParameterTypeString
    • if you added a data object, add the required public object access methods (GetRefObjectNameArray, SetRefObject, etc.)
  • provide the required protected method, ComputeCosineMatrixAndAngularVelocity

Step 2: Implement the source code

  • if you have added user-settable fields, define the PARAMETER_TEXT and PARAMETER_TYPE arrays
  • if you have added static const constants, define them
  • implement the default constructor, copy constructor, operator=, and destructor.  At a minimum, the paramCount and objectTypeNames must be set in the default constructor, e.g.
  • ensure that your copy constructor and operator= handle the new data correctly
  • implement the Initialize and Clone methods
  • implement methods you added to the class
  • implement the parameter and object access methods
  • implement the required protected method, ComputeCosineMatrixAndAngularVelocity method

Step 3: Add your class to the AttitudeFactory

  • edit AttitudeFactor.cpp to add your new class to the creatables list and the CreateAttitude method (NOTE that currently, Attitude objects are created in the Spacecraft code itself, but in the future, the Interpreter and/or Moderator will create the Attitude objects using the AttitudeFactory)

Step 4: If you are using the MakeBase.eclipse makefile, edit it to add your new class

Step 5: Modify Spacecraft.cpp as needed

  • modify Spacecraft::SetStringParameter to create an object of your new type when its string name is passed in
  • if necessary,modify the SetStringParameter, SetRefObject, and/or Initialize methods to add initialization or other operations on your new object

Step 6: Inspect the Attitude Panel for needed mods

You will need to make mods to the Attitude tab of the Spacecraft panel to add/hide data specific to your model, at least in the Create and DisplayDataForModel methods.

Currently, the Attitude tab on the Spacecraft panel looks like this:

 


 

Â