lcp.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * The University of Tokyo
00008  */
00016 #ifndef __LCP_H__
00017 #define __LCP_H__
00018 
00019 #include <fMatrix.h>
00020 #include <vector>
00021 #include <assert.h>
00022 
00023 //#define PIVOT_MINIMUM_ONLY  // only for test
00024 //#define INVERSE_FROM_SCRATCH  // turn off to compute inverse incrementally
00025 #define ACTIVATE_SAME_STATE  // activate same state check during planning
00026 
00032 class LCP
00033 {
00034 public:
00036 
00041         LCP(const fMat& _NN, const fVec& _r): N(_NN), r(_r) {
00042                 assert(N.row() == N.col());
00043                 assert(N.row() == r.size());
00044                 n_vars = N.col();
00045         }
00046         ~LCP() {
00047         }
00048         
00050 
00055         int Solve(fVec& g, fVec& a);
00056 
00058 
00068         int SolveEx(fVec& g, fVec& a, const fVec& g_init, double _max_error = 1e-8, int _max_iteration = 100, double _speed = 0.5, int* n_iteration = 0);
00069 
00071 
00080         int SolvePivot(fVec& g, fVec& a, double _max_error, int _max_iteration, int* n_iteration, std::vector<int>& _g2w);
00081 
00083 
00092         int SolvePivot2(fVec& g, fVec& a, double _max_error, int _max_iteration, int* n_iteration, std::vector<int>& _g2w);
00093 
00094         static void Pivot(int idx1, int idx2,
00095                                           const fMat& M, const fVec& q,
00096                                           fMat& M_new, fVec& q_new);
00097         static void Pivot(std::vector<int>& idx1, std::vector<int>& idx2,
00098                                           const fMat& M, const fVec& q,
00099                                           fMat& M_new, fVec& q_new);
00100         static void Pivot(std::vector<int>& w2a, std::vector<int>& w2g,
00101                                           std::vector<int>& z2a, std::vector<int>& z2g,
00102                                           const fMat& M, const fVec& q,
00103                                           fMat& M_new, fVec& q_new);
00104         static void Pivot(const fMat& M, const fVec& q,
00105                                           std::vector<int>& w2a, std::vector<int>& w2g,
00106                                           std::vector<int>& z2a, std::vector<int>& z2g,
00107                                           int new_jr,
00108                                           fMat& m_jr, fVec& q_new);
00109         static void Pivot(const fMat& M, const fVec& q,
00110                                           const fMat& oldMinv,
00111                                           std::vector<int>& old_w2a, std::vector<int>& old_w2g,
00112                                           std::vector<int>& old_z2a, std::vector<int>& old_z2g,
00113                                           int ys2a, int ys2g, int yr2a, int yr2g,
00114                                           std::vector<int>& w2a, std::vector<int>& w2g,
00115                                           std::vector<int>& z2a, std::vector<int>& z2g,
00116                                           int jr,
00117                                           fMat& newMinv, fMat& m_jr, fVec& q_new);
00118 
00119         double CheckPivotResult(const fVec& q_new, std::vector<int>& w2a, std::vector<int>& w2g);
00120 
00121         const fMat& Mref() {
00122                 return M;
00123         }
00124         const fVec& Qref() {
00125                 return q;
00126         }
00127 
00128         int NumLoops();
00129         int NumErrors();
00130         
00131 protected:
00132         static void pivot_body(const fMat& M12, const fMat& M1, const fMat& M2, const fMat& M12bar, const fVec& q1, const fVec& q1bar, fMat& Md12, fMat& Md1, fMat& Md2, fMat& Md12bar, fVec& qd1, fVec& qd1bar);
00133 
00134         int check_q(const fVec& q, double max_error) {
00135                 for(int i=0; i<n_vars; i++)
00136                 {
00137                         if(q(i) < -max_error)
00138                         {
00139                                 return false;
00140                         }
00141                 }
00142                 return true;
00143         }
00144 
00145         fMat N;
00146         fVec r;
00147         int n_vars;
00148 
00149         fMat M;
00150         fVec q;
00151 };
00152 
00153 #endif


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:17