Changeset 1184 for applications/pmsm

Show
Ignore:
Timestamp:
09/10/10 11:11:41 (14 years ago)
Author:
smidl
Message:

corrections of PMSM simulations

Location:
applications/pmsm
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • applications/pmsm/CMakeLists.txt

    r1168 r1184  
    3030 
    3131EXEC (pmsm_estim pmsmsim ekf_obj) 
     32MEX (pmsm_estim pmsmsim ekf_obj) 
    3233#EXEC (sim pmsmsim) 
    3334#EXEC (sim_var pmsmsim) 
  • applications/pmsm/TR2245/CMakeLists.txt

    r744 r1184  
    11# Make sure the compiler can find include files from our Bdm library. 
    2 EXEC (unitsteps pmsmsim) 
    3 EXEC (wishart pmsmsim) 
     2#EXEC (unitsteps pmsmsim) 
     3#EXEC (wishart pmsmsim) 
    44#EXEC (pmsm_wishart pmsmsim) 
  • applications/pmsm/pmsm.h

    r1160 r1184  
    364364UIREGISTER ( OMpmsmRO ); 
    365365 
     366class OMpmsmROMz: public OMpmsmRO{ 
     367public: 
     368        OMpmsmROMz() :OMpmsmRO() {dimy=2;dimx=5;dimu=0;}; 
     369}; 
     370UIREGISTER ( OMpmsmROMz ); 
    366371 
    367372//! Observation model for PMSM drive and its derivative with respect to \f$x\f$ for full vector of observations 
  • applications/pmsm/pmsm_estim.cpp

    r1174 r1184  
    1515 
    1616using namespace bdm; 
     17#ifdef MEX 
     18#include <itpp/itmex.h> 
     19#include <mex/mex_BM.h> 
     20#include <mex/mex_logger.h> 
     21#include <mex/mex_datasource.h> 
     22#include <mex/mex_function.h> 
     23 
     24void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { 
     25        // Check the number of inputs and output arguments 
     26        if ( n_input<2 ) mexErrMsgTxt ( "Usage:\n" 
     27                                                "[Res,estimators,Res2]=estimator(system, estimators, experiment, logger)\n" 
     28                                                "  system     = struct('class','datasource',...);  % Estimated system\n" 
     29                                                "  estimators = {struct('class','estimator',...),  % Estimators\n" 
     30                                                "                struct('class','estimator',...),...} \n" 
     31                                                "  === optional ===" 
     32                                                "  experiment = struct('ndat',10);                 % number of data in experiment, full length of finite datasources, 10 otherwise \n" 
     33                                                "  logger     = struct('class','mexlogger');       % How to store results, default=mexlog, i.e. matlab structure\n\n" 
     34                                                "Output:\n" 
     35                                                "  Res          Matlab structure with logged results, \n"   
     36                                                "  estimators   Array of estimators updated with data \n" 
     37                                                "  Res2         When logfull log_level is on, this structure is filled with structures of posterior densities\n\n" 
     38                                                "see documentation of classes datasource, BM, and mexlogger and their offsprings in BDM." ); 
     39 
     40        RV::clear_all(); 
     41        //CONFIG 
     42        UImxArray F; 
     43        try { 
     44                F.addGroup ( input[0],"system" ); 
     45                F.addList ( input[1],"estimators" ); 
     46                if ( n_input>2 ) { 
     47                        F.addGroup ( input[2],"experiment" ); 
     48                } 
     49                if ( n_input>3 ) { 
     50                        F.addGroup ( input[3],"logger" ); 
     51                } 
     52        } catch ( SettingException e ) { 
     53                it_error ( "error: "+string ( e.getPath() ) ); 
     54        } 
     55 
     56        //DBG 
     57        F.writeFile ( "pmsm_estim.cfg" ); 
     58 
     59#else 
    1760int main ( int argc, char* argv[] ) { 
    1861        const char *fname; 
     
    2063        else { cout << "Missing configuration file.\n Usage: \n $> estimator config_file.cfg"<<endl; abort(); } 
    2164        UIFile F ( fname ); 
    22  
     65#endif 
     66         
    2367        shared_ptr<logger> L = UI::build <logger>( F, "logger" ); 
    2468        shared_ptr<DS>  pDS = UI::build<DS> ( F, "system" ); 
    2569        Array<shared_ptr<BM> > Es;                      // array of estimators 
    26         UI::get( Es, F, "estimator" ); 
     70        UI::get( Es, F, "estimators" ); 
    2771        int nE = Es.length();   //number of estimators 
    2872        int Ndat;                               //number of data records 
    2973        F.lookupValue ( "experiment.ndat",Ndat ); 
    30                  
     74                         
     75        if ( !L ) { 
     76        #ifdef MEX 
     77                        //mex logger has only from_setting constructor - we  have to fill it... 
     78                        L=new mexlog ( Ndat ); 
     79        #else 
     80                        L=new stdlog(); 
     81        #endif 
     82                } 
    3183        pDS->log_register ( *L, "true" ); 
    3284        string Ename; 
     
    67119 
    68120        L->finalize(); 
     121#ifdef MEX 
     122        mexlog* mL=dynamic_cast<mexlog*> ( L.get() ); 
     123 
     124        if ( mL ) { // user wants output!! 
     125                if ( n_output<1 ) mexErrMsgTxt ( "Wrong number of output variables!" ); 
     126                output[0] = mL->toCell(); 
     127                if (n_output>1){ // write estimators 
     128                        UImxArray Ests; 
     129                        UI::save(Es, Ests,"estimators"); 
     130                        output[1]=UImxArray::create_mxArray(Ests); 
     131                } 
     132                if (n_output>2) { 
     133                        mL->_setting_conf().setAutoConvert(true); 
     134                        output[2]= UImxArray::create_mxArray(mL->_setting_conf().getRoot()); 
     135                } 
     136        } 
     137#endif 
    69138 
    70139        for (int i=0; i<nE; i++){ 
     
    72141                delete Dlsc(i); 
    73142        } 
    74         return 0; 
    75143} 
    76144 
  • applications/pmsm/pmsm_estim_mex.cpp

    r706 r1184  
    77 */ 
    88 
    9 #include "pmsm.h" 
    10 #include "stat/loggers.h" 
     9#include "base/user_info.h" 
     10#include "base/loggers.h" 
    1111#include "estim/kalman.h" 
     12#include "pmsmDS.h" 
     13#include "filters.h" 
     14#include "base/datasources.h" 
     15#include "simulator_zdenek/ekf_example/ekf_obj.h" 
    1216 
    1317#include <itpp/itmex.h> 
    14 #include "../../library/mex/mex_logger.h" 
    15 #include "../../library/mex/mex_datasource.h" 
    16 #include "../../library/mex/mex_parser.h" 
     18#include <mex/mex_BM.h> 
     19#include <mex/mex_logger.h> 
     20#include <mex/mex_datasource.h> 
     21#include <mex/mex_function.h> 
    1722 
    1823using namespace bdm; 
  • applications/pmsm/simulator_zdenek/ekf_example/matrix_vs.cpp

    r1182 r1184  
    217217            sigma += (((long)(*PSIU_ik)**PSIU_ik)>>15)*(*Dold_i); 
    218218                } 
    219                 sigma += *(Q+i+irows); 
     219                sigma += *(Q+i+irows)<<15; 
    220220        for (j=i+1, G_ik=G+irows+i+1; j<rows; j++,G_ik++) { 
    221221            sigma += (((long)(*G_ik)**G_ik)>>13)**(Q+j+j*rows);