root/applications/bdmtoolbox/mex/lqg_redesign.cpp @ 733

Revision 733, 2.0 kB (checked in by smidl, 14 years ago)

LQG wrapper in bdm toolbox + related stuff

Line 
1/*!
2\file
3\brief wrapper function for lqg.redesign()
4
5
6 */
7
8#include <design/arx_ctrl.h>
9
10using namespace bdm;
11
12#ifdef MEX
13#include <mex/mex_parser.h>
14#include <mex/config2mxstruct.h>
15
16void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) {
17        // Check the number of inputs and output arguments
18        if ( n_input<1 ) mexErrMsgTxt ( 
19                " LQ controller of the given system according to criteria\n"
20                "              L = y' Qy y + u' Qu u \n\n"
21                "Usage:\n"
22                "[vec,rv]=lqg_redesign(system,params)\n"
23                "  system = struct('class','mlnorm',...);  % description of linear Gaussian system \n"
24                "  params = struct('Qy',[], 'Qu',[], 'yr',[],'horizon', [1]);  \n"
25                "output:\n"
26                "  vec  vector of the controller.\n"
27                "  rv   varibles in regressor of the controller.\n");
28
29        RV::clear_all();
30        //CONFIG
31        if (!mxIsStruct(input[0])) mexErrMsgTxt("Given input is not a struct.");
32        if ((n_input<2)||(!mxIsStruct(input[1]))) mexErrMsgTxt("Second parametr is not a structure.");
33               
34        UImxArray Cfg;
35        Cfg.addGroup ( input[0],"system" );
36        Cfg.addGroup ( input[1],"params" );
37        Cfg.writeFile("lqg_redesign.cfg");
38
39        // load stuff
40        shared_ptr<mlnorm<chmat> > ml=UI::build<mlnorm<chmat> >(Cfg,"system");
41        if (!ml) {mexErrMsgTxt("Incorrect input #1");}
42       
43        Setting &params=Cfg.getRoot()["params"];
44        mat Qu;
45        mat Qy;
46        int horizon;
47        vec yr;
48       
49        UI::get(Qy, params, "Qy",UI::compulsory);
50        UI::get(Qu, params, "Qu",UI::compulsory);
51        UI::get(yr, params, "yr",UI::compulsory);
52        UI::get(horizon, params, "horizon", UI::compulsory);
53       
54                                  // set it up
55        shared_ptr<StateFromARX> Stsp=new StateFromARX;
56        RV xrv;
57        RV urv;
58        Stsp->connect_mlnorm(*ml,xrv,urv);
59       
60        LQG lq;
61        lq.set_system(Stsp);
62        lq.set_control_parameters(Qy,Qu,yr,horizon);
63        lq.validate();
64        lq.redesign();
65       
66        mat L = lq._L();
67        RV rv = lq._rvc();
68       
69        if ( n_output<1 ) mexErrMsgTxt ( "No output - nothing to do!" );
70        output[0] = mxCreateDoubleMatrix(L.rows(),L.cols(), mxREAL);
71        mat2mxArray(L, output[0]);
72        if (n_output>1){
73                Config C; 
74                rv.to_setting(C.getRoot());
75                UImxConfig ui(C.getRoot());
76                output[1] = ui.mxconfig;
77        }
78               
79}
80#endif
Note: See TracBrowser for help on using the browser.