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

robot/SerialManipulator

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: SerialManipulator,v 1.14 2002/09/18 17:08:44 jungd Exp $
00019   $Revision: 1.14 $
00020   $Date: 2002/09/18 17:08:44 $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _ROBOT_SERIALMANIPULATOR_
00026 #define _ROBOT_SERIALMANIPULATOR_
00027 
00028 #include <robot/robot>
00029 
00030 #include <base/array>
00031 #include <base/Serializer>
00032 #include <robot/Manipulator>
00033 
00034 
00035 namespace robot {
00036 
00037 
00038 /// Abstract interface for serial manipulator description classes.
00039 /**
00040  *  Describables serial manipulator via Denavit-Hartenberg parameters.
00041  */
00042 class SerialManipulator : public Manipulator
00043 {
00044 public:
00045 
00046   virtual Type type() const { return Serial; }
00047 
00048   /// Parameters for a single joint
00049   class JointParameters : public base::Serializable
00050   {
00051   public:
00052     enum JointType { Prismatic, Revolute };
00053 
00054     JointParameters() {}
00055     JointParameters(JointType type, Real alpha, Real a, Real d, Real theta,
00056                     Real minLimit, Real MaxLimit, Real minAccel=0, Real maxAccel=0,
00057                     bool active=true)
00058       : type(type), alpha(alpha), a(a), d(d), theta(theta),
00059         minLimit(minLimit), maxLimit(maxLimit), minAccel(minAccel), maxAccel(maxAccel),
00060         active(active)
00061       {}
00062     ~JointParameters() {}
00063 
00064     virtual String className() const { return String("JointParameters"); }
00065 
00066 
00067     JointType type;
00068 
00069     // Denavit-Hartenberg 
00070     Real alpha;  ///< twist angle (const) (radians)
00071     Real a;      ///< link length (const)
00072     Real d;      ///< distance between links (home pos)
00073     Real theta;  ///< angle between links (home pos) (radians)
00074 
00075     Real minLimit, maxLimit; ///< joint limits
00076     Real minAccel, maxAccel; ///< joint acceleration limits
00077     
00078     bool active; 
00079     
00080     bool operator==(const JointParameters& p)
00081     { return (type==p.type)
00082         && Math::equals(alpha,p.alpha) && Math::equals(theta,p.theta)
00083         && Math::equals(d,p.d) && Math::equals(a,p.a)
00084         && (active==p.active); 
00085     }
00086 
00087     bool operator!=(const JointParameters& p) { return !(*this == p); }
00088 
00089     virtual void serialize(base::Serializer& s)
00090     {
00091       s(type,"type");
00092       s(alpha,"alpha")(a,"a")(d,"d")(theta,"theta");
00093       s(minLimit,"minLimit")(maxLimit,"maxLimit"); 
00094       s(minAccel,"minAccel")(maxAccel,"maxAccel");
00095       s(active,"active");
00096     }
00097   };
00098 
00099   /// Parameters describing complete manipulator
00100   typedef base::array<JointParameters> Parameters;
00101 
00102   virtual const Parameters& getParameters() const = 0; ///< returns all of manipulator's joint parameters
00103   virtual Parameters& getParameters() = 0; ///< returns all of manipulator's joint parameters
00104 
00105   virtual void serialize(base::Serializer& s)
00106   {
00107     s(getName(),"name");
00108     s(getParameters(),"serialManipulatorParameters");
00109   }
00110 
00111 protected:
00112   SerialManipulator() {}
00113   SerialManipulator(const SerialManipulator& sm) : Manipulator(sm) {}
00114   SerialManipulator(String name) : Manipulator(name) {}
00115 
00116 };
00117 
00118 
00119 /// \todo consolidate the output operators
00120 inline std::ostream& operator<<(std::ostream& out, const robot::SerialManipulator& m) // Output
00121 {
00122   out << "D-H parameters for each joint: (* marks variable)\n";
00123   const robot::SerialManipulator::Parameters& p = m.getParameters();
00124 
00125   for(Int i=0; i<p.size(); i++) {
00126     const robot::SerialManipulator::JointParameters& j(p[i]);
00127     out << i << " - ";
00128 
00129     switch(j.type){
00130     case SerialManipulator::JointParameters::Revolute:  
00131       out << "Revolute :" << " alpha:" << Math::radToDeg(j.alpha) << ",  a:" << j.a << ",  d:" << j.d << ",  theta:"  << Math::radToDeg(j.theta) << "*\n"; 
00132       break;
00133     case SerialManipulator::JointParameters::Prismatic:  
00134       out << "Prismatic:" << " alpha:" << Math::radToDeg(j.alpha) << ",  a:" << j.a << ",  d:" << j.d << "*,  theta:"  << Math::radToDeg(j.theta) << "\n";
00135       break;
00136     }
00137   }
00138   return out;
00139 }
00140 
00141 
00142 inline std::ostream& operator<<(std::ostream& out, const robot::SerialManipulator::Parameters& p) // Output
00143 {
00144   out << "D-H parameters for each joint: (* marks variable)\n";
00145 
00146   for(Int i=0; i<p.size(); i++) {
00147     out << i << " - ";
00148 
00149     switch(p[i].type){
00150     case SerialManipulator::JointParameters::Revolute:  
00151       out << "Revolute :" << " alpha:" << Math::radToDeg(p[i].alpha) << ",  a:" << p[i].a << ",  d:" << p[i].d << ",  theta:"  << " * " << "\n"; 
00152       break;
00153     case SerialManipulator::JointParameters::Prismatic:  
00154       out << "Prismatic:" << " alpha:" << Math::radToDeg(p[i].alpha) << ",  a:" << p[i].a << ",  d:" << " * " << ",  theta:"  << Math::radToDeg(p[i].theta) << "\n";
00155       break;
00156     }
00157   }
00158   return out;
00159 }
00160 
00161 
00162 
00163 inline std::ostream& operator<<(std::ostream& out, const robot::SerialManipulator::JointParameters& j) // Output
00164 {
00165 
00166   out << "D-H parameters for joint: (* marks variable)\n";
00167 
00168   switch(j.type){
00169     case SerialManipulator::JointParameters::Revolute:  
00170       out << "Revolute :" << " alpha:" << Math::radToDeg(j.alpha) << ",  a:" << j.a << ",  d:" << j.d << ",  theta:"  << " * " << "\n"; 
00171       break;
00172     case SerialManipulator::JointParameters::Prismatic:  
00173       out << "Prismatic:" << " alpha:" << Math::radToDeg(j.alpha) << ",  a:" << j.a << ",  d:" << " * " << ",  theta:"  << Math::radToDeg(j.theta) << "\n";
00174       break;
00175   }
00176   return out;
00177 }
00178 
00179 } // robot
00180 
00181 #endif

Generated on Thu Nov 21 23:58:04 2002 for OpenSim by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002