Show
Ignore:
Timestamp:
08/12/09 16:47:33 (15 years ago)
Author:
smidl
Message:

LQG basic implementation

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/design/ctrlbase.cpp

    r491 r508  
    1 #include <ctrlbase.h> 
     1#include "ctrlbase.h" 
    22 
    3 LQG::set_system_parameters(const mat &A0, const mat &B0, const mat &C0){ 
     3namespace bdm{ 
     4 
     5void LQG::set_system_parameters(const mat &A0, const mat &B0, const mat &C0){ 
    46        dimx = A0.rows(); 
    57        dimy = C0.rows(); 
     
    1315        B=B0; 
    1416        C=C0; 
    15          
    16         // set temporary stuff; 
    17         pr = concat_vertical(  
    18                                         concat_horizontal(B,A, zeros(dimx, dimu+dimy)), 
    19                                         concat_horizontal(zeros(dimu+dimy,dimu+dimx), eye(dimu+dimy))); 
     17        pr=zeros(dimx+dimu+dimy,  dimu+dimx+dimu+dimy); 
     18        pr.set_submatrix(dimx, dimu+dimx, eye(dimu+dimy)); 
     19} 
     20 
     21void LQG::set_control_parameters(const mat &Qy0, const mat &Qu0, const vec y_req0, int horizon0){ 
     22        it_assert_debug ( Qy0.cols() == dimy, "LQG: wrong dimensions of Qy " ); 
     23        it_assert_debug ( Qu0.cols() == dimu, "LQG: wrong dimensions of Qu " ); 
     24        it_assert_debug ( y_req0.length() == dimy, "LQG: wrong dimensions of y_req " ); 
     25 
     26        Qy=Qy0; 
     27        Qu=Qu0; 
     28        y_req=y_req0; 
     29        horizon = horizon0; 
     30        prepare_qr(); 
     31} 
     32 
     33void LQG::prepare_qr(){ 
     34        // set parameter matrix 
     35        pr.set_submatrix(0,0,B); 
     36        pr.set_submatrix(0,dimu, A); 
    2037         
    2138        //penalization 
     
    2441        qux.set_submatrix(0,dimx+dimu+dimy,Qu); 
    2542 
    26         qyx=concat_horizontal(C,-eye(dimy),zeros(dimy,dimu)); 
     43        qyx=zeros(dimy, dimx+dimy+dimu); 
     44        qyx.set_submatrix(0,0,C); 
     45        qyx.set_submatrix(0,dimx,-eye(dimy)); 
    2746         
    2847        // 
    29         s=1e-5*eye(dimx+dimu+dimy); 
     48        s=1e-5*eye(4);//dimx+dimu+dimy); 
    3049        // parts of QR 
    3150        hqy=Qy*qyx*pr; 
    3251         
    3352        // pre_qr 
    34         pre_qr = concat_vertical(s*pr, hqy, qux); 
    35          
     53        pre_qr = concat_vertical(s*pr, concat_vertical(hqy, qux)); 
     54        post_qr = zeros(pre_qr.rows(), pre_qr.cols()); 
    3655} 
     56 
     57}