Spacecraft.cpp

Go to the documentation of this file.
00001 
00002 #pragma ident "$Id: Spacecraft.cpp 3140 2012-06-18 15:03:02Z susancummins $"
00003 
00009 //============================================================================
00010 //
00011 //  This file is part of GPSTk, the GPS Toolkit.
00012 //
00013 //  The GPSTk is free software; you can redistribute it and/or modify
00014 //  it under the terms of the GNU Lesser General Public License as published
00015 //  by the Free Software Foundation; either version 2.1 of the License, or
00016 //  any later version.
00017 //
00018 //  The GPSTk is distributed in the hope that it will be useful,
00019 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021 //  GNU Lesser General Public License for more details.
00022 //
00023 //  You should have received a copy of the GNU Lesser General Public
00024 //  License along with GPSTk; if not, write to the Free Software Foundation,
00025 //  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
00026 //
00027 //  Wei Yan - Chinese Academy of Sciences . 2009, 2010
00028 //
00029 //============================================================================
00030 
00031 #include "Spacecraft.hpp"
00032 #include "Exception.hpp"
00033 
00034 namespace gpstk
00035 {
00036 
00037       // Default constructor
00038    Spacecraft::Spacecraft(std::string name)
00039    {
00040       scName = name;
00041 
00042       reflectCoeff= 1.0;      //
00043       dragCoeff   = 2.0;      //
00044       crossArea   = 5;         // m^2
00045       dryMass      = 1000;      // kg
00046 
00047       resetState();
00048 
00049    }
00050 
00051 
00052    void Spacecraft::resetState()
00053    {
00054       // resize
00055       r.resize(3,0.0);
00056       v.resize(3,0.0);
00057       p.resize(0,0.0);
00058 
00059       dr_dr0.resize(9,0.0);      // I
00060       dr_dv0.resize(9,0.0);      // 0
00061       dr_dp0.resize(0,0.0);      // 0
00062 
00063       dv_dr0.resize(9,0.0);      // 0
00064       dv_dv0.resize(9,0.0);      // I
00065       dv_dp0.resize(0,0.0);      // 0
00066 
00067       // set eye elements to 1
00068       dr_dr0(0) = 1.0;
00069       dr_dr0(4) = 1.0;
00070       dr_dr0(8) = 1.0;
00071 
00072       dv_dv0(0) = 1.0;
00073       dv_dv0(4) = 1.0;
00074       dv_dv0(8) = 1.0;
00075    }
00076 
00077    void Spacecraft::initStateVector(Vector<double> rv, Vector<double> dp)
00078    {
00079       // first the size of input vector should be checked
00080       if(rv.size()!=6)
00081       {
00082          Exception e("Error in Spacecraft::initStateVector(): the size of rv should be 6.");
00083          GPSTK_THROW(e);
00084       }
00085 
00086       resetState();
00087       
00088       // set position
00089       r(0) = rv(0);
00090       r(1) = rv(1);
00091       r(2) = rv(2);
00092 
00093       // set velocity
00094       v(0) = rv(3);
00095       v(1) = rv(4);
00096       v(2) = rv(5);
00097       
00098       // set force model parameters
00099       p = dp;
00100 
00101       // set dr_dp0 and dv_dp0
00102       const int np = p.size();
00103 
00104       dr_dp0.resize(3*np,0.0);
00105       dv_dp0.resize(3*np,0.0);
00106 
00107    }  // End of method 'Spacecraft::initStateVector()'
00108 
00109       // Get Transition Matrix
00110    Matrix<double> Spacecraft::getTransitionMatrix()
00111    {
00112       /* Transition Matrix
00113           |                          |
00114           | dr_dr0   dr_dv0   dr_dp0 |
00115           |                          |
00116       phi=| dv_dr0   dv_dv0   dv_dp0 |
00117           |                          |
00118           | 0         0           I    |
00119           |                          |
00120       */
00121       
00122       const int np=p.size();
00123 
00124       Matrix<double> phiMatrix(np+6,np+6,0.0);
00125       
00127       phiMatrix(0,0)=dr_dr0(0);
00128       phiMatrix(0,1)=dr_dr0(1);
00129       phiMatrix(0,2)=dr_dr0(2);
00130       phiMatrix(1,0)=dr_dr0(3);
00131       phiMatrix(1,1)=dr_dr0(4);
00132       phiMatrix(1,2)=dr_dr0(5);
00133       phiMatrix(2,0)=dr_dr0(6);
00134       phiMatrix(2,1)=dr_dr0(7);
00135       phiMatrix(2,2)=dr_dr0(8);
00137       phiMatrix(0,3)=dr_dv0(0);
00138       phiMatrix(0,4)=dr_dv0(1);
00139       phiMatrix(0,5)=dr_dv0(2);
00140       phiMatrix(1,3)=dr_dv0(3);
00141       phiMatrix(1,4)=dr_dv0(4);
00142       phiMatrix(1,5)=dr_dv0(5);
00143       phiMatrix(2,3)=dr_dv0(6);
00144       phiMatrix(2,4)=dr_dv0(7);
00145       phiMatrix(2,5)=dr_dv0(8);
00147       phiMatrix(3,0)=dv_dr0(0);
00148       phiMatrix(3,1)=dv_dr0(1);
00149       phiMatrix(3,2)=dv_dr0(2);
00150       phiMatrix(4,0)=dv_dr0(3);
00151       phiMatrix(4,1)=dv_dr0(4);
00152       phiMatrix(4,2)=dv_dr0(5);
00153       phiMatrix(5,0)=dv_dr0(6);
00154       phiMatrix(5,1)=dv_dr0(7);
00155       phiMatrix(5,2)=dv_dr0(8);
00157       phiMatrix(3,3)=dv_dv0(0);
00158       phiMatrix(3,4)=dv_dv0(1);
00159       phiMatrix(3,5)=dv_dv0(2);
00160       phiMatrix(4,3)=dv_dv0(3);
00161       phiMatrix(4,4)=dv_dv0(4);
00162       phiMatrix(4,5)=dv_dv0(5);
00163       phiMatrix(5,3)=dv_dv0(6);
00164       phiMatrix(5,4)=dv_dv0(7);
00165       phiMatrix(5,5)=dv_dv0(8);
00166 
00168       for(int i=0;i<np;i++)
00169       {
00170          phiMatrix(0,i+6) = dr_dp0(i+0*np);
00171          phiMatrix(1,i+6) = dr_dp0(i+1*np);
00172          phiMatrix(2,i+6) = dr_dp0(i+2*np);
00173 
00174          phiMatrix(3,i+6) = dv_dp0(i+0*np);
00175          phiMatrix(4,i+6) = dv_dp0(i+1*np);
00176          phiMatrix(5,i+6) = dv_dp0(i+2*np);
00177 
00178          phiMatrix(i+6,i+6) = 1.0;
00179          phiMatrix(i+6,i+6) = 1.0;
00180          phiMatrix(i+6,i+6) = 1.0;
00181       }
00182 
00183       return phiMatrix;
00184 
00185    }  // End of method 'Spacecraft::getTransitionMatrix()'
00186 
00187 
00188    void Spacecraft::setTransitionMatrix(Matrix<double> phiMatrix)
00189    {
00190       /* Transition Matrix
00191           |                          |
00192           | dr_dr0   dr_dv0   dr_dp0 |
00193           |                          |
00194       phi=| dv_dr0   dv_dv0   dv_dp0 |
00195           |                          |
00196           | 0         0          I     |
00197           |                          |
00198       */
00199 
00200       const int np = phiMatrix.rows()-6;
00201 
00202       // resize the vectors
00203       p.resize(np,0.0);
00204       dr_dp0.resize(3*np,0.0);
00205       dv_dp0.resize(3*np,0.0);
00206 
00207       // dr/dr0
00208       dr_dr0(0) = phiMatrix(0,0);
00209       dr_dr0(1) = phiMatrix(0,1);
00210       dr_dr0(2) = phiMatrix(0,2);
00211       dr_dr0(3) = phiMatrix(1,0);
00212       dr_dr0(4) = phiMatrix(1,1);
00213       dr_dr0(5) = phiMatrix(1,2);
00214       dr_dr0(6) = phiMatrix(2,0);
00215       dr_dr0(7) = phiMatrix(2,1);
00216       dr_dr0(8) = phiMatrix(2,2);
00217       // dr/dv0
00218       dr_dv0(0) = phiMatrix(0,3);
00219       dr_dv0(1) = phiMatrix(0,4);
00220       dr_dv0(2) = phiMatrix(0,5);
00221       dr_dv0(3) = phiMatrix(1,3);
00222       dr_dv0(4) = phiMatrix(1,4);
00223       dr_dv0(5) = phiMatrix(1,5);
00224       dr_dv0(6) = phiMatrix(2,3);
00225       dr_dv0(7) = phiMatrix(2,4);
00226       dr_dv0(8) = phiMatrix(2,5);
00227       // dv/dr0
00228       dv_dr0(0) = phiMatrix(3,0);
00229       dv_dr0(1) = phiMatrix(3,1);
00230       dv_dr0(2) = phiMatrix(3,2);
00231       dv_dr0(3) = phiMatrix(4,0);
00232       dv_dr0(4) = phiMatrix(4,1);
00233       dv_dr0(5) = phiMatrix(4,2);
00234       dv_dr0(6) = phiMatrix(5,0);
00235       dv_dr0(7) = phiMatrix(5,1);
00236       dv_dr0(8) = phiMatrix(5,2);
00237       // dv/dv0
00238       dv_dv0(0) = phiMatrix(3,3);
00239       dv_dv0(1) = phiMatrix(3,4);
00240       dv_dv0(2) = phiMatrix(3,5);
00241       dv_dv0(3) = phiMatrix(4,3);
00242       dv_dv0(4) = phiMatrix(4,4);
00243       dv_dv0(5) = phiMatrix(4,5);
00244       dv_dv0(6) = phiMatrix(5,3);
00245       dv_dv0(7) = phiMatrix(5,4);
00246       dv_dv0(8) = phiMatrix(5,5);
00247 
00248       // dr/dp0
00249       for(int i=0;i<np;i++)
00250       {
00251          dr_dp0(i+0*np) = phiMatrix(0,i+6);
00252          dr_dp0(i+1*np) = phiMatrix(1,i+6);
00253          dr_dp0(i+2*np) = phiMatrix(2,i+6);
00254 
00255          dv_dp0(i+0*np) = phiMatrix(3,i+6);
00256          dv_dp0(i+1*np) = phiMatrix(4,i+6);
00257          dv_dp0(i+2*np) = phiMatrix(5,i+6);
00258       }
00259 
00260    }  // End of method 'Spacecraft::setTransitionMatrix()'
00261 
00262 
00263    // get State Transition Matrix 6*6
00264    Matrix<double> Spacecraft::getStateTransitionMatrix()
00265    {
00266       /* Transition Matrix
00267           |                  |
00268           | dr_dr0   dr_dv0  |
00269       phi=|                  |
00270           | dv_dr0   dv_dv0  |
00271           |                  |
00272       */
00273       const int np=p.size();
00274 
00275       Matrix<double> phiMatrix(6,6,0.0);
00276 
00278       phiMatrix(0,0)=dr_dr0(0);
00279       phiMatrix(0,1)=dr_dr0(1);
00280       phiMatrix(0,2)=dr_dr0(2);
00281       phiMatrix(1,0)=dr_dr0(3);
00282       phiMatrix(1,1)=dr_dr0(4);
00283       phiMatrix(1,2)=dr_dr0(5);
00284       phiMatrix(2,0)=dr_dr0(6);
00285       phiMatrix(2,1)=dr_dr0(7);
00286       phiMatrix(2,2)=dr_dr0(8);
00288       phiMatrix(0,3)=dr_dv0(0);
00289       phiMatrix(0,4)=dr_dv0(1);
00290       phiMatrix(0,5)=dr_dv0(2);
00291       phiMatrix(1,3)=dr_dv0(3);
00292       phiMatrix(1,4)=dr_dv0(4);
00293       phiMatrix(1,5)=dr_dv0(5);
00294       phiMatrix(2,3)=dr_dv0(6);
00295       phiMatrix(2,4)=dr_dv0(7);
00296       phiMatrix(2,5)=dr_dv0(8);
00298       phiMatrix(3,0)=dv_dr0(0);
00299       phiMatrix(3,1)=dv_dr0(1);
00300       phiMatrix(3,2)=dv_dr0(2);
00301       phiMatrix(4,0)=dv_dr0(3);
00302       phiMatrix(4,1)=dv_dr0(4);
00303       phiMatrix(4,2)=dv_dr0(5);
00304       phiMatrix(5,0)=dv_dr0(6);
00305       phiMatrix(5,1)=dv_dr0(7);
00306       phiMatrix(5,2)=dv_dr0(8);
00308       phiMatrix(3,3)=dv_dv0(0);
00309       phiMatrix(3,4)=dv_dv0(1);
00310       phiMatrix(3,5)=dv_dv0(2);
00311       phiMatrix(4,3)=dv_dv0(3);
00312       phiMatrix(4,4)=dv_dv0(4);
00313       phiMatrix(4,5)=dv_dv0(5);
00314       phiMatrix(5,3)=dv_dv0(6);
00315       phiMatrix(5,4)=dv_dv0(7);
00316       phiMatrix(5,5)=dv_dv0(8);
00317 
00318       return phiMatrix;
00319 
00320    }  // End of method 'Spacecraft::getStateTransitionMatrix()'
00321 
00322    // get Sensitivity Matrix 6*np
00323    Matrix<double> Spacecraft::getSensitivityMatrix()
00324    {
00325       /* Transition Matrix
00326           |        |
00327           | dr_dp0 |
00328       s = |        |
00329           | dv_dp0 |
00330           |        |
00331       */
00332       const int np=p.size();
00333 
00334       Matrix<double> sMatrix(6,np,0.0);
00335       
00336       for(int i=0;i<np;i++)
00337       {
00338          sMatrix(0,i) = dr_dp0(i+0*np);
00339          sMatrix(1,i) = dr_dp0(i+1*np);
00340          sMatrix(2,i) = dr_dp0(i+2*np);
00341 
00342          sMatrix(3,i) = dv_dp0(i+0*np);
00343          sMatrix(4,i) = dv_dp0(i+1*np);
00344          sMatrix(5,i) = dv_dp0(i+2*np);
00345       }
00346 
00347       return sMatrix;
00348 
00349    }  // End of method 'Spacecraft::getSensitivityMatrix()'
00350 
00351 
00352    Vector<double> Spacecraft::getStateVector()
00353    {
00354       const int np=p.size();
00355       Vector<double> y(6*np+42);
00356 
00357       y(0) = r(0);
00358       y(1) = r(1);
00359       y(2) = r(2);
00360       y(3) = v(0);
00361       y(4) = v(1); 
00362       y(5) = v(2);
00363       
00364       for(int i=0;i<9;i++)
00365       {
00366          y(6+i) = dr_dr0(i);
00367          y(15+i) = dr_dv0(i);
00368          
00369          y(24+3*np+i) = dv_dr0(i);
00370          y(33+3*np+i) = dv_dv0(i);
00371       }
00372       for(int i=0;i<3*np;i++)
00373       {
00374          y(24+i) = dr_dp0(i);
00375          y(42+3*np+i) = dv_dp0(i);
00376       }
00377 
00378       return y;
00379 
00380    }  // End of method 'Spacecraft::getStateVector()'
00381 
00382 
00383    void Spacecraft::setStateVector(Vector<double> y)
00384    {
00385       const int dim = y.size();
00386       const int np = (dim-42)/6;
00387       
00388       // resize the vectors
00389       p.resize(np,0.0);
00390       dr_dp0.resize(3*np,0.0);
00391       dv_dp0.resize(3*np,0.0);
00392       
00393       r(0) = y(0);
00394       r(1) = y(1);
00395       r(2) = y(2);
00396       v(0) = y(3);
00397       v(1) = y(4);
00398       v(2) = y(5);
00399 
00400       for(int i=0;i<9;i++)
00401       {
00402          dr_dr0(i) = y(6+i);
00403          dr_dv0(i) = y(15+i);
00404 
00405          dv_dr0(i) = y(24+3*np+i);
00406          dv_dv0(i) = y(33+3*np+i);
00407       }
00408       
00409       for(int i=0;i<3*np;i++)
00410       {
00411          dr_dp0(i) = y(24+i);
00412          dv_dp0(i) = y(42+3*np+i);
00413       }
00414 
00415    }  // End of method 'Spacecraft::setStateVector(Vector<double> y)'
00416 
00417    void Spacecraft::test()
00418    {
00419       cout<<"testing Spacecraft"<<endl;
00420       
00421       /*
00422       r.resize(3,8.0);
00423       v.resize(3,8.0);
00424       p.resize(2,0.0);
00425 
00426       dr_dr0.resize(9,0.0);      // I
00427       dr_dv0.resize(9,0.0);      // 0
00428       dr_dp0.resize(6,3.0);      // 0
00429 
00430       dv_dr0.resize(9,0.0);      // 0
00431       dv_dv0.resize(9,0.0);      // I
00432       dv_dp0.resize(6,4.0);      // 0
00433 
00434       // set eye elements to 1
00435       dr_dr0(0) = 1.0;
00436       dr_dr0(4) = 1.0;
00437       dr_dr0(8) = 1.0;
00438 
00439       dv_dv0(0) = 1.0;
00440       dv_dv0(4) = 1.0;
00441       dv_dv0(8) = 1.0;
00442       
00443    
00444       writeToFile("default.sc");
00445 
00446       // it work well
00447       */
00448 
00449    }   // End of method 'Spacecraft::test()'
00450 
00451 
00452       // Stream output for CommonTime objects.  Typically used for debugging.
00453       // @param s stream to append formatted CommonTime to.
00454       // @param t Spacecraft to append to stream \c s.
00455       // @return reference to \c s.
00456    ostream& operator<<( ostream& s, 
00457                         const gpstk::Spacecraft& sc )
00458    {
00459       // s << endl;
00460 
00461       return s;
00462 
00463    }  // End of 'ostream& operator<<()'
00464 
00465 }  // End of namespace 'gpstk'
00466 

Generated on Mon May 20 03:31:12 2013 for GPS ToolKit Software Library by  doxygen 1.3.9.1