Basic Image AlgorithmS Library 2.8.0

ViscaControl.hh

00001 /*
00002 This file is part of the BIAS library (Basic ImageAlgorithmS).
00003 
00004 Copyright (C) 2003-2009    (see file CONTACT for details)
00005   Multimediale Systeme der Informationsverarbeitung
00006   Institut fuer Informatik
00007   Christian-Albrechts-Universitaet Kiel
00008 
00009 
00010 BIAS is free software; you can redistribute it and/or modify
00011 it under the terms of the GNU Lesser General Public License as published by
00012 the Free Software Foundation; either version 2.1 of the License, or
00013 (at your option) any later version.
00014 
00015 BIAS is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU Lesser General Public License for more details.
00019 
00020 You should have received a copy of the GNU Lesser General Public License
00021 along with BIAS; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023 */
00024 
00025 #ifndef __ViscaControl_hh__
00026 #define __ViscaControl_hh__
00027 
00028 #include <bias_config.h>
00029 #ifdef BIAS_HAVE_PTHREADS
00030     #include <pthread.h>
00031 #endif
00032 #include <string>
00033 #ifdef WIN32
00034 #include <windows.h>
00035 #include <Base/Common/W32Compat.hh>
00036 #endif
00037 // BIAS
00038 #include <Utils/SerialPortIO.hh>
00039 #include <Base/Debug/Debug.hh>
00040 #include <Base/Debug/Error.hh>
00041 
00042 namespace BIAS {
00043 
00044 /**
00045  * \class ViscaControl
00046  * \brief for use with Sony PanTilt Cameras, also compatible with
00047  *  WISKA PanTilt Cameras. This is used to control a camera settings.
00048  *  It uses the class SerialPortIO to send commands and receive answers.
00049  *  Also included are some functions of the Camera (MoveUp...), they can
00050  *  be extended as needed (for a full list of functions see the reference
00051  *  manuals for the parts).
00052  *  The commands always start with 8X where X is the camera number, so 1 is the first camera!!
00053  *  and X \element of {1,...,7}. A broadcast is done with 88.
00054  *  Replies start with 9X and 0!! (unequal to request command!)
00055  * \author  ischiller, fnommensen, mfranke
00056  */
00057 class BIASPanTilt_EXPORT ViscaControl: public BIAS::Debug
00058 {
00059 
00060 public:
00061     enum VISCA_CONSTANT{
00062         VISCA_ERROR=-1,
00063         VISCA_INTERLACED=0,
00064         VISCA_PROGRESSIVE
00065     };
00066 
00067   ViscaControl();
00068   ~ViscaControl();
00069 
00070   bool InitPanTiltUnit(std::string port); //PowerOn+Cam calibration etc
00071 
00072   // Moves the PanTilt unit in various directions
00073   // until MoveStop() is called. Use with caution!
00074   void MoveUp();
00075   void MoveUpLeft();
00076   void MoveUpRight();
00077   void MoveDown();
00078   void MoveDownLeft();
00079   void MoveDownRight();
00080   void MoveLeft();
00081   void MoveRight();
00082   void MoveStop();
00083   
00084   void LightOn();
00085   void LightOff();
00086 
00087   void Wash();
00088   void Wipe();
00089 
00090   void ZoomTele();
00091   void ZoomWide();
00092   void ZoomStop();
00093 
00094   void MoveRelative(short relPan, short relTilt);
00095   void MoveAbsolute(short panPos, short tiltPos);
00096   void MovePhysical(short panSteps, short tiltSteps);
00097 
00098   void CamPower(bool mode);
00099   bool ClosePanTiltUnit();
00100   void PanTiltPosInq();
00101   void MoveHome();
00102 
00103     // Change pan and tilt speed for units with speed support.
00104     // WARNING: Sending other values than the defaults to units
00105     // without speed support will result in an engine lock!
00106     void SetPanSpeed(unsigned char panSpeed) {
00107         panSpeed_ = panSpeed;
00108     }
00109     void SetTiltSpeed(unsigned char tiltSpeed) {
00110         tiltSpeed_ = tiltSpeed;
00111     }
00112 
00113     // Change active unit (default: 0x81)
00114     void SetActiveUnit(unsigned char activeUnit) {
00115         activeUnit_ = activeUnit;
00116     }
00117 
00118   /** Answers start with X0, where X is the camera number +8, e.g. 90 is camera 1 */
00119   void ManageAnswer();
00120 
00121   void AdressSet();
00122   void WaitForAck();
00123   void ResetPanTilt();
00124   void ResetCamCustom();
00125   void ZoomInq();
00126   void ZoomDirect(short zoom);
00127 
00128   bool IsConnected(){return connected_;}
00129   bool SetCCDScanningMode(VISCA_CONSTANT mode);
00130 
00131   ViscaControl::VISCA_CONSTANT GetCCDScanningMode();
00132   int GetMaxZoom(){return maxZoom_;}
00133   int GetPan(){return pan_;}
00134   int GetTilt(){return tilt_;}
00135   int GetZoom(){return zoom_;}
00136   void ContinuousRead();
00137 
00138   // values for pan, tilt and zoom
00139   short int pan_,tilt_,zoom_;
00140   // have the values been used yet?
00141   bool used_;
00142 
00143 protected:
00144   /** adresses of cameras start with 1, eg, 0x81 is first cam
00145       the reply starts with 0 on 90, e.g. 0.90 is first cam */
00146   int SendCommand_(unsigned char* buf,int length,
00147                                      bool manageAnswer=true);
00148   int CamInitialize_();
00149 
00150 protected:
00151 #ifdef BIAS_HAVE_PTHREADS
00152   pthread_mutex_t camMutex; 
00153 #endif
00154   bool zoomed_;
00155   bool connected_;
00156   int maxZoom_;
00157   unsigned char sendBuffer[16];
00158   unsigned char* sendPtr;
00159 
00160     unsigned char panSpeed_;
00161     unsigned char tiltSpeed_;
00162     unsigned char activeUnit_;
00163 
00164     BIAS::SerialPortIO serialIO_;
00165 };
00166 
00167 }//end namespace
00168 #endif
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends