GCOP
1.0
|
00001 #ifndef GCOP_TPARAM_H 00002 #define GCOP_TPARAM_H 00003 00004 #include "system.h" 00005 00006 namespace gcop { 00007 00008 using namespace std; 00009 using namespace Eigen; 00010 00020 template <typename T, 00021 int nx = Dynamic, 00022 int nu = Dynamic, 00023 int np = Dynamic, 00024 int _ntp = Dynamic, 00025 typename Tc = T> class Tparam { 00026 00027 typedef Matrix<double, nx, 1> Vectornd; 00028 typedef Matrix<double, nu, 1> Vectorcd; 00029 typedef Matrix<double, nx, nx> Matrixnd; 00030 typedef Matrix<double, nx, nu> Matrixncd; 00031 typedef Matrix<double, nu, nx> Matrixcnd; 00032 typedef Matrix<double, nu, nu> Matrixcd; 00033 00034 typedef Matrix<double, np, 1> Vectormd; 00035 00036 typedef Matrix<double, _ntp, 1> Vectorntpd; 00037 00038 public: 00039 Tparam(System<T, nx, nu, np> &sys, int ntp = 0); 00040 00050 virtual bool To(Vectorntpd &s, 00051 const vector<double> &ts, 00052 const vector<T> &xs, 00053 const vector<Vectorcd> &us, 00054 const Vectormd *p = 0); 00055 00065 virtual bool From(vector<double> &ts, 00066 vector<T> &xs, 00067 vector<Vectorcd> &us, 00068 const Vectorntpd &s, 00069 Vectormd *p = 0); 00070 00071 virtual bool SetContext(const Tc &c) { return true; } 00072 00073 System<T, nx, nu, np> &sys; 00074 int ntp; 00075 }; 00076 00077 template <typename T, int nx, int nu, int np, int _ntp, typename Tc> 00078 Tparam<T, nx, nu, np, _ntp, Tc>::Tparam(System<T, nx, nu, np> &sys, int ntp) : 00079 sys(sys), ntp(_ntp != Dynamic ? _ntp : ntp) { 00080 assert(ntp > 0); 00081 std::cout<<"ntp: "<<ntp<<std::endl;//#DEBUG 00082 } 00083 00084 template <typename T, int nx, int nu, int np, int _ntp, typename Tc> 00085 bool Tparam<T, nx, nu, np, _ntp, Tc>::To(Vectorntpd &s, 00086 const vector<double> &ts, 00087 const vector<T> &xs, 00088 const vector<Vectorcd> &us, 00089 const Vectormd *p) { 00090 assert(ntp == us.size()*sys.U.n); 00091 for (int i = 0; i < us.size(); ++i) { 00092 memcpy(s.data() + i*sys.U.n, us[i].data(), sys.U.n*sizeof(double)); 00093 } 00094 return true; 00095 // assume parameter p does not play a role 00096 } 00097 00098 template <typename T, int nx, int nu, int np, int _ntp, typename Tc> 00099 bool Tparam<T, nx, nu, np, _ntp, Tc>::From(vector<double> &ts, 00100 vector<T> &xs, 00101 vector<Vectorcd> &us, 00102 const Vectorntpd &s, 00103 Vectormd *p) { 00104 assert(ntp == us.size()*sys.U.n); 00105 sys.Reset(xs[0],ts[0]); 00106 for (int i = 0; i < us.size(); ++i) { 00107 memcpy(us[i].data(), s.data() + i*sys.U.n, sys.U.n*sizeof(double)); 00108 sys.Step(xs[i+1], us[i], ts[i+1] - ts[i], p); 00109 } 00110 return true; 00111 } 00112 } 00113 00114 #endif