BeoSubSim.H

Go to the documentation of this file.
00001 /*!@file BeoSub/BeoSubSim.H */
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/BeoSubSim.H $
00035 // $Id: BeoSubSim.H 6454 2006-04-11 00:47:40Z rjpeters $
00036 //
00037 
00038 #ifndef BEOSUBSIML_H_DEFINED
00039 #define BEOSUBSIM_H_DEFINED
00040 
00041 #include "BeoSub/BeoSub.H"
00042 #include "BeoSub/BeoSubSensor.H"
00043 #include "Devices/BeoChip.H"
00044 #include "Controllers/PID.H"
00045 class HMR3300;
00046 class BeoSubBallast;
00047 class BeoSubIMU;
00048 class FrameIstream;
00049 
00050 
00051 //! Definition and access functions for the BeoSub
00052 /*! BeoSub is an autonomous visually-guided submarine. This class
00053   implements the high-level functionality, relying on low-level
00054   drivers to handle motor activation, compass reading, etc */
00055 class BeoSubSim : public BeoSub
00056 {
00057 public:
00058   // ######################################################################
00059   /*! @name Constructors and Destructors */
00060   //@{
00061 
00062   //! Constructor
00063   BeoSubSim(OptionManager& mgr);
00064 
00065   //! Destructor
00066   ~BeoSubSim();
00067 
00068   //@}
00069 
00070   // ####################################################################
00071   /*! @name mid-level overloads */
00072   //@{
00073   //! Advance the sub by some distance in meters
00074   /*! This is an overload of BeoSub::advanceRel() which ensures we
00075     turn off the heading PID during the advance */
00076   virtual void advanceRel(const float relDist, const bool stop = true);
00077 
00078   //! Strafe the sub by some distance in meters
00079   /*! this is an overload of BeoSub::strafeRel() which ensures we turn
00080     the heading PID off during the strafe */
00081   virtual void strafeRel(const float relDist);
00082 
00083   void turnAbs(const Angle finalHeading, const bool blocking = false);
00084   void turnRel(const Angle relHeading, const bool blocking = false);
00085   void turnOpen(const Angle relHeading, const bool blocking = false);
00086   void diveAbs(const float finalDepth, const bool blocking = false);
00087   void diveRel(const float relDepth, const bool blocking = false);
00088   // ######################################################################
00089   /*! @name Low-level access functions */
00090   //@{
00091 
00092   //! Activate the thrusters
00093   /*! Values should be between -1.0 (full reverse) and 1.0 (full
00094     forward), 0.0 being no motion */
00095   void thrust(const float leftval, const float rightval);
00096 
00097   //! Get the current thruster settings
00098   void getThrusters(float& leftval, float& rightval) const;
00099 
00100   //! Set the front ballast. Value is between 0.0 (empty) and 1.0 (full)
00101   void setFrontBallast(const float val, const bool blocking = false);
00102 
00103   //! Set the rear ballast. Value is between 0.0 (empty) and 1.0 (full)
00104   void setRearBallast(const float val, const bool blocking = false);
00105 
00106   //! Set all ballasts
00107   void setBallasts(const float f, const float r,
00108                    const bool blocking = false);
00109 
00110   //! Get the front ballast. Value is between 0.0 (empty) and 1.0 (full)
00111   float getFrontBallast() const;
00112 
00113   //! Get the rear ballast. Value is between 0.0 (empty) and 1.0 (full)
00114   float getRearBallast() const;
00115 
00116   //! Get all ballasts
00117   void getBallasts(float& f, float& r) const;
00118 
00119   //! Drop a marker
00120   virtual void dropMarker(const bool blocking = false);
00121 
00122   //! Grab a an image from one of the cameras
00123   virtual Image< PixRGB<byte> > grabImage(const enum BeoSubCamera cam) const;
00124 
00125   //@}
00126 
00127   // ##################################################################
00128 
00129   //! Update compass - used by sensors
00130   void updateCompass(const Angle heading, const Angle pitch,
00131                      const Angle roll);
00132 
00133   //! Update depth - used by sensors
00134   void updateDepth(const float depth);
00135 
00136   //! Update position
00137   void updatePosition(const float z, const float x);
00138 
00139   inline float getCurrentZ() { return itsCurrentZ; }
00140   inline float getCurrentX() { return itsCurrentX; }
00141   inline float getRelDist() { return relDistance; }
00142   inline bool isStrafing() { return isStrafe; }
00143   inline void setStrafing(const bool s = false) { isStrafe = s; }
00144   inline void setUpGrabFlag(const bool s = false) { upImageFlag = s; }
00145   inline bool getUpGrabFlag() { return upImageFlag; }
00146   inline void setDownGrabFlag(const bool s = false) { downImageFlag = s; }
00147   inline bool getDownGrabFlag() { return downImageFlag; }
00148   inline void setFrontGrabFlag(const bool s = false) { frontImageFlag = s; }
00149   inline bool getFrontGrabFlag() { return frontImageFlag; }
00150 
00151   //! Turn depth PID on/off
00152   void useDepthPID(const bool useit);
00153 
00154   //! Turn heading PID on/off
00155   void useHeadingPID(const bool useit);
00156 
00157   //! Turn pitch PID on/off
00158   void usePitchPID(const bool useit);
00159 
00160 protected:
00161   NModelParam<int> itsLeftThrusterServoNum;  //!< servo num for left thruster
00162   NModelParam<int> itsRightThrusterServoNum; //!< servo num for right thruster
00163 
00164   nub::soft_ref<HMR3300> itsHMR3300;         //!< compass for heading
00165   nub::soft_ref<BeoChip> itsBeo;             //!< our beochip
00166   nub::soft_ref<BeoSubBallast> itsFballast, itsRballast; //!< our 2 ballasts
00167   nub::soft_ref<BeoSubIMU> itsIMU;           //!< our IMU
00168   nub::soft_ref<FrameIstream> itsCameraFront,
00169     itsCameraDown, itsCameraUp;              //!< our three cameras
00170   float itsThrustLeft, itsThrustRight;       //!< our current thruster settings
00171   float relDistance;
00172   bool isStrafe;
00173   int imageCounter;
00174   float itsCurrentZ, itsCurrentX;
00175   bool upImageFlag, frontImageFlag, downImageFlag;
00176 
00177   BeoSubSensor<float> itsDepthSensor; //!< sensor cleaner for depth
00178   BeoSubSensor<Angle> itsHeadingSensor; //!< sensor cleaner for heading
00179   BeoSubSensor<Angle> itsPitchSensor; //!< sensor cleaner for pitch
00180   PID<float> itsDepthPID;    //!< PID for depth stabilization
00181   PID<Angle> itsHeadingPID;  //!< PID for heading stabilization
00182   PID<Angle> itsPitchPID;    //!< PID for pitch stabilization
00183 
00184   bool itsDepthPIDon, itsHeadingPIDon, itsPitchPIDon;
00185 
00186   void start1(); //!< get started, before our subcomponents start
00187   void start2(); //!< get started, after our subcomponents have started
00188 
00189 
00190 private:
00191   //! Dispatch a BeoChip event
00192   void dispatchBeoChipEvent(const BeoChipEventType t,
00193                             const int valint,
00194                             const float valfloat);
00195 
00196   friend class BeoSubListener;
00197   friend class HMRlistener;
00198 };
00199 
00200 #endif
00201 
00202 // ######################################################################
00203 /* So things look consistent in everyone's emacs... */
00204 /* Local Variables: */
00205 /* indent-tabs-mode: nil */
00206 /* End: */
Generated on Sun May 8 08:40:19 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3