コード例 #1
0
ファイル: lqr.cpp プロジェクト: janfrs/kwc-ros-pkg
void test_randomDiscrete(int n, int m, int repeats=1)
{
  ASSERT_TRUE(N==n||N==Dynamic);
  ASSERT_TRUE(M==m||M==Dynamic);
  
  typedef typename Eigen::Matrix<Scalar,N,N> AMatrix;
  typedef typename Eigen::Matrix<Scalar,N,1> AVector;
  typedef typename Eigen::Matrix<Scalar,N,M> BMatrix;
  typedef typename Eigen::Matrix<Scalar,M,N> GMatrix;
  typedef typename Eigen::Matrix<Scalar,M,M> WMatrix;
  
  AMatrix Q = AMatrix::Random(n,n);
  Q*=Q.transpose();
  WMatrix R = WMatrix::Random(m,m);
  R*=R.transpose();
  
  GMatrix G(m,n);
  
  for(int i=0;i<repeats;++i)
  {
    const AMatrix & A = 3*AMatrix::Random(n,n);
    const BMatrix & B = 3*BMatrix::Random(n,m);
    
    if(LQR::isCommandable(A,B))
    {
      LQR::LQRDP<AMatrix,BMatrix,AMatrix,BMatrix>::run(A,B,Q,Q,R,0.01,G);
      const AVector & x0 = AVector::Random(n,1);
      ASSERT_TRUE(test_convergenceDiscrete(A+B*G,x0));
      ASSERT_TRUE(LQR::isConvergingDiscrete(A,B,G));
    }   
  }
}
コード例 #2
0
ファイル: lqr.cpp プロジェクト: janfrs/kwc-ros-pkg
void test_random(int n, int m, int repeats=1)
{
  ASSERT_TRUE(N==n||N==Dynamic);
  ASSERT_TRUE(M==m||M==Dynamic);
  
  typedef typename Eigen::Matrix<Scalar,N,N> AMatrix;
  typedef typename Eigen::Matrix<Scalar,N,1> AVector;
  typedef typename Eigen::Matrix<Scalar,N,M> BMatrix;
  typedef typename Eigen::Matrix<Scalar,M,N> GMatrix;
  typedef typename Eigen::Matrix<Scalar,M,M> WMatrix;
  
  GMatrix G(m,n);
  
  for(int i=0;i<repeats;++i)
  {
    AMatrix Q = AMatrix::Random(n,n);
    Q*=Q.transpose();
    WMatrix R = WMatrix::Random(m,m);
    R*=R.transpose();
    
    const AMatrix & A = AMatrix::Random(n,n);
    const BMatrix & B = BMatrix::Random(n,m);
    
    if(LQR::isCommandable(A,B))
    {
      LQR::LQRDP<AMatrix,BMatrix,AMatrix,BMatrix>::runContinuous(A,B,Q,R,G);
      
      ASSERT_TRUE(LQR::isConverging(A,B,G));
      //This test might fail for big matrices => disabled
//       const AVector & x0 = 10*AVector::Random(n,1);
//       ASSERT_TRUE(test_convergence(A+B*G,x0,0.1));
    }   
  }
}