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