BeoSubAction.H

Go to the documentation of this file.
00001 /*!@file BeoSub/BeoSubAction.H Helper class for BeoSub motor actions */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003   //
00005 // by the 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: Laurent Itti <itti@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/BeoSub/BeoSubAction.H $
00035 // $Id: BeoSubAction.H 4663 2005-06-23 17:47:28Z rjpeters $
00036 //
00037 
00038 #ifndef BEOSUBACTION_H_DEFINED
00039 #define BEOSUBACTION_H_DEFINED
00040 
00041 class BeoSub;
00042 
00043 // ######################################################################
00044 //! Helper base class for BeoSub motor actions
00045 /*! The base class defines an interface that will then be used in
00046   various derived forms in order to perfom a variety of actions */
00047 class BeoSubAction
00048 {
00049 public:
00050   //! Constructor
00051   BeoSubAction(BeoSub *bs, const bool pulseWidthControl = false);
00052 
00053   //! Destructor
00054   virtual ~BeoSubAction();
00055 
00056   //! Execute the action
00057   /*! This will attempt to reach the target reading by iteratively
00058     outputing motor commands and monitoring the instruments. If stabil
00059     is true, we will attempt to maintain the sub stable while
00060     executing the action. Returns true on success. */
00061   virtual bool execute(const float target, const bool stabil, const int itsMaxIter = 100);
00062 
00063   virtual bool pulseWidthExecute(const float target, const bool stabil, const int itsMaxIter = 100);
00064 
00065 
00066 protected:
00067   //! Activate the action for one step
00068   /*! @param incr if true, the one step of activation should tend to
00069     increase the value returned by getPosition(), otherwise it should
00070     tend to decrease it
00071     @return true on success */
00072   virtual bool activate(const bool incr) = 0;
00073 
00074   //turn on the motor for corresponding action
00075   virtual bool turnOnMotor(const bool incr) = 0;
00076 
00077   //turn off the motor for corresponding action
00078   virtual bool turnOffMotor(const bool incr) = 0;
00079 
00080   //! Get a reading of the current position
00081   virtual float getPosition() const = 0;
00082 
00083   //! Stabilize whatever is not being modified by the action
00084   virtual bool stabilize(const bool pulseWidthControl = false) = 0;
00085 
00086   //! Calculate current and target value differences
00087   virtual float difference(float pos, float target) = 0;
00088 
00089   BeoSub *itsBeoSub; //! our BeoSub, which holds our actuators & instruments
00090   float itsDeadBand; //! deadband
00091   bool pulseWidthControl; //! true when using pulse width control, number of pusle control when false
00092 
00093   float itsGainP;    //! Gain for Propositional Control
00094   float itsGainD;    //! Gain for Derivative Control
00095   float itsGainI;    //! Gain for Integral Control
00096 
00097   int turnOnTime; //! Number of time steps (iterations) for the motor to turn on when going pule interval control
00098 
00099   float itsErrorHistory[20]; //! storing pass 20 iterations value
00100   int itsErrIndex; //! index top iterate the history
00101   float u; //! motor command in number of pulses
00102 };
00103 
00104 // ######################################################################
00105 //! Helper base class for BeoSub dive actions
00106 class BeoSubActionDive : public BeoSubAction
00107 {
00108 public:
00109   //! Constructor
00110   BeoSubActionDive(BeoSub *bs, bool pulseWidthControl = false);
00111 
00112   //! Destructor
00113   virtual ~BeoSubActionDive();
00114 
00115 
00116 protected:
00117   //! Dive for one step (go deeper if incr=true)
00118   virtual bool activate(const bool incr);
00119 
00120   //turn on the motor for corresponding action
00121   virtual bool turnOnMotor(const bool incr);
00122 
00123   //turn off the motor for corresponding action
00124   virtual bool turnOffMotor(const bool incr);
00125 
00126   //! Get a reading of the current depth
00127   virtual float getPosition() const;
00128 
00129   //! Stabilize the heading
00130   virtual bool stabilize(const bool pulseWidthControl = false);
00131 
00132   //! Calculate current and target value differences
00133   virtual float difference(float pos, float target);
00134 
00135 
00136 private:
00137   float itsHeading;  // ref heading (yaw only) in case we want to stabilize it
00138 };
00139 
00140 // ######################################################################
00141 //! Helper base class for BeoSub turn actions
00142 class BeoSubActionTurn : public BeoSubAction
00143 {
00144 public:
00145   //! Constructor
00146   BeoSubActionTurn(BeoSub *bs, bool pulseWidthControl = false);
00147 
00148   //! Destructor
00149   virtual ~BeoSubActionTurn();
00150 
00151 protected:
00152   //! Turn for one step (turn right if incr=true)
00153   virtual bool activate(const bool incr);
00154 
00155   //turn on the motor for corresponding action
00156   virtual bool turnOnMotor(const bool incr);
00157 
00158   //turn off the motor for corresponding action
00159   virtual bool turnOffMotor(const bool incr);
00160 
00161 
00162   //! Get a reading of the current heading
00163   virtual float getPosition() const;
00164 
00165   //! Stabilize the depth
00166   virtual bool stabilize(const bool pulseWidthControl = false);
00167 
00168   //! Calculate current and target value differences
00169   //! Returning shortest turning angle with clockwise direction (positive)
00170   virtual float difference(float pos, float target);
00171 
00172 private:
00173   float itsDepth;    // our reference depth in case we want to stabilize it
00174 };
00175 
00176 #endif
00177 
00178 // ######################################################################
00179 /* So things look consistent in everyone's emacs... */
00180 /* Local Variables: */
00181 /* indent-tabs-mode: nil */
00182 /* End: */
Generated on Sun May 8 08:40:19 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3