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

robot/Robot.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)2003 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: Robot.cpp 1039 2004-02-11 20:50:52Z jungd $
00019   $Revision: 1.4 $
00020   $Date: 2004-02-11 15:50:52 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #include <robot/Robot>
00026 
00027 #include <base/Matrix4>
00028 
00029 
00030 using robot::Robot;
00031 
00032 using base::Matrix4;
00033 using base::Orient;
00034 using base::array;
00035 
00036 
00037 array<std::pair<String,String> > Robot::controlInterfaces() const
00038 {
00039   return array<std::pair<String,String> >(); // empty (i.e. we don't have any interfaces by default)
00040 }
00041 
00042   
00043 
00044 Matrix4 Robot::coordFrameTransform(CoordFrame from, CoordFrame to,
00045                                    Int manipulatorIndex,
00046                                    const Matrix4& T,
00047                                    const Point3& platformPosition, 
00048                                    const Orient& platformOrientation) const
00049 {
00050   if ((from == UnknownFrame) || (to == UnknownFrame))
00051     throw std::invalid_argument(Exception("can't convert to or from an unknown coordinate frame"));
00052 
00053   Matrix4 t;
00054 
00055   switch (from) {
00056 
00057   case EndEffectorFrame: {
00058     switch (to) {
00059 
00060     case EndEffectorFrame: {
00061     } break;
00062     
00063     case EndEffectorBaseFrame: {
00064       Unimplemented;
00065     } break;
00066     
00067     case BaseFrame: {
00068       t = T;
00069     } break;
00070     
00071     case MountFrame: {
00072       t = robotDescription->manipulators()[manipulatorIndex]->getBaseTransform() * T;
00073     } break;
00074     
00075     case PlatformFrame: {
00076       Unimplemented;
00077     } break;
00078     
00079     case WorldFrame: {
00080       Matrix4 ptw(platformOrientation.getRotationMatrix3());
00081       ptw.setTranslationComponent(platformPosition);
00082       Matrix4 mtp; mtp.setToTranslation(robotDescription->manipulatorOffsets()[manipulatorIndex]);
00083       Matrix4 etm( robotDescription->manipulators()[manipulatorIndex]->getBaseTransform() * T );
00084       t = ptw * mtp * etm;
00085     } break;
00086     
00087     default:
00088       throw std::invalid_argument(Exception("unknown to CoordFrame"));
00089     }
00090   } break;
00091 
00092 
00093 
00094   case EndEffectorBaseFrame: {
00095     switch (to) {
00096 
00097     case EndEffectorFrame: {
00098       Unimplemented;
00099     } break;
00100     
00101     case EndEffectorBaseFrame: {
00102     } break;
00103     
00104     case BaseFrame: {
00105       Unimplemented;
00106     } break;
00107     
00108     case MountFrame: {
00109       Unimplemented;
00110     } break;
00111     
00112     case PlatformFrame: {
00113       Unimplemented;
00114     } break;
00115     
00116     case WorldFrame: {
00117       Matrix4 ptw(platformOrientation.getRotationMatrix3());
00118       ptw.setTranslationComponent(platformPosition);
00119       Matrix4 mtp; mtp.setToTranslation(robotDescription->manipulatorOffsets()[manipulatorIndex]);
00120       Matrix4 btm( robotDescription->manipulators()[manipulatorIndex]->getBaseTransform() );
00121       Matrix4 eebtb; eebtb.setToTranslation( T.column(4).toVector3() );
00122       t = ptw * mtp * btm * eebtb;
00123     } break;
00124     
00125     default:
00126       throw std::invalid_argument(Exception("unknown to CoordFrame"));
00127     }
00128   } break;
00129 
00130 
00131 
00132   case BaseFrame: {
00133     switch (to) {
00134 
00135     case EndEffectorFrame: { 
00136       t = T;
00137       t.invert();
00138     } break;
00139     
00140     case EndEffectorBaseFrame: {
00141       Unimplemented;
00142     } break;
00143     
00144     case BaseFrame: {
00145     } break;
00146     
00147     case MountFrame: {
00148       t = robotDescription->manipulators()[manipulatorIndex]->getBaseTransform();
00149     } break;
00150     
00151     case PlatformFrame: {
00152       Unimplemented;
00153     } break;
00154     
00155     case WorldFrame: {
00156       Matrix4 btm(robotDescription->manipulators()[manipulatorIndex]->getBaseTransform());
00157       Matrix4 ptw(platformOrientation.getRotationMatrix3());
00158       ptw.setTranslationComponent(platformPosition);
00159       t.setToTranslation(robotDescription->manipulatorOffsets()[manipulatorIndex]);
00160       t = ptw * t * btm;
00161     } break;
00162     
00163     default:
00164       throw std::invalid_argument(Exception("unknown to CoordFrame"));
00165     }
00166   } break;
00167 
00168 
00169 
00170   case MountFrame: {
00171     switch (to) {
00172 
00173     case EndEffectorFrame: {
00174       t = robotDescription->manipulators()[manipulatorIndex]->getBaseTransform() * T;
00175       t.invert();
00176     } break;
00177     
00178     case EndEffectorBaseFrame: {
00179       Unimplemented;
00180     } break;
00181     
00182     case BaseFrame: {
00183       t = robotDescription->manipulators()[manipulatorIndex]->getBaseTransform();
00184       t.invert();
00185     } break;
00186     
00187     case MountFrame: {
00188     } break;
00189     
00190     case PlatformFrame: {
00191       t.setToTranslation(robotDescription->manipulatorOffsets()[manipulatorIndex]);
00192     } break;
00193     
00194     case WorldFrame: {
00195       Matrix4 ptw(platformOrientation.getRotationMatrix3());
00196       ptw.setTranslationComponent(platformPosition);
00197       t.setToTranslation(robotDescription->manipulatorOffsets()[manipulatorIndex]);
00198       t = ptw * t;
00199     } break;
00200     
00201     default:
00202       throw std::invalid_argument(Exception("unknown to CoordFrame"));
00203     }
00204   } break;
00205 
00206 
00207 
00208   case PlatformFrame: {
00209     switch (to) {
00210 
00211     case EndEffectorFrame: {
00212       Unimplemented;
00213     } break;
00214     
00215     case EndEffectorBaseFrame: {
00216       Unimplemented;
00217     } break;
00218     
00219     case BaseFrame: {
00220       Unimplemented;
00221     } break;
00222     
00223     case MountFrame: {
00224       t.setToTranslation(-robotDescription->manipulatorOffsets()[manipulatorIndex]);
00225     } break;
00226     
00227     case PlatformFrame: {
00228     } break;
00229     
00230     case WorldFrame: {
00231       t = Matrix4(platformOrientation.getRotationMatrix3());
00232       t.setTranslationComponent(platformPosition);
00233     } break;
00234     
00235     default:
00236       throw std::invalid_argument(Exception("unknown to CoordFrame"));
00237     }
00238   } break;
00239 
00240 
00241 
00242   case WorldFrame: {
00243     switch (to) {
00244 
00245     case EndEffectorFrame: {
00246       Matrix4 ptw(platformOrientation.getRotationMatrix3());
00247       ptw.setTranslationComponent(platformPosition);
00248       Matrix4 mtp; mtp.setToTranslation(robotDescription->manipulatorOffsets()[manipulatorIndex]);
00249       Matrix4 etm( robotDescription->manipulators()[manipulatorIndex]->getBaseTransform() * T );
00250       t = ptw * mtp * etm;
00251       t.invert();
00252     } break;
00253     
00254     case EndEffectorBaseFrame: {
00255       Matrix4 ptw(platformOrientation.getRotationMatrix3());
00256       ptw.setTranslationComponent(platformPosition);
00257       Matrix4 mtp; mtp.setToTranslation(robotDescription->manipulatorOffsets()[manipulatorIndex]);
00258       Matrix4 btm( robotDescription->manipulators()[manipulatorIndex]->getBaseTransform() );
00259       Matrix4 eebtb; eebtb.setToTranslation( T.column(4).toVector3() );
00260       t = ptw * mtp * btm * eebtb;
00261       t.invert(); 
00262     } break;
00263     
00264     case BaseFrame: {
00265       Matrix4 ptw(platformOrientation.getRotationMatrix3());
00266       ptw.setTranslationComponent(platformPosition);
00267       Matrix4 mtp; mtp.setToTranslation(robotDescription->manipulatorOffsets()[manipulatorIndex]);
00268       Matrix4 btm( robotDescription->manipulators()[manipulatorIndex]->getBaseTransform() );
00269       t = ptw * mtp * btm;
00270       t.invert();      
00271     } break;
00272     
00273     case MountFrame: {
00274       Matrix4 ptw(platformOrientation.getRotationMatrix3());
00275       ptw.setTranslationComponent(platformPosition);
00276       t.setToTranslation(robotDescription->manipulatorOffsets()[manipulatorIndex]);
00277       t = ptw * t;
00278       t.invert();
00279     } break;
00280     
00281     case PlatformFrame: {
00282       t = Matrix4(platformOrientation.getRotationMatrix3());
00283       t.setTranslationComponent(platformPosition);
00284       t.invert();
00285     } break;
00286     
00287     case WorldFrame: {
00288     } break;
00289     
00290     default:
00291       throw std::invalid_argument(Exception("unknown to CoordFrame"));
00292     }
00293   } break;
00294 
00295   default:
00296     throw std::invalid_argument(Exception("unknown from CoordFrame"));
00297   }
00298 
00299   return t;
00300 }
00301 
00302 
00303 
00304 Robot::CoordFrame Robot::coordFrame(const String& frameString)
00305 {
00306   CoordFrame frame = UnknownFrame;
00307 
00308   if (frameString == "world")
00309     frame = Robot::WorldFrame;
00310   else if (frameString == "ee")
00311     frame = Robot::EndEffectorFrame;
00312   else if (frameString == "eebase")
00313     frame = Robot::EndEffectorBaseFrame;
00314   else if (frameString == "base")
00315     frame = Robot::BaseFrame;
00316   else if (frameString == "mount")
00317     frame = Robot::MountFrame;
00318   else if (frameString == "platform")
00319     frame = Robot::PlatformFrame;
00320 
00321   return frame;
00322 }
00323 
00324 
00325 base::String Robot::coordFrame(Robot::CoordFrame coordFrame)
00326 {
00327   switch (coordFrame) {
00328     case WorldFrame: return "world";
00329     case EndEffectorFrame: return "ee";
00330     case EndEffectorBaseFrame: return "eebase";
00331     case BaseFrame: return "base";
00332     case MountFrame: return "mount";
00333     case PlatformFrame: return "platform";
00334     case UnknownFrame: return "unknown";
00335     default: Assertm(false, "unknown coordFrame");
00336   }
00337   return "";
00338 }
00339 

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