Alex Pirciu
/
BFMC
a
include/SystemModels/systemmodels.hpp@1:ceee5a608e7c, 2019-03-28 (annotated)
- Committer:
- alexpirciu
- Date:
- Thu Mar 28 07:44:42 2019 +0000
- Revision:
- 1:ceee5a608e7c
assa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alexpirciu | 1:ceee5a608e7c | 1 | /** |
alexpirciu | 1:ceee5a608e7c | 2 | ****************************************************************************** |
alexpirciu | 1:ceee5a608e7c | 3 | * @file SystemModels/systemmodels.hpp |
alexpirciu | 1:ceee5a608e7c | 4 | * @author RBRO/PJ-IU |
alexpirciu | 1:ceee5a608e7c | 5 | * @version V1.0.0 |
alexpirciu | 1:ceee5a608e7c | 6 | * @date day-month-2017 |
alexpirciu | 1:ceee5a608e7c | 7 | * @brief This file contains the class declarations for system model. |
alexpirciu | 1:ceee5a608e7c | 8 | ****************************************************************************** |
alexpirciu | 1:ceee5a608e7c | 9 | */ |
alexpirciu | 1:ceee5a608e7c | 10 | |
alexpirciu | 1:ceee5a608e7c | 11 | /* Inclusion guard */ |
alexpirciu | 1:ceee5a608e7c | 12 | #ifndef SYSTEM_MODELS_HPP |
alexpirciu | 1:ceee5a608e7c | 13 | #define SYSTEM_MODELS_HPP |
alexpirciu | 1:ceee5a608e7c | 14 | |
alexpirciu | 1:ceee5a608e7c | 15 | #include <Linalg/linalg.h> |
alexpirciu | 1:ceee5a608e7c | 16 | |
alexpirciu | 1:ceee5a608e7c | 17 | // Discrete System Models |
alexpirciu | 1:ceee5a608e7c | 18 | namespace systemmodels{ |
alexpirciu | 1:ceee5a608e7c | 19 | //Linear time variant models |
alexpirciu | 1:ceee5a608e7c | 20 | namespace lti{ |
alexpirciu | 1:ceee5a608e7c | 21 | namespace siso{ |
alexpirciu | 1:ceee5a608e7c | 22 | /** |
alexpirciu | 1:ceee5a608e7c | 23 | * @brief Discrete transfer function |
alexpirciu | 1:ceee5a608e7c | 24 | * |
alexpirciu | 1:ceee5a608e7c | 25 | * @tparam T The type of the variable |
alexpirciu | 1:ceee5a608e7c | 26 | * @tparam NNum The order of the polynomial |
alexpirciu | 1:ceee5a608e7c | 27 | * @tparam NDen The order of the polynomial |
alexpirciu | 1:ceee5a608e7c | 28 | */ |
alexpirciu | 1:ceee5a608e7c | 29 | template <class T,uint32_t NNum,uint32_t NDen> |
alexpirciu | 1:ceee5a608e7c | 30 | class CDiscreteTransferFucntion{ |
alexpirciu | 1:ceee5a608e7c | 31 | public: |
alexpirciu | 1:ceee5a608e7c | 32 | using CDenType = linalg::CMatrix<T,NDen,1>; |
alexpirciu | 1:ceee5a608e7c | 33 | using CDenModType = linalg::CMatrix<T,NDen-1,1>; |
alexpirciu | 1:ceee5a608e7c | 34 | using CNumType = linalg::CMatrix<T,NNum,1>; |
alexpirciu | 1:ceee5a608e7c | 35 | // using CNumModType = linalg::CMatrix<T,NNum-1,1>; |
alexpirciu | 1:ceee5a608e7c | 36 | using CInputMem = linalg::CMatrix<T,1,NNum>; |
alexpirciu | 1:ceee5a608e7c | 37 | using COutputMem = linalg::CMatrix<T,1,NDen-1>; |
alexpirciu | 1:ceee5a608e7c | 38 | /* Constructor */ |
alexpirciu | 1:ceee5a608e7c | 39 | CDiscreteTransferFucntion(); |
alexpirciu | 1:ceee5a608e7c | 40 | |
alexpirciu | 1:ceee5a608e7c | 41 | CDiscreteTransferFucntion(const CNumType& f_num,const CDenType& f_den); |
alexpirciu | 1:ceee5a608e7c | 42 | |
alexpirciu | 1:ceee5a608e7c | 43 | /* Clear memory */ |
alexpirciu | 1:ceee5a608e7c | 44 | void clearMemmory(); |
alexpirciu | 1:ceee5a608e7c | 45 | /* Shift memory */ |
alexpirciu | 1:ceee5a608e7c | 46 | template<uint32_t N> |
alexpirciu | 1:ceee5a608e7c | 47 | void shiftMemory(linalg::CMatrix<T,1,N>& f_mem); |
alexpirciu | 1:ceee5a608e7c | 48 | /* Operator */ |
alexpirciu | 1:ceee5a608e7c | 49 | T operator()(const T& f_input); |
alexpirciu | 1:ceee5a608e7c | 50 | /* Set num */ |
alexpirciu | 1:ceee5a608e7c | 51 | void setNum(const CNumType& f_num); |
alexpirciu | 1:ceee5a608e7c | 52 | /* Set den */ |
alexpirciu | 1:ceee5a608e7c | 53 | void setDen(const CDenType& f_den); |
alexpirciu | 1:ceee5a608e7c | 54 | |
alexpirciu | 1:ceee5a608e7c | 55 | const CNumType& getNum(); |
alexpirciu | 1:ceee5a608e7c | 56 | const CDenModType& getDen(); |
alexpirciu | 1:ceee5a608e7c | 57 | float getDenCurrent(); |
alexpirciu | 1:ceee5a608e7c | 58 | /* Get output */ |
alexpirciu | 1:ceee5a608e7c | 59 | T getOutput(); |
alexpirciu | 1:ceee5a608e7c | 60 | |
alexpirciu | 1:ceee5a608e7c | 61 | private: |
alexpirciu | 1:ceee5a608e7c | 62 | |
alexpirciu | 1:ceee5a608e7c | 63 | #ifdef SYSTEMMODEL_TEST_HPP |
alexpirciu | 1:ceee5a608e7c | 64 | FRIEND_TEST(CDiscreteTransferFucntionTest,Reset); |
alexpirciu | 1:ceee5a608e7c | 65 | #endif |
alexpirciu | 1:ceee5a608e7c | 66 | |
alexpirciu | 1:ceee5a608e7c | 67 | /* nominator type */ |
alexpirciu | 1:ceee5a608e7c | 68 | CNumType m_num; |
alexpirciu | 1:ceee5a608e7c | 69 | // CDenType m_den; |
alexpirciu | 1:ceee5a608e7c | 70 | /* denominator type */ |
alexpirciu | 1:ceee5a608e7c | 71 | CDenModType m_den; |
alexpirciu | 1:ceee5a608e7c | 72 | T m_denCoef; |
alexpirciu | 1:ceee5a608e7c | 73 | /* input memory */ |
alexpirciu | 1:ceee5a608e7c | 74 | CInputMem m_memInput; |
alexpirciu | 1:ceee5a608e7c | 75 | /* output memory */ |
alexpirciu | 1:ceee5a608e7c | 76 | COutputMem m_memOutput; |
alexpirciu | 1:ceee5a608e7c | 77 | }; |
alexpirciu | 1:ceee5a608e7c | 78 | } |
alexpirciu | 1:ceee5a608e7c | 79 | |
alexpirciu | 1:ceee5a608e7c | 80 | }; |
alexpirciu | 1:ceee5a608e7c | 81 | // Nonlinea time invariant models |
alexpirciu | 1:ceee5a608e7c | 82 | namespace nlti{ |
alexpirciu | 1:ceee5a608e7c | 83 | //Multi-input and multi-output |
alexpirciu | 1:ceee5a608e7c | 84 | namespace mimo{ |
alexpirciu | 1:ceee5a608e7c | 85 | // Discrete time system model of a system nonlinear time invariant with multi-input and multi-output |
alexpirciu | 1:ceee5a608e7c | 86 | // T -variable type |
alexpirciu | 1:ceee5a608e7c | 87 | // NA -number of inputs |
alexpirciu | 1:ceee5a608e7c | 88 | // NB -number of states |
alexpirciu | 1:ceee5a608e7c | 89 | // NC -number of outputs |
alexpirciu | 1:ceee5a608e7c | 90 | template <class T,uint32_t NA, uint32_t NB,uint32_t NC> |
alexpirciu | 1:ceee5a608e7c | 91 | class CDiscreteTimeSystemModel{ |
alexpirciu | 1:ceee5a608e7c | 92 | public: |
alexpirciu | 1:ceee5a608e7c | 93 | using CStatesType = linalg::CMatrix<T,NB,1>; |
alexpirciu | 1:ceee5a608e7c | 94 | using CInputType = linalg::CMatrix<T,NA,1>; |
alexpirciu | 1:ceee5a608e7c | 95 | using COutputType = linalg::CMatrix<T,NC,1>; |
alexpirciu | 1:ceee5a608e7c | 96 | /* Constructor */ |
alexpirciu | 1:ceee5a608e7c | 97 | CDiscreteTimeSystemModel(const double f_dt);//:m_states(),m_dt(f_dt){} |
alexpirciu | 1:ceee5a608e7c | 98 | /* Constructor */ |
alexpirciu | 1:ceee5a608e7c | 99 | CDiscreteTimeSystemModel(const CStatesType& f_states |
alexpirciu | 1:ceee5a608e7c | 100 | ,const double f_dt); |
alexpirciu | 1:ceee5a608e7c | 101 | //State transition model |
alexpirciu | 1:ceee5a608e7c | 102 | //Calculate the system state depending on input, after calculation the relevant class members need to be syncronized. |
alexpirciu | 1:ceee5a608e7c | 103 | virtual CStatesType update(const CInputType& f_input)=0; |
alexpirciu | 1:ceee5a608e7c | 104 | //State observation model |
alexpirciu | 1:ceee5a608e7c | 105 | //Calculate the system output depending on input, after calculation the relevant class members need to be syncronized. |
alexpirciu | 1:ceee5a608e7c | 106 | virtual COutputType calculateOutput(const CInputType& f_input)=0; |
alexpirciu | 1:ceee5a608e7c | 107 | // GETTERS |
alexpirciu | 1:ceee5a608e7c | 108 | // The method returns the current system states |
alexpirciu | 1:ceee5a608e7c | 109 | CStatesType getStates();//{return m_states;} |
alexpirciu | 1:ceee5a608e7c | 110 | // The method returns the current system output |
alexpirciu | 1:ceee5a608e7c | 111 | COutputType getOutput(){return m_outputs;} |
alexpirciu | 1:ceee5a608e7c | 112 | float getTimeStep(){return m_dt;} |
alexpirciu | 1:ceee5a608e7c | 113 | // SETTERS |
alexpirciu | 1:ceee5a608e7c | 114 | void setStates(const CStatesType& f_states){ |
alexpirciu | 1:ceee5a608e7c | 115 | m_states=f_states; |
alexpirciu | 1:ceee5a608e7c | 116 | } |
alexpirciu | 1:ceee5a608e7c | 117 | protected: |
alexpirciu | 1:ceee5a608e7c | 118 | // States |
alexpirciu | 1:ceee5a608e7c | 119 | CStatesType m_states; |
alexpirciu | 1:ceee5a608e7c | 120 | // Output |
alexpirciu | 1:ceee5a608e7c | 121 | COutputType m_outputs; |
alexpirciu | 1:ceee5a608e7c | 122 | // Time step |
alexpirciu | 1:ceee5a608e7c | 123 | const double m_dt; |
alexpirciu | 1:ceee5a608e7c | 124 | private: |
alexpirciu | 1:ceee5a608e7c | 125 | }; |
alexpirciu | 1:ceee5a608e7c | 126 | |
alexpirciu | 1:ceee5a608e7c | 127 | // the state transition and observation matrices defined by Jacobians |
alexpirciu | 1:ceee5a608e7c | 128 | // T -variable type |
alexpirciu | 1:ceee5a608e7c | 129 | // NA -number of inputs |
alexpirciu | 1:ceee5a608e7c | 130 | // NB -number of states |
alexpirciu | 1:ceee5a608e7c | 131 | // NC -number of outputs |
alexpirciu | 1:ceee5a608e7c | 132 | template <class T,uint32_t NA, uint32_t NB,uint32_t NC> |
alexpirciu | 1:ceee5a608e7c | 133 | class CJacobianMatrices{ |
alexpirciu | 1:ceee5a608e7c | 134 | public: |
alexpirciu | 1:ceee5a608e7c | 135 | using CStatesType = linalg::CMatrix<T,NB,1>; |
alexpirciu | 1:ceee5a608e7c | 136 | using CInputType = linalg::CMatrix<T,NA,1>; |
alexpirciu | 1:ceee5a608e7c | 137 | // using COutputType = linalg::CMatrix<T,NC,1>; |
alexpirciu | 1:ceee5a608e7c | 138 | using CJMTransitionType = linalg::CMatrix<T,NB,NB>; |
alexpirciu | 1:ceee5a608e7c | 139 | using CJMObservationType = linalg::CMatrix<T,NC,NB>; |
alexpirciu | 1:ceee5a608e7c | 140 | |
alexpirciu | 1:ceee5a608e7c | 141 | //The method calculates and returns the states transition matrix |
alexpirciu | 1:ceee5a608e7c | 142 | virtual CJMTransitionType getJMTransition(const CStatesType& f_states |
alexpirciu | 1:ceee5a608e7c | 143 | ,const CInputType& f_inputs)=0; |
alexpirciu | 1:ceee5a608e7c | 144 | // The method calculates and returns the states observation matrix |
alexpirciu | 1:ceee5a608e7c | 145 | virtual CJMObservationType getJMObservation(const CStatesType& f_states |
alexpirciu | 1:ceee5a608e7c | 146 | ,const CInputType& f_input)=0; |
alexpirciu | 1:ceee5a608e7c | 147 | private: |
alexpirciu | 1:ceee5a608e7c | 148 | }; |
alexpirciu | 1:ceee5a608e7c | 149 | }; |
alexpirciu | 1:ceee5a608e7c | 150 | }; |
alexpirciu | 1:ceee5a608e7c | 151 | }; |
alexpirciu | 1:ceee5a608e7c | 152 | |
alexpirciu | 1:ceee5a608e7c | 153 | #include "systemmodels.inl" |
alexpirciu | 1:ceee5a608e7c | 154 | |
alexpirciu | 1:ceee5a608e7c | 155 | #endif |