BeoSubOneBal.H

Go to the documentation of this file.
00001 /*!@file BeoSub/BeoSubOneBal.H An autonomous submarine with one ballast */
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/BeoSubOneBal.H $
00035 // $Id: BeoSubOneBal.H 6454 2006-04-11 00:47:40Z rjpeters $
00036 //
00037 
00038 #ifndef BEOSUBONEBAL_H_DEFINED
00039 #define BEOSUBONEBAL_H_DEFINED
00040 
00041 #include "BeoSub/BeoSub.H"
00042 #include "BeoSub/BeoSubSensor.H"
00043 #include "Devices/BeoChip.H"
00044 #include "Controllers/PID.H"
00045 #include "BeoSub/Stepper.H"
00046 #include "Devices/ParPort.H"
00047 class HMR3300;
00048 class BeoSubBallast;
00049 class BeoSubIMU;
00050 class IEEE1394grabber;
00051 
00052 
00053 //! Definition and access functions for the BeoSub
00054 /*! BeoSub is an autonomous visually-guided submarine. This class
00055   impoements the highl-evel functionality, relying on low-level
00056   drivers to handle motor activation, compass reading, etc */
00057 class BeoSubOneBal : public BeoSub
00058 {
00059 public:
00060   // ######################################################################
00061   /*! @name Constructors and Destructors */
00062   //@{
00063 
00064   //! Constructor
00065   BeoSubOneBal(OptionManager& mgr);
00066 
00067   //! Destructor
00068   ~BeoSubOneBal();
00069 
00070   //@}
00071 
00072   // ######################################################################
00073   /*! @name mid-level overloads */
00074   //@{
00075 
00076   //! Advance the sub by some distance in meters
00077   /*! This is an overload of BeoSub::advanceRel() which ensures we
00078     turn off the heading PID during the advance */
00079   virtual void advanceRel(const float relDist, const bool stop = true);
00080 
00081   //! Strafes the sub by some distance in meters
00082   /*! This is an overload of BeoSub::strafeRel() which ensures we turn
00083     the heading PID off during the strafe */
00084   virtual void strafeRel(const float relDist);
00085 
00086   virtual void turnOpen(const Angle openHeading, const bool stop = true);
00087 
00088   //@}
00089 
00090   // ######################################################################
00091   /*! @name Low-level access functions */
00092   //@{
00093 
00094   //! Activate the thrusters
00095   /*! Values should be between -1.0 (full reverse) and 1.0 (full
00096     forward), 0.0 being no motion */
00097   void thrust(const float leftval, const float rightval);
00098 
00099   //! Get the current thruster settings
00100   void getThrusters(float& leftval, float& rightval) const;
00101 
00102   //! Set the front ballast. Value is between 0.0 (empty) and 1.0 (full)
00103   void setFrontBallast(const float val, const bool blocking = false);
00104 
00105   //! Set the rear ballast. Value is between 0.0 (empty) and 1.0 (full)
00106   void setRearBallast(const float val, const bool blocking = false);
00107 
00108   //! Set all ballasts
00109   void setBallasts(const float f, const float r,
00110                    const bool blocking = false);
00111 
00112   //! Get the front ballast. Value is between 0.0 (empty) and 1.0 (full)
00113   float getFrontBallast() const;
00114 
00115   //! Get the rear ballast. Value is between 0.0 (empty) and 1.0 (full)
00116   float getRearBallast() const;
00117 
00118   //! Get all ballasts
00119   void getBallasts(float& f, float& r) const;
00120 
00121   //! Drop a marker
00122   virtual void dropMarker(const bool blocking = false);
00123 
00124   //! Grab a an image from one of the cameras
00125   virtual Image< PixRGB<byte> > grabImage(const enum BeoSubCamera cam) const;
00126 
00127   //@}
00128 
00129   // **********************************************************************
00130   /*! closed-loop control */
00131 private:
00132   void updateThrusters();
00133   void updateRotVelPID(const Angle current);
00134   Angle PIDRotVel;
00135   float RotVelCommand;
00136   float PIDTransVel, TransVelCommand;
00137 public:
00138   void setRotVel(const Angle desired);
00139   void setTransVel(const float desired);
00140 
00141   // ######################################################################
00142   /*! @name PID control */
00143   //@{
00144 
00145   //! Turn depth PID on/off
00146   void useDepthPID(const bool useit);
00147 
00148   //! set depth PID pgain
00149   void setDepthPgain(float p);
00150 
00151   //! set depth PID igain
00152   void setDepthIgain(float i);
00153 
00154   //! set depth PID dgain
00155   void setDepthDgain(float d);
00156 
00157   //! Turn heading PID on/off
00158   void useHeadingPID(const bool useit);
00159 
00160   //! set heading PID pgain
00161   void setHeadingPgain(float p);
00162 
00163   //! set heading PID igain
00164   void setHeadingIgain(float i);
00165 
00166   //! set heading PID dgain
00167   void setHeadingDgain(float d);
00168 
00169   //! Turn pitch PID on/off
00170   void usePitchPID(const bool useit);
00171 
00172   //! set pitch PID pgain
00173   void setPitchPgain(float p);
00174 
00175   //! set pitch PID igain
00176   void setPitchIgain(float i);
00177 
00178   //! set pitch PID dgain
00179   void setPitchDgain(float d);
00180 
00181   //! Turn pitch PID on/off
00182   void useRotVelPID(const bool useit);
00183 
00184   //! set pitch PID pgain
00185   void setRotVelPgain(float p);
00186 
00187   //! set pitch PID igain
00188   void setRotVelIgain(float i);
00189 
00190   //! set pitch PID dgain
00191   void setRotVelDgain(float d);
00192 
00193 
00194   //@}
00195 
00196   // ######################################################################
00197   /*! @name Miscellaneous */
00198   //@{
00199 
00200   //! Use or ignore the kill switch
00201   void useKillSwitch(const bool useit);
00202   /* TODO: two different kill switch code! connected to different hardware, though */
00203   bool isKilled();
00204 
00205   //! Kill Switch Function
00206   /*! This is called when the kill switch is activated */
00207   void killSwitch();
00208 
00209   //@}
00210 
00211   // ######################################################################
00212   /*! @name For internal use by our listeners only -- do not call */
00213   //@{
00214 
00215   //! Update compass - used by sensors
00216   void updateCompass(const Angle heading, const Angle pitch,
00217                      const Angle roll);
00218 
00219   //! Update depth - used by sensors
00220   void updateDepth(const float depth);
00221 
00222   void updateIMU(const float xa, const float ya, const float za,
00223                   const Angle xv, const Angle yv, const Angle zv);
00224   //@}
00225   nub::soft_ref<BeoSubIMU> itsIMU;           //!< our IMU
00226 
00227 protected:
00228   NModelParam<int> itsLeftThrusterServoNum;  //!< servo num for left thruster
00229   NModelParam<int> itsRightThrusterServoNum; //!< servo num for right thruster
00230 
00231   nub::soft_ref<HMR3300> itsHMR3300;         //!< compass for heading
00232   nub::soft_ref<BeoChip> itsBeo;             //!< our beochip
00233   nub::soft_ref<BeoSubBallast> itsFballast, itsRballast; //!< our 2 ballasts
00234  // nub::soft_ref<BeoSubIMU> itsIMU;           //!< our IMU
00235   nub::soft_ref<FrameIstream> itsCameraFront,
00236     itsCameraDown, itsCameraUp;              //!< our three cameras
00237   float itsThrustLeft, itsThrustRight;       //!< our current thruster settings
00238 
00239   BeoSubSensor<float> itsDepthSensor; //!< sensor cleaner for depth
00240   BeoSubSensor<Angle> itsHeadingSensor; //!< sensor cleaner for heading
00241   BeoSubSensor<Angle> itsPitchSensor; //!< sensor cleaner for pitch
00242   PID<float> itsDepthPID;    //!< PID for depth stabilization
00243   PID<Angle> itsHeadingPID;  //!< PID for heading stabilization
00244   PID<Angle> itsPitchPID;    //!< PID for pitch stabilization
00245   PID<Angle> itsRotVelPID;    //!< PID for rotational velocity stabilization
00246 
00247   bool itsDepthPIDon, itsHeadingPIDon, itsPitchPIDon, itsRotVelPIDon;
00248   bool itsKillSwitchUsed;
00249 
00250   float itsDiveSetting, itsPitchSetting;
00251   double itsLastHeadingTime, itsLastPitchTime, itsLastDepthTime;
00252 
00253   virtual void start1(); //!< get started, before our subcomponents start
00254   virtual void start2(); //!< get started, after our subcomponents have started
00255   virtual void stop1();
00256 
00257   /* TODO: put these stuff in proper place - khooyp*/
00258 #ifdef HAVE_LINUX_PARPORT_H
00259   nub::soft_ref<ParPort> lp0;
00260   Stepper markerdropper;
00261 #endif
00262   int killSwitchDebounceCounter;
00263 
00264 private:
00265   //! Dispatch a BeoChip event
00266   void dispatchBeoChipEvent(const BeoChipEventType t,
00267                             const int valint,
00268                             const float valfloat);
00269 
00270   friend class BeoSubListener;
00271   friend class HMRlistener;
00272 };
00273 
00274 #endif
00275 
00276 // ######################################################################
00277 /* So things look consistent in everyone's emacs... */
00278 /* Local Variables: */
00279 /* indent-tabs-mode: nil */
00280 /* End: */
Generated on Sun May 8 08:40:19 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3