ArmPlanner.H

Go to the documentation of this file.
00001 /*!@file ArmControl/ArmPlanner.H Interface to robot arm */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Chin-Kai Chang<chinkaic@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/ArmControl/ArmPlanner.H $
00035 // $Id: ArmPlanner.H 10794 2009-02-08 06:21:09Z itti $
00036 //
00037 
00038 #ifndef ArmPlanner_H_DEFINED
00039 #define ArmPlanner_H_DEFINED
00040 #include "Component/ModelParam.H"
00041 #include "Component/ModelOptionDef.H"
00042 #include "Component/ModelComponent.H"
00043 #include "ArmControl/CtrlPolicy.H"
00044 #include "ArmControl/ArmSim.H"
00045 #include "ArmControl/RobotArm.H"
00046 #include "ArmControl/ArmController.H"
00047 #include "Util/Types.H"
00048 #include "Util/MathFunctions.H"
00049 #include <deque>
00050 #include <stdarg.h>
00051 #include <unistd.h>
00052 #include <stdio.h>
00053 
00054 //#define USE_LWPR
00055 #ifdef USE_LWPR
00056 #define USE_EXPAT
00057 #include <lwpr/lwpr.h>
00058 #include <lwpr/lwpr_xml.h>
00059 #endif
00060 class ArmPlanner : public ModelComponent
00061 {
00062 public:
00063 
00064 
00065   //Constructor
00066   ArmPlanner(OptionManager& mgr,
00067       const std::string& descrName = "ArmPlanner",
00068       const std::string& tagName = "ArmPlanner",
00069       nub::soft_ref<ArmController> realControler = nub::soft_ref<ArmController>(),
00070       nub::soft_ref<ArmController> controler = nub::soft_ref<ArmController>(),
00071       nub::soft_ref<ArmSim> armSim = nub::soft_ref<ArmSim>()
00072       );
00073 
00074   //Distructor
00075   ~ArmPlanner(){};
00076 
00077   //! Move the arm to desire point with the error closer than errThres
00078   bool move(double *desire,double errThres);//{}
00079   bool moveRel(double x,double y,double z,double errThres);
00080   //! Compute the gradient to get the next movement direction and distance
00081   bool gradient(double *desire,double errThres);//{return false;}
00082   //! Useing the gibbs sampling to approach the desire point
00083   bool gibbsSampling(double *desire,double errThres);//{return false;}
00084   //! Useing the line segment approaching between desire and arm
00085   bool gibbsControl(double *desire,double d);//{return false;}
00086   //! Move ArmSim motor
00087   void moveMotor(int motor,int move);
00088 #ifdef USE_LWPR
00089   //! Traing the arm to learn how to approach the desire point
00090   void trainArm(LWPR_Model& ik_model, const double* armPos, const ArmController::JointPos& jointPos);
00091   //! Using current learning data to get IK
00092   ArmController::JointPos getIK(LWPR_Model& ik_model, const double* desiredPos);
00093 #endif
00094   ArmController::JointPos getIK2(const double* desiredPos);
00095   void getFK(double *endPos);
00096   //!
00097   //!
00098   ArmController::JointPos calcGradient(const double* desiredPos);
00099 
00100   void minJerk(double *desire,double *nextPoint,double time);
00101   void updateDataImg();
00102   const Image<PixRGB<byte> >* getImagePtr() { return &itsImage; }
00103   ArmController::JointPos sim2real(ArmController::JointPos armSimJointPos );
00104   //###########################################################
00105 private:
00106 #ifdef USE_LWPR
00107   LWPR_Model ik_model;
00108 #endif
00109   int numWarnings ;
00110   nub::soft_ref<ArmController> itsRealArmController;
00111   nub::soft_ref<ArmController> itsArmController;
00112   nub::soft_ref<ArmSim> itsArmSim;
00113   Image<PixRGB<byte> > itsImage;
00114 
00115   double getDistance(const double* pos, const double* desire)
00116   {
00117     double sum = 0;
00118     for(int i = 0; i < 3; i++)
00119             sum+= (pos[i]-desire[i])*(pos[i]-desire[i]);
00120     return sqrt(sum);
00121   }
00122   double getDistance2D(const double* pos, const double* desire)
00123   {
00124     double sum = 0;
00125     for(int i = 0; i < 2; i++)
00126             sum+= (pos[i]-desire[i])*(pos[i]-desire[i]);
00127     return sqrt(sum);
00128   }
00129   double sq(const double x)
00130   {
00131     return x*x;
00132   }
00133 
00134 };
00135 
00136 #endif
00137 
00138 // ######################################################################
00139 /* So things look consistent in everyone's emacs... */
00140 /* Local Variables: */
00141 /* indent-tabs-mode: nil */
00142 /* End: */
Generated on Sun May 8 08:40:11 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3