00001 ////////////////////////////////////////////////////////////////////////////////////////////////// 00002 /*! \file Environment.h 00003 * \brief Interface to the Environment encapsulation object. 00004 * \author $Author: jayhawk_hokie $ 00005 * \version $Revision: 1.2 $ 00006 * \date $Date: 2005/06/10 12:53:28 $ 00007 *////////////////////////////////////////////////////////////////////////////////////////////////// 00008 /* \todo Add name strings and outputting of "turned-on" disturbances 00009 * \todo Add reference counter to ensure deletion when not used anymore. 00010 * \todo Add CreateIterator() function 00011 */ 00012 ////////////////////////////////////////////////////////////////////////////////////////////////// 00013 00014 #ifndef __ENVIRONMENT_H__ 00015 #define __ENVIRONMENT_H__ 00016 00017 #include <rotation/Rotation.h> 00018 #include <utils/Integrator.h> 00019 #include <matrix/Matrix.h> 00020 #include <utils/Time.h> 00021 #include <set> 00022 #include <vector> 00023 00024 using namespace std; 00025 00026 namespace O_SESSAME { 00027 class CentralBody; 00028 00029 ////////////////////////////////////////////////////////////////////////////////////////////////// 00030 /*! @defgroup EnvironmentToolkit Environment Toolkit 00031 * The Environment Toolkit is the collection of classes and functions that assist in modeling a 00032 * spacecraft's external environment. This includes the central bodies, disturbance forces and 00033 * disturbance torques. 00034 * 00035 * \par Extension Points: 00036 * The current toolkit provides functionality for the main planets of the solar system as 00037 * central bodies. There are other central bodies such as moons, asteroids, comets, or stars that 00038 * could be added by deriving from the CentralBody interface class. Furthermore, only a couple of 00039 * the primary disturbance torque and force functions have been implemented. There are numerous 00040 * models of varying complexity that could be added. The only stipulation is that these new disturbance 00041 * functions match the parameterization specified by pt2EnvFunc. 00042 */ 00043 00044 /*! specification of the parameter list type to be used for environmental function pointers */ 00045 typedef vector<void*> EnvFuncParamaterType; 00046 /*! defines a pointer to a Environmental disturbance calculating function */ 00047 typedef Vector(*pt2EnvFunc)(const ssfTime &_currentTime, const OrbitState &_currentOrbitState, const AttitudeState &_currentAttitudeState, const EnvFuncParamaterType &_parameterList); 00048 00049 /*! \brief Encapsulation of an environmental disturbance function. 00050 * \ingroup EnvironmentToolkit 00051 * 00052 * An EnvFunction is used to store a function pointer and the list of parameters 00053 * that are used in evaluating an environmental disturbance function. The 00054 * function can either be a force or torque disturbance. Examples include:<p> 00055 * 00056 * \par (force) Gravity, aerodynamic drag, solar radiation pressure 00057 * \par (torque) Gravity gradient, magnetic, aerodynamic, fuel slosh <p> 00058 * 00059 * \oar The parameters are the constants (such as Ballistic coefficient, 00060 * magnetic dipole, cross-sectional area), in the appropriate function 00061 * order, and can be set or removed individually. Furthermore, because 00062 * they are actually pointers to data, once the pointer is set, the data 00063 * can still change (for example the mass of the spacecraft) without 00064 * having to alter the EnvFunction parameter list.</p> 00065 * 00066 * \par Usage: 00067 * To use the EnvFunction class, the user first creates a disturbance 00068 * function that matches the prototype of pt2EnvFunc, which takes the 00069 * current time, orbit state, attitude state, and an STL vector 00070 * of pointers to the parameters. They then must create an instance of 00071 * an EnvFunction with a pointer to the function: 00072 * \code 00073 EnvFunction DragForce(&myDisturbanceFunction); 00074 * \endcode 00075 * and then fill out the parameter list: 00076 * \code 00077 DragForce.AddParameter(reinterpret_cast<void*>(*CrossArea), 1); 00078 * \endcode 00079 * Notice it is important to only give a pointer to a value that will 00080 * stay "in scope" as long as needed for the simulation. Also, the 00081 * reinterpret_cast<void*>() is needed to make the value 'look like' a void 00082 * pointer. Don't worry too much about this, but read Stroustrop if 00083 * you'd like to know more. 00084 * 00085 * \par Example disturbance function: 00086 \code 00087 // Force function that will be called each timestep 00088 Vector DragForceFunction(const ssfTime* _currentTime, const OrbitState* _currentOrbitState, const AttitudeState* _currentAttitudeState, EnvFuncParamaterType _parameterList) 00089 { 00090 Vector Forces(3); 00091 double BC = *(reinterpret_cast<double*>(_parameterList[1])); 00092 double Density = *(reinterpret_cast<double*>(_parameterList[2])); // kg/m^3 00093 Vector Vrel(3); Vrel = _currentOrbitState->GetState()(_(VectorIndexBase+3,VectorIndexBase+5)); 00094 double Vrel_mag = norm2(Vrel); 00095 Forces = -1/2 * rho / BC * pow(Vrel_mag,2) * Vrel / Vrel_mag; 00096 return Forces; 00097 } 00098 \endcode 00099 * 00100 * \example testEnvironment.cpp 00101 * Example using an Environment object for integration. 00102 * 00103 * \example testPropagation.cpp 00104 * Example propagation of a combined satellite orbit \& attitude. 00105 */ 00106 class EnvFunction 00107 { 00108 public: 00109 EnvFunction(pt2EnvFunc _EnvFuncPtr); 00110 00111 EnvFunction(pt2EnvFunc _EnvFuncPtr, const int & _numParameters); 00112 00113 Vector Evaluate(const ssfTime &_currentTime, const OrbitState &_currentOrbitState, const AttitudeState &_currentAttitudeState); 00114 00115 void AddParameter(void* _parameter, int _paramNumber = -1); 00116 00117 void RemoveParameter(int _paramNumber = -1); 00118 00119 void ChangeParameter(void* _parameter, int _paramNumber = -1); 00120 private: 00121 /*! \brief internal pointer to the environmental disturbance function */ 00122 pt2EnvFunc m_EnvFuncPtr; 00123 /*! \brief internal storage of the number of parameters in the list */ 00124 int m_NumParameters; 00125 /*! \brief list of pointers to the parameters */ 00126 EnvFuncParamaterType m_EnvFuncParameters; 00127 00128 }; 00129 00130 ////////////////////////////////////////////////////////////////////////////////////////////////// 00131 /*! @defgroup EnvironmentForceFunctions Environment Force Disturbance Functions 00132 * @ingroup EnvironmentToolkit 00133 * 00134 * 00135 */ 00136 /*! @defgroup EnvironmentTorqueFunctions Environment Torque Disturbance Functions 00137 * @ingroup EnvironmentToolkit 00138 * 00139 * 00140 */ 00141 ////////////////////////////////////////////////////////////////////////////////////////////////// 00142 00143 /*!\brief Encapsulation of a spacecraft environment (disturbance forces, torques, central body, etc.) 00144 * \ingroup EnvironmentToolkit Environment Toolkit 00145 * 00146 * The Environment class is used to contain all the different aspects of the external 00147 * environment of the spacecraft. This currently includes disturbance forces (gravity, drag, solar radiation pressure), 00148 * disturbance torques (gravity gradient, magnetic dipole, fuel slosh), and central body (for constants). 00149 * 00150 * To use the Environment class, the user should create (or include) and assign the desired force and torque 00151 * disturbance functions (EnvFunction), and CentralBody. The integrator or propagator would then use the GetTorque() and 00152 * GetForce() functions to modify the dynamics. 00153 * 00154 * \par Example: 00155 \code 00156 * Environment* pEarthEnv = new Environment; 00157 * EarthCentralBody *pCBEarth = new EarthCentralBody; 00158 * pEarthEnv->SetCentralBody(pCBEarth); 00159 00160 * // Add Gravity force function 00161 * EnvFunction TwoBodyGravity(&GravityForceFunction); 00162 * double Mass = 100; \\kg 00163 * TwoBodyGravity.AddParameter(reinterpret_cast<void*>(&Mass), 1); 00164 * pEarthEnv->AddForceFunction(TwoBodyGravity); 00165 00166 * // Add Drag Force Function 00167 * EnvFunction DragForce(&DragForceFunction); 00168 * double BallisticCoefficient = 200; 00169 * DragForce.AddParameter(reinterpret_cast<void*>(&BallisticCoefficient), 1); 00170 * pEarthEnv->AddForceFunction(DragForce); 00171 00172 * // Add Magnetic Dipole 00173 * EnvFunction MagDipole(&MagneticDipoleFunction); 00174 * MagDiple.AddParameter(reinterpret_cast<void*>(&Spacecraft.GetDipole(), 1); 00175 * pEarthEnv->AddTorqueFunction(MagDipole); 00176 \endcode 00177 * 00178 */ 00179 class Environment 00180 { 00181 public: 00182 Environment(); 00183 00184 virtual ~Environment(); 00185 00186 Vector GetTorques(const ssfTime& _currentTime, const OrbitState& _currentOrbitState, const AttitudeState& _currentAttitudeState); 00187 00188 Vector GetForces(const ssfTime& _currentTime, const OrbitState& _currentOrbitState, const AttitudeState& _currentAttitudeState); 00189 00190 void AddForceFunction(const EnvFunction &_forceFunc); 00191 00192 void AddTorqueFunction(const EnvFunction &_torqueFunc); 00193 00194 const Functor& GetForceFunction() const; 00195 00196 const Functor& GetTorqueFunction() const; 00197 00198 void SetCentralBody(CentralBody *_pCB); 00199 00200 const CentralBody* GetCentralBody() const; 00201 00202 private: 00203 /*! \brief internal vector of the pointers to the force disturbance functions */ 00204 vector<EnvFunction> m_ForceFunctions; 00205 /*! \brief internal vector of the pointers to the torque disturbance functions */ 00206 vector<EnvFunction> m_TorqueFunctions; 00207 /*! \brief internal iterator for stepping through the disturbance function vectors */ 00208 vector<EnvFunction>::iterator m_funcIterator; 00209 /*! \brief internal pointer to the environment central body */ 00210 CentralBody *m_pCB; 00211 00212 /*! \brief internal Vector of the most recent calculated disturbance forces */ 00213 Vector m_CalculatedForces; 00214 /*! \brief internal Vector of the most recent calculated disturbance torques */ 00215 Vector m_CalculatedTorques; 00216 /*! \brief internal pointer to the Environment::GetForces() function */ 00217 ObjectFunctor<Environment> m_ForcesFunctor; 00218 /*! \brief internal pointer to the Environment::GetTorques() function */ 00219 ObjectFunctor<Environment> m_TorquesFunctor; 00220 00221 00222 }; 00223 } // close namespace O_SESSAME 00224 #endif 00225 // Do not change the comments below - they will be added automatically by CVS 00226 /***************************************************************************** 00227 * $Log: Environment.h,v $ 00228 * Revision 1.2 2005/06/10 12:53:28 jayhawk_hokie 00229 * Changed header file format to make it easier to link to the spacecraft code by only having to specify dsacss/dep/spacecraft/src (ex. "file.h" changed to <dir/file.h> where dir is a folder in src). 00230 * 00231 * Revision 1.1.1.1 2005/04/26 17:40:56 cakinli 00232 * Adding OpenSESSAME to DSACSS distrib to capture fixed version. 00233 * 00234 * Revision 1.13 2003/10/18 21:37:28 rsharo 00235 * Removed "../utils" from all qmake project paths. Prepended "utils 00236 * /" to all #include directives for utils. Removed ".h" extensions from STL header 00237 * s and referenced STL components from "std::" namespace. Overall, changed to be 00238 * more portable. 00239 * 00240 * Revision 1.12 2003/06/12 18:06:35 nilspace 00241 * . 00242 * 00243 * Revision 1.11 2003/06/10 14:48:03 nilspace 00244 * Changed include CentralBody.h to look in CentralBody directory. 00245 * 00246 * Revision 1.10 2003/06/06 17:35:52 nilspace 00247 * Moved to CentralBody directory. 00248 * 00249 * Revision 1.9 2003/05/22 21:04:16 nilspace 00250 * Updated comments. 00251 * 00252 * Revision 1.8 2003/05/22 03:42:32 nilspace 00253 * Moved documentation to the implementation file. 00254 * 00255 * Revision 1.7 2003/05/20 17:51:12 nilspace 00256 * Updated comments. 00257 * 00258 * Revision 1.6 2003/05/13 18:59:16 nilspace 00259 * Fixed some comments. 00260 * 00261 * Revision 1.5 2003/05/05 20:45:46 nilspace 00262 * Changed the pass-by-address parameters to pass-by-reference. 00263 * 00264 * Revision 1.4 2003/05/02 16:16:28 nilspace 00265 * Documented the API. 00266 * 00267 * Revision 1.3 2003/05/02 02:16:29 nilspace 00268 * Documented the API. 00269 * Added a GetTorquesFunction(). 00270 * 00271 * Revision 1.2 2003/04/27 22:04:33 nilspace 00272 * Created the namespace O_SESSAME. 00273 * 00274 * Revision 1.1 2003/04/08 22:37:22 nilspace 00275 * Initial Submission. 00276 * 00277 * 00278 ******************************************************************************/