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

robot/control/kinematics/BetaFormConstraints

Go to the documentation of this file.
00001 /* **-*-c++-*-**************************************************************
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: BetaFormConstraints 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 #ifndef _ROBOT_CONTROL_KINEMATICS_BETAFORMCONSTRAINTS_
00026 #define _ROBOT_CONTROL_KINEMATICS_BETAFORMCONSTRAINTS_
00027 
00028 #include <robot/control/kinematics/kinematics>
00029 
00030 #include <sstream>
00031 
00032 #include <base/Named>
00033 #include <robot/control/kinematics/Optimizer>
00034 
00035 
00036 namespace robot {
00037 namespace control {
00038 namespace kinematics {
00039 
00040 
00041 /// Representation of a Optimizer::Constraints expressed in the form of a beta expression
00042 ///   (and optionally a single non-holonomic constraint in the form of an alpha expression).
00043 /**
00044  * Paper 1 below introduces an analytic optimization method where the constraints are
00045  *  expressed in terms betajs
00046  *  betaj . t - 1 = 0, j=1..r 
00047  *
00048  * Paper 2 below adds a non-holonomic constraint expressed terms of alpha
00049  *  alpha^T . t = 0
00050  *  
00051  * This class represents the constraints in this form.
00052  *
00053  * see 1. "Resolving Kinematic Redundancy with Constraints 
00054  * Using the FSP (Full Space Parameterization) Approach", Francois G. Pin & Faithlyn A. Tulloch,
00055  * Proceedings of the 1996 IEEE International Conference on Robotics and Automation.
00056  *
00057  * see 2. "Motion Planning for Mobile Manipulators with a Non-Holonomic Constraint
00058  * Using the FSP (Full Space Marameterization) Method", Francois G. Pin, Kristi A. Morgansen,
00059  * Faithlyn A. Tulloch, Charles J. Hacker and Kathryn B. Gower,
00060  * Journal of Robotic Systems 13(11), 723-736 (1996).
00061  */
00062 class BetaFormConstraints : public Optimizer::Constraints
00063 {
00064 public:
00065   /// Abstract interface for a constraint expressed in beta form
00066   class BetaFormConstraint : public base::ReferencedObject, public base::Named
00067   {
00068   public:
00069     BetaFormConstraint() : Named(className()), id(0) {}
00070     BetaFormConstraint(const BetaFormConstraint& bc) : Named(bc), id(bc.id), beta(bc.beta) {}
00071     BetaFormConstraint(const Vector& beta) : id(0), beta(beta) { setName(className()); }
00072 
00073     virtual String className() const { return String("BetaFormConstraint"); }
00074     
00075     virtual Int    getID() const { return id; }
00076     virtual void   setID(Int id) { this->id = id; }
00077     
00078     virtual Vector getBeta() const { return beta; }
00079 
00080     virtual String toString() const { return String(); }
00081     
00082   protected:
00083     Int id; ///< user specified id (not interpreted by this)
00084     Vector beta;
00085   };
00086 
00087 
00088   BetaFormConstraints() 
00089     : numBetas(0), nonholonomicConstraint(false) {}
00090 
00091   virtual String className() const { return String("BetaFormConstraints"); }
00092 
00093   virtual ConstraintsType getConstraintsType() const              { return Linear; }
00094   virtual ConstraintType  getConstraintType(Int constraint) const { return Equality; }
00095   virtual Int numConstraints() const           { return numBetas+(nonholonomicConstraint?1:0); }
00096   virtual Int numEqualityConstraints() const   { return numConstraints(); }
00097   virtual Int numInequalityConstraints() const { return 0; }
00098   
00099   virtual Real   evaluate(Int constraint, const Vector& x, const Vector& a) const
00100     {
00101       Assert( constraint < numConstraints() );
00102       const Vector& t(a);
00103       if (constraint < numBetas) { // eval beta
00104         Assert(t.size() == betas.size1());
00105         return (inner_prod(matrixColumn(betas,constraint),t) - 1.0);
00106       }
00107       else  { // eval alpha
00108         Assert(t.size() == alpha.size());
00109         return inner_prod(alpha, t);
00110       }
00111     }
00112 
00113   virtual Vector evaluate(const Vector& x, const Vector& a) const
00114     {
00115       const Vector& t(a);
00116       Vector C(numConstraints());
00117       for(Int c=0; c<numBetas; c++)
00118         C[c] = (inner_prod(matrixColumn(betas,c),t) - 1.0);
00119       if (nonholonomicConstraint)
00120         C[numConstraints()-1] = inner_prod(alpha, t);
00121       return C;
00122     }
00123 
00124 
00125   void addConstraint(ref<BetaFormConstraint> constraint)
00126     { 
00127       constraints.push_back(constraint);
00128       
00129       Vector beta(constraint->getBeta());
00130 
00131       // resize Matrix if necessary
00132       if (numBetas == 0) {
00133         betas.resize(beta.size(),16);
00134       }
00135       else {
00136         if (numBetas == betas.size2()) {
00137           // double no. of columns and copy betas to new Matrix
00138           Matrix newbetas(betas.size1(), betas.size2()*2);
00139           matrixRange(newbetas,Range(0,betas.size1()),Range(0,numBetas)) = betas;
00140           betas = newbetas;
00141         }
00142       }
00143 
00144       Assert( beta.size() == betas.size1() );
00145       matrixColumn(betas,numBetas) = beta;
00146       ++numBetas;
00147     }
00148 
00149   void setAlphaConstraint(const Vector& alpha)
00150     {
00151       nonholonomicConstraint = true;
00152       this->alpha.reset(alpha);
00153     }
00154 
00155   bool isAlphaConstraint() const { return nonholonomicConstraint; }
00156 
00157   
00158   void clear() { betas.resize(0,0); numBetas=0; constraints.clear(); nonholonomicConstraint = false; }
00159   ref<BetaFormConstraint> getConstraint(Int i) { return constraints[i]; }
00160   Vector getBeta(Int i) const { return matrixColumn(betas,i); }
00161   
00162   Vector getAlpha() const { return nonholonomicConstraint?alpha:Vector(); }
00163 
00164 
00165   /// get Matrix of beta column vectors 
00166   Matrix getBetas() const 
00167   {
00168     Matrix allbetas(betas.size1(), numBetas);
00169     allbetas = matrixRange(betas,Range(0,betas.size1()), Range(0,numBetas));
00170     return allbetas;
00171   } 
00172 
00173   Int  numBetaConstraints() const { return numBetas; }
00174 
00175   
00176   String toString() const
00177   {
00178     std::ostringstream str;
00179     if (nonholonomicConstraint) 
00180       str << "non-holonomic alpha=" << alpha << "\n";
00181     for(Int i=0; i<numBetaConstraints(); i++) {
00182       ref<BetaFormConstraint> bfc(constraints[i]);
00183       str << bfc->getName() << "[id:" << bfc->getID() << "]: " << bfc->toString() << "\n";
00184     }
00185     return str.str();
00186   }
00187   
00188 protected:
00189   typedef array< ref<BetaFormConstraint> > ConstraintArray;
00190 
00191   Int numBetas;
00192   ConstraintArray constraints;  ///< array of constraints (index corresponds to betas matrix column)
00193   Matrix betas;                 ///< columns vectors (no. cols is may be larger than necessary (numBetas))
00194   bool nonholonomicConstraint;  ///< is there a non-holonomic constraint specified via alpha?
00195   Vector alpha;                 ///< alpha form non-holonomic constraint
00196 };
00197   
00198 
00199 inline std::ostream& operator<<(std::ostream& out, const BetaFormConstraints::BetaFormConstraint& bc)
00200 { out << bc.toString(); return out; }
00201 
00202 inline std::ostream& operator<<(std::ostream& out, const BetaFormConstraints& bcs)
00203 { out << bcs.toString(); return out; }
00204 
00205   
00206 
00207 } // namespace kinematics
00208 } // namespace control
00209 } // namespace robot
00210 
00211 #endif
00212 

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