Changeset 1130 for library

Show
Ignore:
Timestamp:
07/09/10 12:39:41 (15 years ago)
Author:
smidl
Message:

Basic outline of universal LQG controller

Location:
library
Files:
1 added
3 modified

Legend:

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

    r1064 r1130  
    2020//! \note advanced Controllers will probably include estimator as their internal attribute (e.g. dual controllers) 
    2121class Controller : public root { 
    22 protected: 
     22  public: 
    2323    //! identifier of the designed action; 
    2424    RV rv; 
     25protected: 
    2526    //! identifier of the conditioning variables - data needed ; 
    2627    RV rvc; 
  • library/bdm/math/functions.h

    r1064 r1130  
    3838//! Class representing function \f$f(x) = Ax+B\f$ 
    3939class linfn: public fnc { 
     40  public: 
    4041    //! Identification of \f$x\f$ 
    4142    RV rv; 
     
    5354    //!default constructor 
    5455    linfn ( ) : fnc(), A ( ), B () { }; 
     56    linfn ( const mat &A0, const vec &B0 ) : fnc(), A (A0 ), B (B0) { }; 
    5557    //! Set values of \c A and \c B 
    5658    void set_parameters ( const mat &A0 , const vec &B0 ) { 
     
    7072UIREGISTER(linfn); 
    7173 
     74 
     75//! Class representing function \f$ f(x) = [x' 1] Q [x' 1]' \f$ with Q in choleski decomposition 
     76class quadraticfn: public fnc { 
     77public : 
     78    //! Identification of \f$x\f$ 
     79    RV rv; 
     80    //! Matrix Q 
     81    chmat Q; 
     82 
     83     
     84    vec eval ( const vec &cond ) { 
     85        bdm_assert_debug ( cond.length() == Q.cols(), "quadraticfc::eval Wrong cond." ); 
     86        return vec_1( Q.qform(concat(cond,1.0)) ); 
     87    } 
     88 
     89    void from_setting(const Setting &set) { 
     90//        UI::get(Q,set,"Q",UI::compulsory); 
     91    } 
     92    void validate() { 
     93        dimy = 1; 
     94        dimc = Q.cols()-1; 
     95    } 
     96 
     97}; 
     98UIREGISTER(quadraticfn); 
    7299 
    73100/*! 
  • library/tests/testsuite/LQG_test.cpp

    r1064 r1130  
    11#define BDMLIB 
    22#include "../mat_checks.h" 
    3 #include "design/ctrlbase.h" 
     3#include "design/lq_ctrl.h" 
    44 
    55using namespace bdm; 
     
    9191    cout << L.to_string() << endl; 
    9292} 
     93 
     94TEST (quadratic_test){ 
     95  quadraticfn qf; 
     96  qf.Q = chmat(2); 
     97  qf.Q._Ch() = mat("1 -1 0; 0 0 0; 0 0 0"); 
     98  CHECK_CLOSE_EX(qf.eval(vec("1 2")), vec_1(1.0), 0.0000000000000001); 
     99   
     100  LQG_universal lq; 
     101  lq.Losses = Array<quadraticfn>(1); 
     102  lq.Losses(0) = quadraticfn(); 
     103  lq.Losses(0).Q._Ch() = mat("1 -1 0; 0 0 0; 0 0 0"); 
     104  lq.Losses(0).rv = RV("{u up }"); 
     105   
     106  lq.Models = Array<linfn>(1); 
     107  lq.Models(0) = linfn(mat("1"),vec("1")); 
     108  lq.Models(0).rv = RV("{x }"); 
     109   
     110  lq.rv = RV("u",1); 
     111   
     112  lq.redesign(); 
     113  CHECK_CLOSE_EX(lq.ctrlaction(vec("1,0")), vec("1.24, -5.6"), 0.0000001); 
     114}