Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

robot/control/kinematics/LeastNormIKSolver.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)2002 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: LeastNormIKSolver.cpp 1036 2004-02-11 20:48:55Z jungd $
00019   $Revision: 1.7 $
00020   $Date: 2004-02-11 15:48:55 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #include <robot/control/kinematics/LeastNormIKSolver>
00026 
00027 using robot::control::kinematics::LeastNormIKSolver;
00028 
00029 using base::Vector;
00030 using base::Orient;
00031 using robot::control::kinematics::MPPseudoInvSolver;
00032 
00033 
00034 LeastNormIKSolver::LeastNormIKSolver()
00035 {
00036   solver = ref<MPPseudoInvSolver>(NewObj MPPseudoInvSolver());
00037 }
00038 
00039 
00040 const Real small = 5.0e-05; 
00041 
00042 
00043 Vector LeastNormIKSolver::solve(const Vector& dx, const Vector& x, const Vector& q,
00044                                 const base::Matrix& J,
00045                                 OptimizationMethod    optMethod,
00046                                 OptimizationCriterion optCriterion,
00047                                 OptimizationConstraints optConstraints,
00048                                 base::Orient::Representation  orientationRepresentation)
00049 {
00050   if (optMethod==DefaultMethod) optMethod=PseudoInv;
00051   if (optCriterion==DefaultCriterion) optCriterion=LeastNorm;
00052   if (optConstraints.test(DefaultConstraints)) optConstraints.reset();
00053 
00054   Assertm(optCriterion==LeastNorm, "criterion is leastnorm (no optimization involved for this method)");
00055   Assertm(optMethod==PseudoInv, "method is pseudo-inverse (no other method supported)");
00056   Assertm(optConstraints.none(), "no constraints (none supported)");
00057 
00058   const Int N = J.size1(); // rows
00059   const Int M = J.size2(); // cols
00060 
00061   Assert(dx.size() == x.size());
00062   Assert(q.size() == M);
00063 
00064   // First, convert the orientation component of dx (if any) to
00065   //  angular velocity (omega)
00066   Vector newdx;
00067   if (N>3) {
00068     Vector dpos(3);
00069     dpos = vectorRange(dx,Range(0,3));
00070     Orient orient(vectorRange(x,Range(3,x.size())),orientationRepresentation);
00071     Orient dorient(vectorRange(dx,Range(3,dx.size())),orientationRepresentation);
00072     Vector omega(3);
00073     omega = orient.getBinv()*Vector(dorient); // w = B(o)^-1 . do/dt
00074     newdx.resize(6);
00075     vectorRange(newdx,Range(0,3)) = dpos;
00076     vectorRange(newdx,Range(3,6)) = omega;
00077   }
00078   else
00079     newdx.reset(dx);
00080 
00081   // special case - if dx==0 (null-space), only trivial solution (dq=0) is possible
00082   if (base::equals(dx,zeroVector(N),small))
00083     return zeroVector(M);
00084 //!!!Debugln(DJ,"dx=" << dx << " dq=" << solver->solve(J, newdx));  
00085   // solve dq = J(q)dx, for least-norm dq via M-P pseudo-inverse
00086   return solver->solve(J, newdx);
00087 }

Generated on Thu Jul 29 15:56:33 2004 for OpenSim by doxygen 1.3.6