VCC4.H

Go to the documentation of this file.
00001 /*!@file Devices/VCC4.H  Interface with pan-tilt mechanism of a Canon VC-C4 camera */
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: Dirk Walther <walther@caltech.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Devices/VCC4.H $
00035 // $Id: VCC4.H 6522 2006-04-25 16:41:24Z rjpeters $
00036 //
00037 
00038 #ifndef __VCC4_H__
00039 #define __VCC4_H__
00040 
00041 #include "Devices/Serial.H"
00042 #include "Devices/VCC4cmddef.H"
00043 
00044 #define VCC4_EMBED_NONE 0
00045 #define VCC4_EMBED_NUM  1
00046 #define VCC4_EMBED_ANG  2
00047 #define VCC4_EMBED_STR  3
00048 
00049 
00050 #define VCC4_SUCCESS          0 //!operation successful
00051 
00052 // errors:
00053 #define VCC4_OPEN_ERR         1 //!error while opening the serial device
00054 #define VCC4_INVALID_COMMAND  2 //!invalid command error
00055 #define VCC4_INVALID_PARAM    3 //!invalid parameters error
00056 #define VCC4_IO_ERR           4 //!input / output error
00057 #define VCC4_REPLY_ERR        5 //!some problem with the reply string
00058 #define VCC4_NO_REPLY         6 //!the camera did not send a reply
00059 #define VCC4_INVALID_NUMBER   7 //!an invalid absolute number parameter
00060 #define VCC4_INVALID_ANGLE    8 //!an invalid angle argument
00061 #define VCC4_ERR_MASK      0x1F
00062 
00063 //error flags returned by the camera
00064 #define VCC4_SYSTEM_ERR   (1<<8)
00065 #define VCC4_BUSY_ERR     (1<<12)
00066 #define VCC4_COMMAND_ERR  (1<<13)
00067 #define VCC4_PARAM_ERR    (1<<14)
00068 #define VCC4_MODE_ERR     (1<<15)
00069 #define VCC4_CAMERA_ERRS  (VCC4_SYSTEM_ERR|VCC4_BUSY_ERR|VCC4_COMMAND_ERR|\
00070                            VCC4_PARAM_ERR|VCC4_MODE_ERR)
00071 
00072 #define VCC4_NUM_OVERFLOW    -1
00073 #define VCC4_BUF_UNDERFLOW   -2
00074 
00075 //!interface with the pan-tilt mechanism of a Canon VC-C4 camera
00076 class VCC4 : public ModelComponent
00077 {
00078 public:
00079   //! constructor. See ModelComponent.H.
00080   VCC4(OptionManager& mgr,
00081        const std::string& descrName = "VCC4 Pan/Tilt Camera Driver",
00082        const std::string& tagName = "VCC4driver");
00083 
00084   //! destructor - closes serial connection
00085   ~VCC4(void);
00086 
00087   //! go to the specified position
00088   /*!@param pan panning angle (in degrees)
00089     @param tilt tilting angle (in degrees)
00090     @param wait wait for the command to successfully complete if true
00091     @return 0 if successful, some error code otherwise*/
00092   int gotoPosition(float pan, float tilt, bool wait = true);
00093 
00094   //! retrieve the current position
00095   /*!@param pan panning angle (in degrees)
00096     @param tilt tilting angle (in degrees)
00097     @param wait wait for the command to successfully complete if true
00098     @return 0 if successful, some error code otherwise*/
00099   int getPosition (float& pan, float& tilt, bool wait = true);
00100 
00101   //! is the pedestal moving?
00102   inline bool IsMoving (void);
00103 
00104   //! send a command that does not need parameters
00105   /*!@param cmdno for command numbers see VCC4cmddef.H
00106     @param wait wait for successful completion if true
00107     @return 0 if successful, some error code otherwise*/
00108   int PlainCommand (int cmdno, bool wait = true);
00109 
00110   //! send a command that needs an integer number as a parameter
00111   /*!@param cmdno for command numbers see VCC4cmddef.H
00112     @param value the integer value to set
00113     @param wait wait for successful completion if true
00114     @return 0 if successful, some error code otherwise*/
00115   int AbsNumCommand (int cmdno, unsigned int value, bool wait = true);
00116 
00117   //! send a command that needs two angles as parameters
00118   /*!@param cmdno for command numbers see VCC4cmddef.H
00119     @param angle1
00120     @param angle2 the angles (in degrees) to set
00121     @param wait wait for successful completion if true
00122     @return 0 if successful, some error code otherwise*/
00123   int AngleCommand (int cmdno, float angle1, float angle2, bool wait = true);
00124 
00125   //! send a command that needs a string as a parameter
00126   /*!@param cmdno for command numbers see VCC4cmddef.H
00127     @param string the string value to set
00128     @param wait wait for successful completion if true
00129     @return 0 if successful, some error code otherwise*/
00130   int StringCommand (int cmdno, char* string, bool wait = true);
00131 
00132   //! retrieve an absolute number from the ReplyString
00133   /*!@param the length of the string representing the number
00134     @return the integer value extracted from the ReplyString */
00135   inline int getAbsNum (unsigned int length);
00136 
00137   //! retrieve one angle from the ReplyString
00138   /*!@param angle reference to write the extracted angle to
00139     @return 0 if successful, some error code otherwise*/
00140   int getOneAngle (float& angle);
00141 
00142   //! retrieve two angle values from ReplyString
00143   /*!@param angle1
00144     @param angle2 references to write the extracted angles to (in degrees)
00145     @return 0 if successful, some error code otherwise*/
00146   int getTwoAngles (float& angle1, float& angle2);
00147 
00148   //! initialize camera
00149   /*! after successful completion, ReplyString contains the name
00150     of the device.
00151     @param goHome put camera into Home position if true
00152     @return 0 if successful, some error code otherwise*/
00153   int CameraInitialize (bool goHome = false);
00154 
00155   //! set the unit number
00156   inline int setUnitNo (int unum);
00157 
00158   //! get the unit number
00159   inline int getUnitNo (void);
00160 
00161   //! returns the pulse ratio for the pan and tilt mechanism
00162   inline float getPulseRatio(void);
00163 
00164   //! reply string from last command (i.e. status reports and other replies)
00165   char ReplyString[30];
00166 
00167 protected:
00168   nub::soft_ref<Serial> itsPort;          //!< our serial port
00169   OModelParam<std::string> itsSerialDevice; //!< our serial device
00170   OModelParam<int> itsUnitNo;          //!< our unit number
00171   OModelParam<float> itsPulseRatio;    //!< our pulse ratio
00172   OModelParam<float> itsMaxAngle;      //!< our max angle
00173 
00174   //! send a command with parameters to the device
00175   int SendRawCommand (int cmdno, char* param = NULL);
00176 
00177   //! send command and keep trying if busy
00178   int WaitRawCommand (int cmdno, char* param = NULL);
00179 
00180   //! return the index for a command number
00181   int getIndex (int cmdno);
00182 
00183   //! attempt to retrieve a reply
00184   int getReply (void);
00185 
00186   //! transforms an unsigned int to a string of hex digits
00187   int intToHexString (unsigned int value, char* buf, unsigned int length);
00188 
00189   //! transforms a string of hex digits into an int
00190   int hexStringToInt (char* buf, unsigned int length);
00191 
00192   //! get started (see ModelComponent.H). The serial port gets configured.
00193   void start1();
00194 
00195   //! get stopped (see ModelComponent.H). We return the unit to home position
00196   void stop1();
00197 
00198 private:
00199   static VCC4CMD command[VCC4_CMDMAX];          // array with command codes
00200   char paramString[30];
00201 };
00202 
00203 // ######################################################################
00204 // ########  inlined methods
00205 // ######################################################################
00206 
00207 // ######################################################################
00208 inline int VCC4::setUnitNo (int unum)
00209 {
00210   if ((unum < 0) || (unum > 9)) itsUnitNo.setVal(0);
00211   else itsUnitNo.setVal(unum);
00212   return unum;
00213 }
00214 
00215 // ######################################################################
00216 inline int VCC4::getUnitNo (void)
00217 {
00218   return itsUnitNo.getVal();
00219 }
00220 
00221 // ######################################################################
00222 inline bool VCC4::IsMoving (void)
00223 {
00224   int err = PlainCommand (VCC4_GetPTAngle2, false);
00225   return ((err & VCC4_BUSY_ERR) != 0);
00226 }
00227 
00228 // ######################################################################
00229 inline int VCC4::getAbsNum (unsigned int length)
00230 {
00231   return hexStringToInt(&(ReplyString[0]), length);
00232 }
00233 
00234 // ######################################################################
00235 inline float VCC4::getPulseRatio(void)
00236 {
00237   return itsPulseRatio.getVal();
00238 }
00239 
00240 
00241 #endif
00242 
00243 
00244 
00245 // ######################################################################
00246 /* So things look consistent in everyone's emacs... */
00247 /* Local Variables: */
00248 /* indent-tabs-mode: nil */
00249 /* End: */
Generated on Sun May 8 08:40:38 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3