Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...


GMAT has the capability to model many types of Resources, for use in various types of space missions. Resources in GMAT are created, via script or GUI, and used by other Resources or in Commands, to run a particular mission of interest. Here is an example of the scripting of Resources for, in this case, a Lunar Orbit StationKeeping script:

Code Block
languagecpp
themeEmacs
languagecpp
Create Spacecraft LunaSat;
GMAT LunaSat.DateFormat = TAIModJulian;
GMAT LunaSat.Epoch = '21545';
GMAT LunaSat.CoordinateSystem = MoonInertial;
%% [...] other statements to configure the LunaSat resource 
Create ForceModel MoonProp_ForceModel;
GMAT MoonProp_ForceModel.CentralBody = Luna;
GMAT MoonProp_ForceModel.PrimaryBodies = {Luna};
GMAT MoonProp_ForceModel.PointMasses = {Earth, Jupiter, Sun};
%% [...] other statements to configure the ForceModel resource 
Create Propagator MoonProp;
GMAT MoonProp.FM = MoonProp_ForceModel;
GMAT MoonProp.Type = PrinceDormand78;
%% [...] other statements to configure the MoonProp resource 
Create ImpulsiveBurn dv1;
GMAT dv1.CoordinateSystem = Local;
GMAT dv1.Origin = Luna;
GMAT dv1.Axes = VNB;
%% [...] other statements to configure the dv1 resource 
Create ImpulsiveBurn dv2;
GMAT dv2.CoordinateSystem = Local;
GMAT dv2.Origin = Luna;
GMAT dv2.Axes = VNB;
%% [...] other statements to configure the dv2 resource 
Create Variable I; 
Create CoordinateSystem MoonInertial;
GMAT MoonInertial.Origin = Luna;
GMAT MoonInertial.Axes = BodyInertial;
%% [...] other statements to configure the MoonInertial resource 
Create DifferentialCorrector DefaultDC;
GMAT DefaultDC.ShowProgress = true;
%% [...] other statements to configure the DefaultDC resource 
Create OrbitView DefaultOrbitView;
GMAT DefaultOrbitView.SolverIterations = Current;
GMAT DefaultOrbitView.Add = {LunaSat, Luna};
GMAT DefaultOrbitView.CoordinateSystem = MoonInertial;
%% [...] other statements to configure the OrbitView 
Create XYPlot XYPlot1;
GMAT XYPlot1.SolverIterationsXVariable = LunaSat.A1ModJulian;
GMAT XYPlot1.YVariables = Current{LunaSat.Luna.RadPer};
%% [...] other statements to configure the XYPlot

The corresponding Resource Tree (top part only), showing the Resources defined in the script, looks like this: Image Removed

Image Added

GMAT provides many types of Resources that are useful in modeling Spacecraft Missions. However, you may need a particular type of resource that is not included in GMAT. In this case, you can add the needed resource to GMAT. There are two types of additions to discuss:

...

  • For the power system class, we need a custom GUI panel. See How to Create GMAT Panels for further instructions on creating a new GUI panel.
  • In the GuiItemManager class, we need to do several modifications:
    • Remember to set theNumPowerSystem in the constructors, and, as appropriate
    • Add the UpdatePowerSystem method referenced (see Appendix B)
    • Add the methods GetPowerSystemComboBox and UpdatePowerSystemList (see Appendix B)
    • Modify the GetAttachedHardwareList method:

      Code Block
      languagecpp
      // Get requested spacecraft
      GmatBase *obj = theGuiInterpreter->GetConfiguredObject(scName.c_str());
      if (obj)
      {
         StringArray tanks     = obj->GetStringArrayParameter("Tanks");
         StringArray thrusters = obj->GetStringArrayParameter("Thrusters");
         std::string pwrSystem = obj->GetStringParameter("PowerSystem");
      }
      
    • Update the UpdateAll method with:

      Code Block
      languagecpp
      case Gmat::POWER_SYSTEM:
         UpdatePowerSystem(true);
         break; 


      and further down, with: 

      Code Block
      languagecpp
      UpdatePowerSystem(false);
      #if DBGLVL_GUI_ITEM_UPDATE
      MessageInterface::ShowMessage("======> after UpdatePowerSystem()\n");
      #endif
    • In the UnregisterComboBox method, add: 


      Code Block
      languagecpp
      else if (type == "PowerSystem")
      {
         std::vector<wxComboBox*>::iterator pos =
         find(mPowerSystemCBList.begin(), mPowerSystemCBList.end(), cb); 
         if (pos != mPowerSystemCBList.end())
            mPowerSystemCBList.erase(pos);
      }
       
  • In the ResourceTreeclass, we need to add or modify code in several places:
    • In the UpdateGuiItem method, add the following:

      Code Block
      languagecpp
      case GmatTree::POWER_SYSTEM:
         theGuiManager->UpdatePowerSystem();
         break;
    • In the GetItemTypeAndIcon method, add the following:

      Code Block
      languagecpp
      else if (obj->IsOfType("PowerSystem"))
      {
         itemType = GmatTree::POWER_SYSTEM;
         itemIcon = GmatTree::RESOURCE_ICON_THRUSTER; // temporary - I need an icon for this!
      }
    • For this example, we are going to treat the PowerSystem class like other hardware plugins, even though it is not a plugin. This makes sense as there is already existing code to handle non-thruster, non-tank hardware objects. So, in OnAddHardware, we will need to check the type of the selection (see example code in Appendix B).
    • We also need to add the PowerSystem type to the GetObjectType and GetTreeItemId methods' switch statements:

      Code Block
      languagecpp
      case GmatTree::POWER_SYSTEM:
    • To make sure PowerSystem items are updated correctly, we need to add to the switch statement in the UpdateGUIItem method:

      Code Block
      languagecpp
      case GmatTree::POWER_SYSTEM:
         theGuiManager->UpdatePowerSystem();
         break;
       





  • Now we should create our PowerSystemConfgPanel GUI Panel (please see How to Create GMAT Panels for more information).

...

Code Block
languagecpp
//------------------------------------------------------------------------------
// NuclearPowerSystem
//------------------------------------------------------------------------------
// GMAT: General Mission Analysis Tool.
//
// Copyright (c) 2002-2014 United States Government as represented by the
// Administrator of The National Aeronautics and Space Administration.
// All Other Rights Reserved.
//
// Author: Wendy C. Shoan
// Created: 2014.04.28
//
//
/**
* Class implementation for the Nuclear Power System.
*/
//------------------------------------------------------------------------------

#include "NuclearPowerSystem.hpp"
#include "StringUtil.hpp"
#include "HardwareException.hpp"
#include "MessageInterface.hpp"
#include "Spacecraft.hpp"
//#define DEBUG_NUCLEAR
//---------------------------------
// static data
//---------------------------------
// none at this time
//------------------------------------------------------------------------------
// NuclearPowerSystem()
//------------------------------------------------------------------------------
/**
* Nuclear Power System constructor.
*
* @param nomme Name for the power system.
*/
//------------------------------------------------------------------------------
NuclearPowerSystem::NuclearPowerSystem(const std::string &nomme) :
   PowerSystem ("NuclearPowerSystem",nomme)
{
   objectTypes.push_back(Gmat::NUCLEAR_POWER_SYSTEM);
   objectTypeNames.push_back("NuclearPowerSystem");
   parameterCount = NuclearPowerSystemParamCount;
}

//------------------------------------------------------------------------------
// ~NuclearPowerSystem()
//------------------------------------------------------------------------------
/**
* Nuclear Power System destructor.
*/
//------------------------------------------------------------------------------
NuclearPowerSystem::~NuclearPowerSystem()
{
}

//------------------------------------------------------------------------------
// NuclearPowerSystem(const NuclearPowerSystem& copy)
//------------------------------------------------------------------------------
/**
* Copy constructor.
*
* This method is called by the Clone method to replicate power systems.
*
* @param copy Reference to the system that gets replicated.
*/
//------------------------------------------------------------------------------
NuclearPowerSystem::NuclearPowerSystem(const NuclearPowerSystem& copy) :
   PowerSystem (copy)
{
   parameterCount = copy.parameterCount;
}

//------------------------------------------------------------------------------
// NuclearPowerSystem& operator=(const NuclearPowerSystem& copy)
//------------------------------------------------------------------------------
/**
* Assignment operator.
*
* Sets the parameters for one power system equal to another's.
*
* @param copy Reference to the system that gets replicated.
*/
//------------------------------------------------------------------------------
NuclearPowerSystem& NuclearPowerSystem::operator=(const NuclearPowerSystem& copy)
{
   #ifdef DEBUG_NUCLEAR
      MessageInterface::ShowMessage("Calling assignment operator on %s\n",
                        instanceName.c_str());
   #endif
   if (&copy != this)
   {
      PowerSystem::operator=(copy);
   }
   return *this;
}

//------------------------------------------------------------------------------
// bool Initialize()
//------------------------------------------------------------------------------
/**
* Initializes the Nuclear Power System.
*/
//------------------------------------------------------------------------------
bool NuclearPowerSystem::Initialize()
{
   PowerSystem::Initialize();
   return isInitialized;
}
//---------------------------------------------------------------------------
// GmatBase* Clone() const
//---------------------------------------------------------------------------
/**
* Provides a clone of this object by calling the copy constructor.
*
* @return A GmatBase pointer to the cloned thruster.
*/
//---------------------------------------------------------------------------
GmatBase* NuclearPowerSystem::Clone() const
{
   return new NuclearPowerSystem(*this);
}


//------------------------------------------------------------------------------
// Real GetPowerGenerated()
//------------------------------------------------------------------------------
Real NuclearPowerSystem::GetPowerGenerated() const
{
   return GetBasePower();
}

//------------------------------------------------------------------------------
// Protected methods
//------------------------------------------------------------------------------
// none at this time

 


GUI Code

 


Code examples for the following are included here:

...

GuiItemManager.cpp

PowerSystemPanel.hpp

 


Code Block
languagecpp
//------------------------------------------------------------------------------
// void OnAddHardware(wxCommandEvent &event)
//------------------------------------------------------------------------------
/**
* Add a generic hardware to hardware folder
*
* The code used here should be generalizable for other plugin elements as well.
*
* @param <event> command event
*/
//------------------------------------------------------------------------------
void ResourceTree::OnAddHardware(wxCommandEvent &event)
{
   bool isPowerSystem = false;
   GmatTree::ItemType itsType = GmatTree::HARDWARE; 
   // Look up the plugin type based on the ID built with menu that selected it
   // NOTE: treating PowerSystems as plugins here as well
   std::string selected = pluginMap[event.GetId()];
   if (selected.find("PowerSystem") != std::string::npos)
   {
      isPowerSystem = true;
      itsType = GmatTree::POWER_SYSTEM;
   } 
   // The rest is like the other tree additions
   wxTreeItemId item = GetSelection();
   std::string newName = theGuiInterpreter->GetNewName(selected, 1); 
   GmatBase *obj = CreateObject(selected, newName); 
   if (obj != NULL)
   {
      GmatTree::ItemType dummyType;
      GmatTree::ResourceIconType iconToUse;
      GetItemTypeAndIcon(obj, dummyType, iconToUse); 
      wxString name = newName.c_str();
      AppendItem(item, name, iconToUse, -1,
                 new GmatTreeItemData(name, itsType));
      Expand(item);
      SelectItem(GetLastChild(item)); 
      if (isPowerSystem)
         theGuiManager->UpdatePowerSystem();
      else
         theGuiManager->UpdateSensor();
   }
} 

...

  • Next we modify Moderator.cpp to register the new ErrorModelFactory. We add an errorModelList to Interpreter. Then we edit Interpreter::BuildCreatableObjectMaps, to add a section for this new list:  


    Code Block
    languagecpp
    errorModelList.clear(); 
    StringArray erm = theModerator->GetListOfFactoryItems(Gmat::ERROR_MODEL); 
    copy(erm.begin(), erm.end(), back_inserter(errorModelList)); 
    copy(erm.begin(), erm.end(), back_inserter(allObjectTypeList)); 
    for (UnsignedInt i = 0; i < errorModelList.size(); i++) 
       objectTypeMap.insert(std::make_pair(errorModelList[i], Gmat::ERROR_MODEL));
  • In Interpreter::GetCreatableList, we add a section to the switch statement for this type as well:

...

The steps for adding a panel and incorporating your new Resource into the other GUI code are identical to steps taken for Type 1 (see Appendix A).