GCOP  1.0
system_extstep.h
Go to the documentation of this file.
00001 #ifndef GCOP_SYSTEM_EXTSTEP_H
00002 #define GCOP_SYSTEM_EXTSTEP_H
00003 #include "system.h"
00004 #include <iostream>
00005 
00006 namespace gcop {
00007   template <typename T, 
00008     int _nx = Dynamic, 
00009     int _nu = Dynamic,
00010     int _np = Dynamic> 
00011     class System_extstep : public System<T,_nx,_nu,_np>
00012     {
00013       public:
00014         typedef Matrix<double, _nx, 1> Vectornd;
00015         typedef Matrix<double, _nu, 1> Vectorcd;
00016         typedef Matrix<double, _np, 1> Vectormd;
00017 
00018         typedef Matrix<double, _nx, _nx> Matrixnd;
00019         typedef Matrix<double, _nx, _nu> Matrixncd;
00020         typedef Matrix<double, _nu, _nx> Matrixcnd;
00021         typedef Matrix<double, _nu, _nu> Matrixcd;
00022 
00023         typedef Matrix<double, _np, _np> Matrixmd;
00024         typedef Matrix<double, _nx, _np> Matrixnmd;
00025         typedef Matrix<double, _np, _nx> Matrixmnd;
00026 
00027       private: 
00028         typedef boost::function<void(T &, const Vectorcd &, double)> Func_type;
00029         typedef boost::function<void(const T &)> resetFuncType;
00030         Func_type  extstep;
00031         resetFuncType  extreset;
00032         //void (*extstep)(T &, const Tu &, double);// Outstate, Controls, Timestep, 
00033 
00034       public: 
00035         //np is not added but can be added if needed
00036         System_extstep(Manifold<T, _nx> &X, int nu, Func_type steparg, resetFuncType resetarg = NULL): System<T,_nx,_nu,_np>(X,nu) 
00037                                                                                                        ,extstep(steparg), extreset(resetarg){}
00038 
00039         double Step(T &xb, double t, const T &xa,
00040             const Vectorcd &u, double h, const Vectormd *p = 0, 
00041             Matrixnd *A = 0, Matrixncd *B = 0, Matrixnmd *C = 0, bool reset=false)
00042         {
00043           if(!extstep || !extreset)
00044           {
00045             std::cout<<"external step or reset not defined"<<std::endl;
00046             return 0;
00047           }
00048           extreset(xa);//Reset to initial state
00049           extstep(xb, u, h);
00050           //We do not update internal state in finite difference functions
00051           return 0;
00052         }
00053 
00054         double Step(const Vectorcd &u, double h,
00055             const Vectormd *p,
00056             Matrixnd *A, Matrix<double, _nx, _nu> *B, 
00057             Matrix<double, _nx, _np> *C) 
00058         {
00059           if(!extstep)
00060           {
00061             std::cout<<"External step not defined"<<std::endl;
00062           }
00063           extstep(this->x, u, h);
00064           this->t = (this->t + h);
00065           return 0;
00066         }
00067 
00068         double Step(T& xb,
00069             const Vectorcd &u, double h,
00070             const Vectormd *p,
00071             Matrixnd *A, Matrix<double, _nx, _nu> *B, 
00072             Matrix<double, _nx, _np> *C) 
00073         {
00074           extstep(xb, u, h);
00075           this->x = xb;
00076           this->t = (this->t + h);
00077           return 0;
00078         }
00079 
00080         bool Reset(const T& x, double t = 0)
00081         {
00082           extreset(x);
00083           this->x = x;
00084           this->t = t;
00085         }
00086     };
00087 }
00088 #endif