...
Built-in GMAT function call can have any number of predefined inputs and outputs. As an example, a new function called QuatToCosineMatrix() will be created. This function takes 4 element Array of quaternion as an input and converts to 3 by 3 element Array of cosine matrix as output. The function interface will look like “[cosMat] = QuatToCosineMatrix(quat).” This function will call base/util/AttitudeConversionUtility::ToCosineMatrix when executing.
- Copy base/function/GetLastState.hpp and GetLastState.cpp to base/function/ QuatToCosineMatrix.hpp and QuatToCosineMatrix.cpp.
- Replace “GetLastState” to “QuatToCosineMatrix” in QuatToCosineMatrix.hpp and QuatToCosineMatrix.cpp files.
- Update file prolog and method prologs.
- In QuatToCosineMatrix.hpp, under protected, add member data to hold input and output values.
Rvector quat;Rmatrix33 cosMat;
- In constructor, add dummy input names to inputNames and inputArgMap. Input names must be unique since these names will be added to function object store. Initialize wrappers to NULL.
inputNames.push_back(“__BuiltinFunction_QuatToCosineMatrix_input_1_quat__”);inputArgMap.insert(std::make_pair(“__BuiltinFunction_QuatToCosineMatrix_input_1_quat__”, (ElementWrapper*) NULL));
- In constructor, add dummy output names and expected output wrapper type. Output names must be unique since these names will be added to function object store. Initialize wrappers to NULL. Add output types and size of output.
outputNames.push_back("__BuiltinFunction_QuatToCosineMatrix_output_1_cosmat__");outputArgMap.insert(std::make_pair("__BuiltinFunction_QuatToCosineMatrix_output_1_cosmat__", (ElementWrapper*) NULL));outputWrapperTypes.push_back(Gmat::ARRAY_WT);outputRowCounts.push_back(3);outputColCounts.push_back(3);
- In copy constructor and assignment operator, copy member data.
- In Execute(), check for output type and size. Check if input object exist in the object store. If it exist get object pointer and check for its type. Input must be a type of Gmat::ARRAY.
std::string msg;GmatBase *obj = NULL;Array *input_quat = NULL;for (unsigned int i = 0; i < inputNames.size(); i++){std::string objName = inputNames[i];ObjectMap::iterator objIter = objectStore->find(objName);if (objIter != objectStore->end()){obj = objIter->second;if (obj == NULL){msg = msg + "Cannot find the object '" + objName + "' in the objectStore\n";}else{// Check for Array typeif (obj->IsOfType(Gmat::ARRAY)){input_quat = (Array*)obj;}else{msg = msg + "The object '" + objName + "' is not valid type to retrieve QuatToCosineMatrix()\n";}}}}
- Get row and column number from the input array.
- Convert input quaternion to cosine matrix by calling AttitudeConversionUtility::ToCosineMatrix().
- Create local output Array to hold value of cosine matrix.
- Create output array wrapper and set it to wrapper pointer in outputArgMap which was initially set to NULL.
- In base/factory/FunctionFactory.cpp, add “#include “QuatToCosineMatrix.hpp” and add new builtin function type “QuatToCosineMatrix” in FunctionFactory::CreateFunction() to create an instance of QuatToCosineMatrix. In FunctionFactory::BuildCreatables(), add “QuatToCosineMatrix” to creatable list.
- Add function/QuatToCosineMatirx.cpp to base/CMakeList.txt.
- Build GMAT.
- Create a script to test QuatToCosineMatrix() function in the script and run the test.