Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DPPanTiltControl.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 __DPPanTiltControl_hh__
26 #define __DPPanTiltControl_hh__
27 
28 #include <bias_config.h>
29 
30 #include <stdio.h>
31 #ifndef WIN32
32 # include <unistd.h>
33 #endif
34 #include <iostream>
35 #include <vector>
36 
37 // Include headers for Directed Perception PTU
38 extern "C"
39 {
40 #include "include/ptu.h"
41 #ifndef WIN32
42 # include "include/linuxser.h"
43 #else
44 # include "include/w32seria.h"
45 #endif
46 }
47 
48 // @note Call QueryResolution to get actual pan/tilt resolution
49 // because it depends on the PTU model and speed settings!
50 
51 #define DPPTU_DEF_RES 0.051428
52 #define DPPTU_MAXSPEED 2901
53 
54 #define DPPTU_MINPAN -3000
55 #define DPPTU_MAXPAN 3000
56 #define DPPTU_MINTILT -500
57 #define DPPTU_MAXTILT 300
58 
59 #define SPEEDMODE 0
60 #define ABSOLUTEMODE 1
61 
62 namespace BIAS
63 {
64  /**
65  @class DPPanTiltControl
66  @brief Basic controller interface for Directed Perception Pan Tilt Unit.
67  @author MIP
68  */
69  class BIASPanTilt_EXPORT DPPanTiltControl
70  {
71  public:
72 
74  AUTO = 0,
78  FULL
79  };
80 
81  /** @brief Standard constructor */
83 
84  /** @brief Standard destructor */
86 
87  /** @brief Set the mode in which the camera is to operate
88  @param[in] nMode Defines the mode, 0 is speed control mode,
89  1 is absolute positioning mode
90  @return Returns 0 on success, != 0 for errors */
91  int SetMode(int nMode);
92 
93  /** @brief Reset the position of the pan tilt unit to 0.
94  @return Returns true on success, false for errors */
95  bool ResetPanTiltUnit();
96 
97  /** @brief Stop the currently moving pan tilt unit. */
98  void StopPanTiltUnit();
99 
100  /** @brief Await completion of currently executed command. */
101  void AwaitCompletion();
102 
103  /** @brief Open the given serial port and initialize the pan tilt unit.
104  @param[in] nPort The number of the serial port (or USB port)
105  @param[in] bUSB Use USB port instead of serial port
106  @return Returns true on success, false for errors */
107  bool InitPanTiltUnit(int nPort, bool bUSB = false);
108 
109  /** @brief Open the given port and initialize the pan tilt unit.
110  @param[in] portName The name of the serial port or USB port to open,
111  e.g. /dev/ttyUSB0
112  @return Returns true on success, false for errors */
113  bool InitPanTiltUnit(const char *portName);
114 
115  /** @brief closes the comport stream connected to PTU */
116  void ClosePanTiltUnit();
117 
118  /** @brief Move camera nValue steps upwards */
119  void MoveUp(int nValue);
120 
121  /** @brief Move camera nValue steps downwards */
122  void MoveDown(int nValue);
123 
124  /** @brief Move camera nValue steps left */
125  void MoveLeft(int nValue);
126 
127  /** @brief Move camera nValue steps right */
128  void MoveRight(int nValue);
129 
130  /** @brief Start a thread moving the PTU in a circle */
131  void StartCircularMovement();
132 
133  /** @brief Set speed for movement */
134  char SetSpeed(int nPanSpeed,int nTiltSpeed);
135 
136  /** @brief Set acceleration for movement */
137  char SetAcceleration(int nPanAcc, int nTiltAcc);
138 
139  /** @brief Get the resolution of the pan axis
140  @return Returns the pan resolution in radians per step */
141  double GetPanResolution() { return panResolution_; }
142 
143  /** @brief Get the resolution of the tilt axis
144  @return Returns the tilt resolution in radians per step */
145  double GetTiltResolution() { return tiltResolution_; }
146 
147  /** @return Returns the current speed */
148  void GetSpeed(long &panSpeed, long &tiltSpeed);
149 
150  /** @return Returns the current acceleration */
151  void GetAcceleration(long &panAcc, long &tiltAcc);
152 
153  /** @return Returns the current position of the PTU in steps */
154  void GetCurrentPosition(long &lPanPos, long &lTiltPos);
155 
156  /** @return Returns the current position of the PTU in degrees */
157  void GetCurrentPositionDegrees(double &dPanDeg, double &dTiltDeg);
158 
159  /** @return Returns the current position of the PTU in radians */
160  void GetCurrentPositionRadians(double &dPanRad, double &dTiltRad);
161 
162  /** @brief Set the current position of the PTU in steps */
163  void SetPosition(int nPanPos, int nTiltPos, bool bWaitComplete = true);
164 
165  /** @brief Send a command string terminated by a space or carriage
166  return character to the serial (or USB) port. */
167  void SendRawCommand(std::string cmd);
168 
169  /** @brief Read a line from the serial (or USB) port.
170  @return Returns the length of the read string, or 0 when nothing
171  has been read */
172  int ReadRawLine(std::string &cmd);
173 
174  /** @brief Set the stepping of the motor. */
175  int SetMotorStepping(int panStepping, int tiltStepping);
176 
177  /** @brief Get resolution of the motor.
178  @param[out] panResolution Return the pan resolution
179  @param[out] tiltResolution Returns the tilt resolution */
180  void QueryResolution(double &panResolution, double &tiltResolution,
181  bool updateInternal = false);
182 
183  /** @brief Set the orientation of the PTU (default or upside-down).
184  @param[in] use Use true for default orientation and false for mounting
185  upside down (e.g. when mounted under helicopter)
186  @note Implemented for helicopter project by Ingo Schiller */
187  inline void UseDefaultOrientation(bool use) { bDefaultOrientation_ = use; }
188 
189  protected:
190 
191  portstream_fd COMstream_;
192  short int maxSpeed_;
193  double panResolution_, tiltResolution_;
195 
196  };
197 
198 }
199 
200 #endif // __DPPanTiltControl_hh__
double GetTiltResolution()
Get the resolution of the tilt axis.
void UseDefaultOrientation(bool use)
Set the orientation of the PTU (default or upside-down).
Basic controller interface for Directed Perception Pan Tilt Unit.
double GetPanResolution()
Get the resolution of the pan axis.