Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ViscaControl.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef __ViscaControl_hh__
26 #define __ViscaControl_hh__
27 
28 #include <bias_config.h>
29 #ifdef BIAS_HAVE_PTHREADS
30  #include <pthread.h>
31 #endif
32 #include <string>
33 #ifdef WIN32
34 #include <windows.h>
35 #include <Base/Common/W32Compat.hh>
36 #endif
37 // BIAS
38 #include <Utils/SerialPortIO.hh>
39 #include <Base/Debug/Debug.hh>
40 #include <Base/Debug/Error.hh>
41 
42 namespace BIAS {
43 
44 /**
45  * \class ViscaControl
46  * \brief for use with Sony PanTilt Cameras, also compatible with
47  * WISKA PanTilt Cameras. This is used to control a camera settings.
48  * It uses the class SerialPortIO to send commands and receive answers.
49  * Also included are some functions of the Camera (MoveUp...), they can
50  * be extended as needed (for a full list of functions see the reference
51  * manuals for the parts).
52  * The commands always start with 8X where X is the camera number, so 1 is the first camera!!
53  * and X \element of {1,...,7}. A broadcast is done with 88.
54  * Replies start with 9X and 0!! (unequal to request command!)
55  * \author ischiller, fnommensen, mfranke
56  */
57 class BIASPanTilt_EXPORT ViscaControl: public BIAS::Debug
58 {
59 
60 public:
62  VISCA_ERROR=-1,
63  VISCA_INTERLACED=0,
64  VISCA_PROGRESSIVE
65  };
66 
67  ViscaControl();
68  ~ViscaControl();
69 
70  bool InitPanTiltUnit(std::string port); //PowerOn+Cam calibration etc
71 
72  // Moves the PanTilt unit in various directions
73  // until MoveStop() is called. Use with caution!
74  void MoveUp();
75  void MoveUpLeft();
76  void MoveUpRight();
77  void MoveDown();
78  void MoveDownLeft();
79  void MoveDownRight();
80  void MoveLeft();
81  void MoveRight();
82  void MoveStop();
83 
84  void LightOn();
85  void LightOff();
86 
87  void Wash();
88  void Wipe();
89 
90  void ZoomTele();
91  void ZoomWide();
92  void ZoomStop();
93 
94  void MoveRelative(short relPan, short relTilt);
95  void MoveAbsolute(short panPos, short tiltPos);
96  void MovePhysical(short panSteps, short tiltSteps);
97 
98  void CamPower(bool mode);
99  bool ClosePanTiltUnit();
100  void PanTiltPosInq();
101  void MoveHome();
102 
103  // Change pan and tilt speed for units with speed support.
104  // WARNING: Sending other values than the defaults to units
105  // without speed support will result in an engine lock!
106  void SetPanSpeed(unsigned char panSpeed) {
107  panSpeed_ = panSpeed;
108  }
109  void SetTiltSpeed(unsigned char tiltSpeed) {
110  tiltSpeed_ = tiltSpeed;
111  }
112 
113  // Change active unit (default: 0x81)
114  void SetActiveUnit(unsigned char activeUnit) {
115  activeUnit_ = activeUnit;
116  }
117 
118  /** Answers start with X0, where X is the camera number +8, e.g. 90 is camera 1 */
119  void ManageAnswer();
120 
121  void AdressSet();
122  void WaitForAck();
123  void ResetPanTilt();
124  void ResetCamCustom();
125  void ZoomInq();
126  void ZoomDirect(short zoom);
127 
128  bool IsConnected(){return connected_;}
129  bool SetCCDScanningMode(VISCA_CONSTANT mode);
130 
131  ViscaControl::VISCA_CONSTANT GetCCDScanningMode();
132  int GetMaxZoom(){return maxZoom_;}
133  int GetPan(){return pan_;}
134  int GetTilt(){return tilt_;}
135  int GetZoom(){return zoom_;}
136  void ContinuousRead();
137 
138  // values for pan, tilt and zoom
139  short int pan_,tilt_,zoom_;
140  // have the values been used yet?
141  bool used_;
142 
143 protected:
144  /** adresses of cameras start with 1, eg, 0x81 is first cam
145  the reply starts with 0 on 90, e.g. 0.90 is first cam */
146  int SendCommand_(unsigned char* buf,int length,
147  bool manageAnswer=true);
148  int CamInitialize_();
149 
150 protected:
151 #ifdef BIAS_HAVE_PTHREADS
152  pthread_mutex_t camMutex;
153 #endif
154  bool zoomed_;
156  int maxZoom_;
157  unsigned char sendBuffer[16];
158  unsigned char* sendPtr;
159 
160  unsigned char panSpeed_;
161  unsigned char tiltSpeed_;
162  unsigned char activeUnit_;
163 
165 };
166 
167 }//end namespace
168 #endif
BIAS::SerialPortIO serialIO_
unsigned char * sendPtr
Communication over the serial port, use OpenPort with e.g.
Definition: SerialPortIO.hh:63
pthread_mutex_t camMutex
unsigned char panSpeed_
unsigned char activeUnit_
void SetPanSpeed(unsigned char panSpeed)
for use with Sony PanTilt Cameras, also compatible with WISKA PanTilt Cameras.
Definition: ViscaControl.hh:57
unsigned char tiltSpeed_
void SetTiltSpeed(unsigned char tiltSpeed)
void SetActiveUnit(unsigned char activeUnit)