Show
Ignore:
Timestamp:
06/02/09 10:08:06 (15 years ago)
Author:
smidl
Message:

doc

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • doc/html/pmsmDS_8h-source.html

    r323 r353  
    6666<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;<a class="code" href="loggers_8h.html" title="Loggers for storing results of experiments.">stat/loggers.h</a>&gt;</span> 
    6767<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;<a class="code" href="libKF_8h.html" title="Bayesian Filtering for linear Gaussian models (Kalman Filter) and extensions.">estim/libKF.h</a>&gt;</span> 
    68 <a name="l00015"></a>00015 <span class="preprocessor">#include "simulator.h"</span> 
     68<a name="l00015"></a>00015 <span class="preprocessor">#include "simulator_zdenek/simulator.h"</span> 
    6969<a name="l00016"></a>00016 <span class="preprocessor">#include "pmsm.h"</span> 
    7070<a name="l00017"></a>00017  
     
    7979<a name="l00033"></a><a class="code" href="classpmsmDS.html#f387fee363e4a8492074fee36bb8421b">00033</a>         <span class="keywordtype">bool</span> <a class="code" href="classpmsmDS.html#f387fee363e4a8492074fee36bb8421b" title="options for logging, - log predictions of &amp;#39;true&amp;#39; voltage">opt_modu</a>; 
    8080<a name="l00035"></a>00035 <span class="keyword">public</span>: 
    81 <a name="l00037"></a><a class="code" href="classpmsmDS.html#e6a50a246de039f30cb5423521aab55c">00037</a>         <a class="code" href="classpmsmDS.html#e6a50a246de039f30cb5423521aab55c" title="options for logging, -">pmsmDS</a> ()   {<a class="code" href="classpmsmDS.html#c27956dc82ede2e8dbeb34e6cfa15a40" title="Number of miliseconds per discrete time step.">Dt</a>=125; <a class="code" href="classbdm_1_1DS.html#d8db125ac35f3b8eeb773fc9a4cb45ec" title="Description of data returned by getdata().">Drv</a>=<a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> ( <span class="stringliteral">"{o_ua o_ub o_ia o_ib t_ua t_ub }"</span> );} 
     81<a name="l00037"></a><a class="code" href="classpmsmDS.html#e6a50a246de039f30cb5423521aab55c">00037</a>         <a class="code" href="classpmsmDS.html#e6a50a246de039f30cb5423521aab55c" title="options for logging, -">pmsmDS</a> ()   {<a class="code" href="classpmsmDS.html#c27956dc82ede2e8dbeb34e6cfa15a40" title="Number of miliseconds per discrete time step.">Dt</a>=125; <a class="code" href="classbdm_1_1DS.html#d8db125ac35f3b8eeb773fc9a4cb45ec" title="Description of data returned by getdata().">Drv</a>=<a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a> ( <span class="stringliteral">"{o_ua o_ub o_ia o_ib t_ua t_ub o_om o_th Mz }"</span> );} 
    8282<a name="l00038"></a>00038         <span class="keywordtype">void</span> set_parameters ( <span class="keywordtype">double</span> Rs0, <span class="keywordtype">double</span> Ls0, <span class="keywordtype">double</span> Fmag0, <span class="keywordtype">double</span> Bf0, <span class="keywordtype">double</span> p0, <span class="keywordtype">double</span> kp0, <span class="keywordtype">double</span> J0, <span class="keywordtype">double</span> Uc0, <span class="keywordtype">double</span> DT0, <span class="keywordtype">double</span> dt0 ) { 
    8383<a name="l00039"></a>00039                 pmsmsim_set_parameters ( Rs0, Ls0, Fmag0, Bf0, p0, kp0, J0, Uc0, DT0, dt0 ); 
    8484<a name="l00040"></a>00040         } 
    8585<a name="l00042"></a><a class="code" href="classpmsmDS.html#75dd22db70746bfd0c3e685a17bbf34a">00042</a>         <span class="keywordtype">void</span> <a class="code" href="classpmsmDS.html#75dd22db70746bfd0c3e685a17bbf34a" title="parse options: &amp;quot;modelu&amp;quot; =&amp;gt; opt_modu=true;">set_options</a> ( <span class="keywordtype">string</span> &amp;opt ) { 
    86 <a name="l00043"></a>00043                 <a class="code" href="classpmsmDS.html#f387fee363e4a8492074fee36bb8421b" title="options for logging, - log predictions of &amp;#39;true&amp;#39; voltage">opt_modu</a> = ( opt.find ( <span class="stringliteral">"modelu"</span> ) ==string::npos ); 
     86<a name="l00043"></a>00043                 <a class="code" href="classpmsmDS.html#f387fee363e4a8492074fee36bb8421b" title="options for logging, - log predictions of &amp;#39;true&amp;#39; voltage">opt_modu</a> = ( opt.find ( <span class="stringliteral">"modelu"</span> ) !=string::npos ); 
    8787<a name="l00044"></a>00044         } 
    88 <a name="l00045"></a><a class="code" href="classpmsmDS.html#4e47e678eb56e0b3bd47d801d0995e46">00045</a>         <span class="keywordtype">void</span> <a class="code" href="classpmsmDS.html#4e47e678eb56e0b3bd47d801d0995e46" title="Returns full vector of observed data=[output, input].">getdata</a> ( vec &amp;dt ) {dt=vec ( KalmanObs,6 );} 
     88<a name="l00045"></a><a class="code" href="classpmsmDS.html#4e47e678eb56e0b3bd47d801d0995e46">00045</a>         <span class="keywordtype">void</span> <a class="code" href="classpmsmDS.html#4e47e678eb56e0b3bd47d801d0995e46" title="Returns full vector of observed data=[output, input].">getdata</a> ( vec &amp;dt ) {dt.set_subvector(0,vec ( KalmanObs,6 ));dt(6)=x[2];dt(7)=x[3];dt(8)=x[8];} 
    8989<a name="l00046"></a><a class="code" href="classpmsmDS.html#35e9a2b9d82bd1b71d66778021d1e8b4">00046</a>         <span class="keywordtype">void</span> <a class="code" href="classpmsmDS.html#35e9a2b9d82bd1b71d66778021d1e8b4" title="Accepts action variable and schedule it for application.">write</a> ( vec &amp;ut ) {} 
    9090<a name="l00047"></a>00047  
     
    122122<a name="l00079"></a>00079                 <span class="comment">//Simulate Dt seconds!</span> 
    123123<a name="l00080"></a>00080                 <span class="keywordflow">for</span> ( <span class="keywordtype">int</span> i=0;i&lt;<a class="code" href="classpmsmDS.html#c27956dc82ede2e8dbeb34e6cfa15a40" title="Number of miliseconds per discrete time step.">Dt</a>;i++ ) {      pmsmsim_step ( Ww , Mz);} 
    124 <a name="l00081"></a>00081         }; 
    125 <a name="l00082"></a>00082  
    126 <a name="l00083"></a><a class="code" href="classpmsmDS.html#d75b83468db25c56977ffccff46b0b37">00083</a>         <span class="keywordtype">void</span> <a class="code" href="classpmsmDS.html#d75b83468db25c56977ffccff46b0b37" title="Register DS for logging into logger L.">log_add</a> ( <a class="code" href="classbdm_1_1logger.html" title="Class for storing results (and semi-results) of an experiment.">logger</a> &amp;L ) { 
    127 <a name="l00084"></a>00084                 <a class="code" href="classpmsmDS.html#3975e648cc981a550997df8120e176f7" title="indeces of logged variables">L_x</a> = L.<a class="code" href="classbdm_1_1logger.html#cfb4807e20b3d00f3d33e55ada528dc1">add</a> ( rx, <span class="stringliteral">"x"</span> ); 
    128 <a name="l00085"></a>00085                 L_oy = L.<a class="code" href="classbdm_1_1logger.html#cfb4807e20b3d00f3d33e55ada528dc1">add</a> ( ry, <span class="stringliteral">"o"</span> ); 
    129 <a name="l00086"></a>00086                 L_ou = L.<a class="code" href="classbdm_1_1logger.html#cfb4807e20b3d00f3d33e55ada528dc1">add</a> ( ru, <span class="stringliteral">"o"</span> ); 
    130 <a name="l00087"></a>00087                 L_iu = L.<a class="code" href="classbdm_1_1logger.html#cfb4807e20b3d00f3d33e55ada528dc1">add</a> ( ru, <span class="stringliteral">"t"</span> ); 
    131 <a name="l00088"></a>00088                 <span class="comment">// log differences</span> 
    132 <a name="l00089"></a>00089                 <span class="keywordflow">if</span> ( <a class="code" href="classpmsmDS.html#f387fee363e4a8492074fee36bb8421b" title="options for logging, - log predictions of &amp;#39;true&amp;#39; voltage">opt_modu</a> ) { 
    133 <a name="l00090"></a>00090                         L_optu = L.<a class="code" href="classbdm_1_1logger.html#cfb4807e20b3d00f3d33e55ada528dc1">add</a> ( ru, <span class="stringliteral">"model"</span> ); 
    134 <a name="l00091"></a>00091                 } 
    135 <a name="l00092"></a>00092         } 
    136 <a name="l00093"></a>00093  
    137 <a name="l00094"></a><a class="code" href="classpmsmDS.html#21cac6deaac2dd073c982d7bec839b47">00094</a>         <span class="keywordtype">void</span> <a class="code" href="classpmsmDS.html#21cac6deaac2dd073c982d7bec839b47" title="Register DS for logging into logger L.">logit</a> ( <a class="code" href="classbdm_1_1logger.html" title="Class for storing results (and semi-results) of an experiment.">logger</a> &amp;L ) { 
    138 <a name="l00095"></a>00095                 L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a> ( <a class="code" href="classpmsmDS.html#3975e648cc981a550997df8120e176f7" title="indeces of logged variables">L_x</a>, vec ( x,4 )      ); 
    139 <a name="l00096"></a>00096                 L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a> ( L_oy, vec_2 ( KalmanObs[2],KalmanObs[3] ) ); 
    140 <a name="l00097"></a>00097                 L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a> ( L_ou, vec_2 ( KalmanObs[0],KalmanObs[1] ) ); 
    141 <a name="l00098"></a>00098                 L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a> ( L_iu, vec_2 ( KalmanObs[4],KalmanObs[5] ) ); 
     124<a name="l00081"></a>00081 <span class="comment">//              for ( int i=0;i&lt;Dt;i++ ) {      pmsmsim_noreg_step ( Ww , Mz);}</span> 
     125<a name="l00082"></a>00082                  
     126<a name="l00083"></a>00083                 <span class="comment">//discretization</span> 
     127<a name="l00084"></a>00084                 <span class="keywordtype">double</span> ustep=1.2; 
     128<a name="l00085"></a>00085                 KalmanObs [ 0 ] = ustep*<a class="code" href="group__convertfunc.html#g811e448b443d640d5931624a8727d0fd" title="Round to nearest integer.">itpp::round</a>( KalmanObs [ 0 ]/ ustep) ; 
     129<a name="l00086"></a>00086                 KalmanObs [ 1 ] = ustep*<a class="code" href="group__convertfunc.html#g811e448b443d640d5931624a8727d0fd" title="Round to nearest integer.">itpp::round</a>(KalmanObs [ 1 ]/ ustep); 
     130<a name="l00087"></a>00087                 <span class="keywordtype">double</span> istep=0.085; 
     131<a name="l00088"></a>00088                 KalmanObs [ 2 ] = istep*<a class="code" href="group__convertfunc.html#g811e448b443d640d5931624a8727d0fd" title="Round to nearest integer.">itpp::round</a>( KalmanObs [ 2 ]/ istep) ; 
     132<a name="l00089"></a>00089                 KalmanObs [ 3 ] = istep*<a class="code" href="group__convertfunc.html#g811e448b443d640d5931624a8727d0fd" title="Round to nearest integer.">itpp::round</a>(KalmanObs [ 3 ]/ istep); 
     133<a name="l00090"></a>00090  
     134<a name="l00091"></a>00091         }; 
     135<a name="l00092"></a>00092  
     136<a name="l00093"></a><a class="code" href="classpmsmDS.html#d75b83468db25c56977ffccff46b0b37">00093</a>         <span class="keywordtype">void</span> <a class="code" href="classpmsmDS.html#d75b83468db25c56977ffccff46b0b37" title="Register DS for logging into logger L.">log_add</a> ( <a class="code" href="classbdm_1_1logger.html" title="Class for storing results (and semi-results) of an experiment.">logger</a> &amp;L ) { 
     137<a name="l00094"></a>00094                 <a class="code" href="classpmsmDS.html#3975e648cc981a550997df8120e176f7" title="indeces of logged variables">L_x</a> = L.<a class="code" href="classbdm_1_1logger.html#47aa3b098a81d02a8ffaea2c9fa09ac7">add</a> ( rx, <span class="stringliteral">"x"</span> ); 
     138<a name="l00095"></a>00095                 L_oy = L.<a class="code" href="classbdm_1_1logger.html#47aa3b098a81d02a8ffaea2c9fa09ac7">add</a> ( ry, <span class="stringliteral">"o"</span> ); 
     139<a name="l00096"></a>00096                 L_ou = L.<a class="code" href="classbdm_1_1logger.html#47aa3b098a81d02a8ffaea2c9fa09ac7">add</a> ( ru, <span class="stringliteral">"o"</span> ); 
     140<a name="l00097"></a>00097                 L_iu = L.<a class="code" href="classbdm_1_1logger.html#47aa3b098a81d02a8ffaea2c9fa09ac7">add</a> ( ru, <span class="stringliteral">"t"</span> ); 
     141<a name="l00098"></a>00098                 <span class="comment">// log differences</span> 
    142142<a name="l00099"></a>00099                 <span class="keywordflow">if</span> ( <a class="code" href="classpmsmDS.html#f387fee363e4a8492074fee36bb8421b" title="options for logging, - log predictions of &amp;#39;true&amp;#39; voltage">opt_modu</a> ) { 
    143 <a name="l00100"></a>00100                         <span class="keywordtype">double</span> sq3=sqrt ( 3.0 ); 
    144 <a name="l00101"></a>00101                         <span class="keywordtype">double</span> ua,ub; 
    145 <a name="l00102"></a>00102                         <span class="keywordtype">double</span> i1=x[0]; 
    146 <a name="l00103"></a>00103                         <span class="keywordtype">double</span> i2=0.5* ( -i1+sq3*x[1] ); 
    147 <a name="l00104"></a>00104                         <span class="keywordtype">double</span> i3=0.5* ( -i1-sq3*x[1] ); 
    148 <a name="l00105"></a>00105                         <span class="keywordtype">double</span> u1=KalmanObs[0]; 
    149 <a name="l00106"></a>00106                         <span class="keywordtype">double</span> u2=0.5* ( -u1+sq3*KalmanObs[1] ); 
    150 <a name="l00107"></a>00107                         <span class="keywordtype">double</span> u3=0.5* ( -u1-sq3*KalmanObs[1] ); 
    151 <a name="l00108"></a>00108  
    152 <a name="l00109"></a>00109                         <span class="keywordtype">double</span> du1=0.7* ( double ( i1&gt;0.1 ) - double ( i1&lt;-0.1 ) ) +0.05*i1; 
    153 <a name="l00110"></a>00110                         <span class="keywordtype">double</span> du2=0.7* ( double ( i2&gt;0.1 ) - double ( i2&lt;-0.1 ) ) +0.05*i2; 
    154 <a name="l00111"></a>00111                         <span class="keywordtype">double</span> du3=0.7* ( double ( i3&gt;0.1 ) - double ( i3&lt;-0.1 ) ) +0.05*i3; 
    155 <a name="l00112"></a>00112                         ua = ( 2.0* ( u1-du1 )- ( u2-du2 )- ( u3-du3 ) ) /3.0; 
    156 <a name="l00113"></a>00113                         ub = ( ( u2-du2 )- ( u3-du3 ) ) /sq3; 
    157 <a name="l00114"></a>00114                         L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a> ( L_optu , vec_2 ( ua,ub ) ); 
    158 <a name="l00115"></a>00115                 } 
    159 <a name="l00116"></a>00116                  
    160 <a name="l00117"></a>00117         } 
     143<a name="l00100"></a>00100                         L_optu = L.<a class="code" href="classbdm_1_1logger.html#47aa3b098a81d02a8ffaea2c9fa09ac7">add</a> ( ru, <span class="stringliteral">"model"</span> ); 
     144<a name="l00101"></a>00101                 } 
     145<a name="l00102"></a>00102         } 
     146<a name="l00103"></a>00103  
     147<a name="l00104"></a><a class="code" href="classpmsmDS.html#21cac6deaac2dd073c982d7bec839b47">00104</a>         <span class="keywordtype">void</span> <a class="code" href="classpmsmDS.html#21cac6deaac2dd073c982d7bec839b47" title="Register DS for logging into logger L.">logit</a> ( <a class="code" href="classbdm_1_1logger.html" title="Class for storing results (and semi-results) of an experiment.">logger</a> &amp;L ) { 
     148<a name="l00105"></a>00105                 L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a> ( <a class="code" href="classpmsmDS.html#3975e648cc981a550997df8120e176f7" title="indeces of logged variables">L_x</a>, vec ( x,4 )      ); 
     149<a name="l00106"></a>00106                 L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a> ( L_oy, vec_2 ( KalmanObs[2],KalmanObs[3] ) ); 
     150<a name="l00107"></a>00107                 L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a> ( L_ou, vec_2 ( KalmanObs[0],KalmanObs[1] ) ); 
     151<a name="l00108"></a>00108                 L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a> ( L_iu, vec_2 ( KalmanObs[4],KalmanObs[5] ) ); 
     152<a name="l00109"></a>00109                 <span class="keywordflow">if</span> ( <a class="code" href="classpmsmDS.html#f387fee363e4a8492074fee36bb8421b" title="options for logging, - log predictions of &amp;#39;true&amp;#39; voltage">opt_modu</a> ) { 
     153<a name="l00110"></a>00110                         <span class="keywordtype">double</span> sq3=<a class="code" href="group__miscfunc.html#g20af7c97287e8275db8c2b0f650310ac" title="Square root of the elements.">sqrt</a> ( 3.0 ); 
     154<a name="l00111"></a>00111                         <span class="keywordtype">double</span> ua,ub; 
     155<a name="l00112"></a>00112                         <span class="keywordtype">double</span> i1=x[0]; 
     156<a name="l00113"></a>00113                         <span class="keywordtype">double</span> i2=0.5* ( -i1+sq3*x[1] ); 
     157<a name="l00114"></a>00114                         <span class="keywordtype">double</span> i3=0.5* ( -i1-sq3*x[1] ); 
     158<a name="l00115"></a>00115                         <span class="keywordtype">double</span> u1=KalmanObs[0]; 
     159<a name="l00116"></a>00116                         <span class="keywordtype">double</span> u2=0.5* ( -u1+sq3*KalmanObs[1] ); 
     160<a name="l00117"></a>00117                         <span class="keywordtype">double</span> u3=0.5* ( -u1-sq3*KalmanObs[1] ); 
    161161<a name="l00118"></a>00118  
    162 <a name="l00119"></a>00119         <span class="keywordtype">void</span> set_profile ( <span class="keywordtype">double</span> dt, <span class="keyword">const</span> vec &amp;Ww, <span class="keyword">const</span> vec &amp;Mz ) {<a class="code" href="classpmsmDS.html#01d9d15490d336b6613368557608f4fe" title="time-step for profiles">dt_prof</a>=dt; <a class="code" href="classpmsmDS.html#ba6fbc63e4353135857bbba8f30e3012" title="Setpoints of omega in timespans given by dt_prof.">profileWw</a>=Ww; <a class="code" href="classpmsmDS.html#817e0b4c12e2c185271740b3ce3e3980" title="Setpoints of Mz in timespans given by dt_prof.">profileMz</a>=Mz;} 
    163 <a name="l00120"></a>00120 }; 
    164 <a name="l00121"></a>00121  
    165 <a name="l00123"></a><a class="code" href="classpmsmCRB.html">00123</a> <span class="keyword">class </span><a class="code" href="classpmsmCRB.html" title="This class behaves like BM but it is evaluating EKF.">pmsmCRB</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1EKFCh.html" title="Extended Kalman Filter in Square root.">EKFCh</a>{ 
    166 <a name="l00124"></a>00124         <span class="keyword">protected</span>: 
    167 <a name="l00125"></a>00125                 vec interr; 
    168 <a name="l00126"></a>00126                 vec old_true; 
    169 <a name="l00127"></a>00127                 vec secder; 
    170 <a name="l00128"></a>00128                 <span class="keywordtype">int</span> L_CRB; 
    171 <a name="l00129"></a>00129                 <span class="keywordtype">int</span> L_err; 
    172 <a name="l00130"></a>00130                 <span class="keywordtype">int</span> L_sec; 
    173 <a name="l00131"></a>00131         <span class="keyword">public</span>: 
    174 <a name="l00133"></a><a class="code" href="classpmsmCRB.html#81c85cc94deabb48f8fdd0a22e34aa14">00133</a>         <a class="code" href="classpmsmCRB.html#81c85cc94deabb48f8fdd0a22e34aa14" title="constructor">pmsmCRB</a>():<a class="code" href="classbdm_1_1EKFCh.html" title="Extended Kalman Filter in Square root.">EKFCh</a>(){old_true=zeros(6);} 
    175 <a name="l00134"></a>00134  
    176 <a name="l00135"></a><a class="code" href="classpmsmCRB.html#13749c201329922511369cdbe2f0f50a">00135</a>         <span class="keywordtype">void</span> <a class="code" href="classpmsmCRB.html#13749c201329922511369cdbe2f0f50a" title="Here dt = [yt;ut] of appropriate dimensions.">bayes</a>(<span class="keyword">const</span> vec &amp;dt){ 
    177 <a name="l00136"></a>00136                 <span class="comment">//assume we know state exactly:</span> 
    178 <a name="l00137"></a>00137                 vec true_state=vec(x,4); <span class="comment">// read from pmsm</span> 
    179 <a name="l00138"></a>00138                 <a class="code" href="classbdm_1_1Kalman.html#383f329ff18bbe219254c8b3b916f40d" title="posterior density on $x_t$">est</a>.<a class="code" href="classbdm_1_1enorm.html#8915d68ae76ad185c8c314f960a63f0c">set_mu</a>(true_state); 
    180 <a name="l00139"></a>00139                  
    181 <a name="l00140"></a>00140                 <span class="comment">//integration error</span> 
    182 <a name="l00141"></a>00141                 old_true(4)=KalmanObs[4]; 
    183 <a name="l00142"></a>00142                 old_true(5)=KalmanObs[5];<span class="comment">// add U</span> 
    184 <a name="l00143"></a>00143                 interr = (true_state - <a class="code" href="classbdm_1_1EKFCh.html#e1e895f994398a55bc425551fc275ba3" title="Internal Model f(x,u).">pfxu</a>-&gt;<a class="code" href="classbdm_1_1diffbifn.html#188f31066bd72e1bf0ddacd1eb0e6af3" title="Evaluates  (VS: Do we really need common eval? ).">eval</a>(old_true)); 
    185 <a name="l00144"></a>00144                  
    186 <a name="l00145"></a>00145                 <span class="comment">//second derivative</span> 
    187 <a name="l00146"></a>00146                 <a class="code" href="classIMpmsm2o.html" title="State evolution model for a PMSM drive and its derivative with respect to .">IMpmsm2o</a>* pf = <span class="keyword">dynamic_cast&lt;</span><a class="code" href="classIMpmsm2o.html" title="State evolution model for a PMSM drive and its derivative with respect to .">IMpmsm2o</a>*<span class="keyword">&gt;</span>(<a class="code" href="classbdm_1_1EKFCh.html#e1e895f994398a55bc425551fc275ba3" title="Internal Model f(x,u).">pfxu</a>); 
    188 <a name="l00147"></a>00147                 <span class="keywordflow">if</span> (pf) {secder=pf-&gt;<a class="code" href="classIMpmsm2o.html#cf66e75d9e532b0a1c2135b34ac57c89" title="eval 2nd order Taylor expansion, MUST be used only as a follow up AFTER eval()!!">eval2o</a>(vec_2(KalmanObs[4],KalmanObs[5]));} 
    189 <a name="l00148"></a>00148                                  
    190 <a name="l00149"></a>00149                 <a class="code" href="classpmsmCRB.html#13749c201329922511369cdbe2f0f50a" title="Here dt = [yt;ut] of appropriate dimensions.">EKFCh::bayes</a>(dt); 
    191 <a name="l00150"></a>00150                 old_true.set_subvector(0,true_state); 
    192 <a name="l00151"></a>00151         } 
    193 <a name="l00152"></a>00152          
    194 <a name="l00153"></a><a class="code" href="classpmsmCRB.html#b50294749e1be33687e852ea186815ad">00153</a>         <span class="keywordtype">void</span> <a class="code" href="classpmsmCRB.html#b50294749e1be33687e852ea186815ad" title="Add all logged variables to a logger.">log_add</a>(<a class="code" href="classbdm_1_1logger.html" title="Class for storing results (and semi-results) of an experiment.">logger</a> &amp;L, <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;name=<span class="stringliteral">""</span> ){ 
    195 <a name="l00154"></a>00154                 L_CRB=L.<a class="code" href="classbdm_1_1logger.html#cfb4807e20b3d00f3d33e55ada528dc1">add</a>(rx,<span class="stringliteral">"crb"</span>); 
    196 <a name="l00155"></a>00155                 L_err=L.<a class="code" href="classbdm_1_1logger.html#cfb4807e20b3d00f3d33e55ada528dc1">add</a>(rx,<span class="stringliteral">"err"</span>); 
    197 <a name="l00156"></a>00156                 L_sec=L.<a class="code" href="classbdm_1_1logger.html#cfb4807e20b3d00f3d33e55ada528dc1">add</a>(rx,<span class="stringliteral">"d2"</span>); 
    198 <a name="l00157"></a>00157         } 
    199 <a name="l00158"></a>00158         <span class="keywordtype">void</span> logit(<a class="code" href="classbdm_1_1logger.html" title="Class for storing results (and semi-results) of an experiment.">logger</a> &amp;L){ 
    200 <a name="l00159"></a>00159                 L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a>(L_err, interr); 
    201 <a name="l00160"></a>00160                 L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a>(L_CRB,diag(<a class="code" href="classbdm_1_1Kalman.html#383f329ff18bbe219254c8b3b916f40d" title="posterior density on $x_t$">est</a>.<a class="code" href="classbdm_1_1enorm.html#81d81e35e57c9f194bde248e3affcf1f">_R</a>().<a class="code" href="classchmat.html#045addd685f8d978efda232d7dcb070e" title="Conversion to full matrix.">to_mat</a>())); 
    202 <a name="l00161"></a>00161                 L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a>(L_sec,secder); 
    203 <a name="l00162"></a>00162         } 
    204 <a name="l00163"></a>00163 }; 
     162<a name="l00119"></a>00119                         <span class="keywordtype">double</span> du1=1.4* ( double ( i1&gt;0.3 ) - double ( i1&lt;-0.3 ) ) +0.2*i1; 
     163<a name="l00120"></a>00120                         <span class="keywordtype">double</span> du2=1.4* ( double ( i2&gt;0.3 ) - double ( i2&lt;-0.3 ) ) +0.2*i2; 
     164<a name="l00121"></a>00121                         <span class="keywordtype">double</span> du3=1.4* ( double ( i3&gt;0.3 ) - double ( i3&lt;-0.3 ) ) +0.2*i3; 
     165<a name="l00122"></a>00122                         ua = ( 2.0* ( u1-du1 )- ( u2-du2 )- ( u3-du3 ) ) /3.0; 
     166<a name="l00123"></a>00123                         ub = ( ( u2-du2 )- ( u3-du3 ) ) /sq3; 
     167<a name="l00124"></a>00124                         L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a> ( L_optu , vec_2 ( ua,ub ) ); 
     168<a name="l00125"></a>00125                 } 
     169<a name="l00126"></a>00126                  
     170<a name="l00127"></a>00127         } 
     171<a name="l00128"></a>00128  
     172<a name="l00129"></a>00129         <span class="keywordtype">void</span> set_profile ( <span class="keywordtype">double</span> dt, <span class="keyword">const</span> vec &amp;Ww, <span class="keyword">const</span> vec &amp;Mz ) {<a class="code" href="classpmsmDS.html#01d9d15490d336b6613368557608f4fe" title="time-step for profiles">dt_prof</a>=dt; <a class="code" href="classpmsmDS.html#ba6fbc63e4353135857bbba8f30e3012" title="Setpoints of omega in timespans given by dt_prof.">profileWw</a>=Ww; <a class="code" href="classpmsmDS.html#817e0b4c12e2c185271740b3ce3e3980" title="Setpoints of Mz in timespans given by dt_prof.">profileMz</a>=Mz;} 
     173<a name="l00130"></a>00130 }; 
     174<a name="l00131"></a>00131  
     175<a name="l00133"></a><a class="code" href="classpmsmCRB.html">00133</a> <span class="keyword">class </span><a class="code" href="classpmsmCRB.html" title="This class behaves like BM but it is evaluating EKF.">pmsmCRB</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1EKFfull.html" title="Extended Kalman Filter in full matrices.">EKFfull</a>{ 
     176<a name="l00134"></a>00134         <span class="keyword">protected</span>: 
     177<a name="l00135"></a>00135                 vec interr; 
     178<a name="l00136"></a>00136                 vec old_true; 
     179<a name="l00137"></a>00137                 vec secder; 
     180<a name="l00138"></a>00138                 <span class="keywordtype">int</span> L_CRB; 
     181<a name="l00139"></a>00139                 <span class="keywordtype">int</span> L_err; 
     182<a name="l00140"></a>00140                 <span class="keywordtype">int</span> L_sec; 
     183<a name="l00141"></a>00141         <span class="keyword">public</span>: 
     184<a name="l00143"></a><a class="code" href="classpmsmCRB.html#81c85cc94deabb48f8fdd0a22e34aa14">00143</a>         <a class="code" href="classpmsmCRB.html#81c85cc94deabb48f8fdd0a22e34aa14" title="constructor">pmsmCRB</a>():<a class="code" href="classbdm_1_1EKFfull.html" title="Extended Kalman Filter in full matrices.">EKFfull</a>(){old_true=<a class="code" href="group__specmat.html#g10723ecada06221cbe64fe2736a59de1" title="A Double (rows,cols)-matrix of zeros.">zeros</a>(6);} 
     185<a name="l00144"></a>00144  
     186<a name="l00145"></a><a class="code" href="classpmsmCRB.html#13749c201329922511369cdbe2f0f50a">00145</a>         <span class="keywordtype">void</span> <a class="code" href="classpmsmCRB.html#13749c201329922511369cdbe2f0f50a" title="Here dt = [yt;ut] of appropriate dimensions.">bayes</a>(<span class="keyword">const</span> vec &amp;dt){ 
     187<a name="l00146"></a>00146                 <span class="keyword">static</span> vec umin(2); 
     188<a name="l00147"></a>00147                 vec u(2);  
     189<a name="l00148"></a>00148                 <span class="comment">//assume we know state exactly:</span> 
     190<a name="l00149"></a>00149                 vec true_state=vec(x,4); <span class="comment">// read from pmsm</span> 
     191<a name="l00150"></a>00150                 E.<a class="code" href="classbdm_1_1enorm.html#8915d68ae76ad185c8c314f960a63f0c">set_mu</a>(true_state); 
     192<a name="l00151"></a>00151                 <a class="code" href="classbdm_1_1KalmanFull.html#2defb75e58892615c5f95fd844f3a666" title="Mean value of the posterior density.">mu</a>=true_state; 
     193<a name="l00152"></a>00152                          
     194<a name="l00153"></a>00153                 <span class="comment">//integration error</span> 
     195<a name="l00154"></a>00154                 old_true(4)=KalmanObs[4]; 
     196<a name="l00155"></a>00155                 old_true(5)=KalmanObs[5];<span class="comment">// add U</span> 
     197<a name="l00156"></a>00156                 u(0) = KalmanObs[0]; <span class="comment">// use the required value for derivatives</span> 
     198<a name="l00157"></a>00157                 u(1) = KalmanObs[1]; 
     199<a name="l00158"></a>00158                 interr = (true_state - <a class="code" href="classbdm_1_1EKFfull.html#016d3ec108a430b1e70cf7d78bb963f4" title="Internal Model f(x,u).">pfxu</a>-&gt;<a class="code" href="classbdm_1_1diffbifn.html#188f31066bd72e1bf0ddacd1eb0e6af3" title="Evaluates  (VS: Do we really need common eval? ).">eval</a>(old_true)); 
     200<a name="l00159"></a>00159                  
     201<a name="l00160"></a>00160                 <span class="comment">//second derivative</span> 
     202<a name="l00161"></a>00161                 <a class="code" href="classIMpmsm2o.html" title="State evolution model for a PMSM drive and its derivative with respect to .">IMpmsm2o</a>* pf = <span class="keyword">dynamic_cast&lt;</span><a class="code" href="classIMpmsm2o.html" title="State evolution model for a PMSM drive and its derivative with respect to .">IMpmsm2o</a>*<span class="keyword">&gt;</span>(<a class="code" href="classbdm_1_1EKFfull.html#016d3ec108a430b1e70cf7d78bb963f4" title="Internal Model f(x,u).">pfxu</a>); 
     203<a name="l00162"></a>00162                 <span class="keywordflow">if</span> (pf) {secder=pf-&gt;<a class="code" href="classIMpmsm2o.html#cf66e75d9e532b0a1c2135b34ac57c89" title="eval 2nd order Taylor expansion, MUST be used only as a follow up AFTER eval()!!">eval2o</a>(u-umin);} 
     204<a name="l00163"></a>00163                                  
     205<a name="l00164"></a>00164                 umin =u; 
     206<a name="l00165"></a>00165                 <a class="code" href="classpmsmCRB.html#13749c201329922511369cdbe2f0f50a" title="Here dt = [yt;ut] of appropriate dimensions.">EKFfull::bayes</a>(dt); 
     207<a name="l00166"></a>00166                 old_true.set_subvector(0,true_state); 
     208<a name="l00167"></a>00167         } 
     209<a name="l00168"></a>00168          
     210<a name="l00169"></a><a class="code" href="classpmsmCRB.html#b50294749e1be33687e852ea186815ad">00169</a>         <span class="keywordtype">void</span> <a class="code" href="classpmsmCRB.html#b50294749e1be33687e852ea186815ad" title="Add all logged variables to a logger.">log_add</a>(<a class="code" href="classbdm_1_1logger.html" title="Class for storing results (and semi-results) of an experiment.">logger</a> &amp;L, <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;name=<span class="stringliteral">""</span> ){ 
     211<a name="l00170"></a>00170                 L_CRB=L.<a class="code" href="classbdm_1_1logger.html#47aa3b098a81d02a8ffaea2c9fa09ac7">add</a>(rx,<span class="stringliteral">"crb"</span>); 
     212<a name="l00171"></a>00171                 L_err=L.<a class="code" href="classbdm_1_1logger.html#47aa3b098a81d02a8ffaea2c9fa09ac7">add</a>(rx,<span class="stringliteral">"err"</span>); 
     213<a name="l00172"></a>00172                 L_sec=L.<a class="code" href="classbdm_1_1logger.html#47aa3b098a81d02a8ffaea2c9fa09ac7">add</a>(rx,<span class="stringliteral">"d2"</span>); 
     214<a name="l00173"></a>00173         } 
     215<a name="l00174"></a>00174         <span class="keywordtype">void</span> logit(<a class="code" href="classbdm_1_1logger.html" title="Class for storing results (and semi-results) of an experiment.">logger</a> &amp;L){ 
     216<a name="l00175"></a>00175                 L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a>(L_err, interr); 
     217<a name="l00176"></a>00176                 L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a>(L_CRB,<a class="code" href="group__diag.html#gb0938c932c1cbc19b2ce6c5ac1007553" title="Get the diagonal elements of the input matrix m.">diag</a>(_R())); 
     218<a name="l00177"></a>00177                 L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a>(L_sec,secder); 
     219<a name="l00178"></a>00178         } 
     220<a name="l00179"></a>00179 }; 
     221<a name="l00180"></a>00180  
     222<a name="l00182"></a><a class="code" href="classpmsmCRBMz.html">00182</a> <span class="keyword">class </span><a class="code" href="classpmsmCRBMz.html" title="This class behaves like BM but it is evaluating EKF.">pmsmCRBMz</a> : <span class="keyword">public</span> <a class="code" href="classbdm_1_1EKFfull.html" title="Extended Kalman Filter in full matrices.">EKFfull</a>{ 
     223<a name="l00183"></a>00183         <span class="keyword">protected</span>: 
     224<a name="l00184"></a>00184                 <span class="keywordtype">int</span> L_CRB; 
     225<a name="l00185"></a>00185         <span class="keyword">public</span>: 
     226<a name="l00187"></a><a class="code" href="classpmsmCRBMz.html#3772392eb0db17741f771ad5ba38509f">00187</a>                 <a class="code" href="classpmsmCRBMz.html#3772392eb0db17741f771ad5ba38509f" title="constructor">pmsmCRBMz</a>():<a class="code" href="classbdm_1_1EKFfull.html" title="Extended Kalman Filter in full matrices.">EKFfull</a>(){} 
     227<a name="l00188"></a>00188  
     228<a name="l00189"></a><a class="code" href="classpmsmCRBMz.html#598b556bcccfa02c693830efaba679ef">00189</a>                 <span class="keywordtype">void</span> <a class="code" href="classpmsmCRBMz.html#598b556bcccfa02c693830efaba679ef" title="Here dt = [yt;ut] of appropriate dimensions.">bayes</a>(<span class="keyword">const</span> vec &amp;dt){ 
     229<a name="l00190"></a>00190 <span class="comment">//assume we know state exactly:</span> 
     230<a name="l00191"></a>00191                         vec true_state(5); 
     231<a name="l00192"></a>00192                         true_state.set_subvector(0,vec(x,4)); <span class="comment">// read from pmsm</span> 
     232<a name="l00193"></a>00193                         true_state(4)=x[8]; 
     233<a name="l00194"></a>00194                          
     234<a name="l00195"></a>00195                         E.<a class="code" href="classbdm_1_1enorm.html#8915d68ae76ad185c8c314f960a63f0c">set_mu</a>(true_state); 
     235<a name="l00196"></a>00196                         <a class="code" href="classbdm_1_1KalmanFull.html#2defb75e58892615c5f95fd844f3a666" title="Mean value of the posterior density.">mu</a> = true_state; 
     236<a name="l00197"></a>00197                         <span class="comment">//hack for ut</span> 
     237<a name="l00198"></a>00198                         <a class="code" href="classpmsmCRBMz.html#598b556bcccfa02c693830efaba679ef" title="Here dt = [yt;ut] of appropriate dimensions.">EKFfull::bayes</a>(dt); 
     238<a name="l00199"></a>00199                 } 
     239<a name="l00200"></a>00200          
     240<a name="l00201"></a><a class="code" href="classpmsmCRBMz.html#a5146d6e444d1ae19e71cea2b7400a85">00201</a>                 <span class="keywordtype">void</span> <a class="code" href="classpmsmCRBMz.html#a5146d6e444d1ae19e71cea2b7400a85" title="Add all logged variables to a logger.">log_add</a>(<a class="code" href="classbdm_1_1logger.html" title="Class for storing results (and semi-results) of an experiment.">logger</a> &amp;L, <span class="keyword">const</span> <span class="keywordtype">string</span> &amp;name=<span class="stringliteral">""</span> ){ 
     241<a name="l00202"></a>00202                         L_CRB=L.<a class="code" href="classbdm_1_1logger.html#47aa3b098a81d02a8ffaea2c9fa09ac7">add</a>(concat(rx,<a class="code" href="classbdm_1_1RV.html" title="Class representing variables, most often random variables.">RV</a>(<span class="stringliteral">"Mz"</span>,1,0)),<span class="stringliteral">"crbz"</span>); 
     242<a name="l00203"></a>00203                 } 
     243<a name="l00204"></a>00204                 <span class="keywordtype">void</span> logit(<a class="code" href="classbdm_1_1logger.html" title="Class for storing results (and semi-results) of an experiment.">logger</a> &amp;L){ 
     244<a name="l00205"></a>00205                         L.<a class="code" href="classbdm_1_1logger.html#397c014b0aaf3581516e2a105d26a5c9" title="log this vector">logit</a>(L_CRB,<a class="code" href="group__diag.html#gb0938c932c1cbc19b2ce6c5ac1007553" title="Get the diagonal elements of the input matrix m.">diag</a>(_R())); 
     245<a name="l00206"></a>00206                 } 
     246<a name="l00207"></a>00207 }; 
    205247</pre></div></div> 
    206 <hr size="1"><address style="text-align: right;"><small>Generated on Thu Apr 23 21:06:42 2009 for mixpp by&nbsp; 
     248<hr size="1"><address style="text-align: right;"><small>Generated on Tue Jun 2 10:02:12 2009 for mixpp by&nbsp; 
    207249<a href="http://www.doxygen.org/index.html"> 
    208250<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.8 </small></address>