Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DPPanTiltControlExtended.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 __DPPanTiltControlExtended_hh__
26 #define __DPPanTiltControlExtended_hh__
27 
28 #include "DPPanTiltControl.hh"
29 
30 #include <Base/Math/Vector.hh>
31 #include <Base/Math/Vector2.hh>
32 #include <Geometry/RMatrix.hh>
33 
34 #ifdef BIAS_HAVE_PTHREADS
35 # include <pthread.h>
36 #endif
37 
38 // define object tracking control mode
39 #define TRACK_ABS_POS_MODE 100
40 #define TRACK_PID_SPEED_MODE 101
41 #define TRACK_REC_SPEED_MODE 102
42 
43 namespace BIAS
44 {
45  /**
46  @class DPPanTiltControlExtended
47  @brief Extended controller interface for Directed Perception Pan Tilt Unit.
48  @author Ingo Schiller
49  @data 10/2011
50  */
51  class BIASPanTilt_EXPORT DPPanTiltControlExtended : public DPPanTiltControl
52  {
53  public:
54 
55  /** @brief Standard constructor */
57 
58  /** @brief Standard destructor */
60 
61  /** @brief Set the proportional parameter of the Ziegler-Nichols tuning. */
62  void SetKp(const BIAS::Vector<int> &kp);
63 
64  /** @brief Set the integral parameter of the Ziegler-Nichols tuning. */
65  void SetKi(const BIAS::Vector<int> &ki);
66 
67  /** @brief Set the derivative parameter of the Ziegler-Nichols tuning. */
68  void SetKd(const BIAS::Vector<int> &kd);
69 
70  /**@brief Compensates movement of coordinate system the PTU is mounted to.
71  @attention Only rotation is supported yet!
72  @note Implemented for helicopter project by Ingo Schiller */
73  void CompensateHeliMovement(const BIAS::RMatrix &R);
74 
75  /**@brief Simple object tracking method, uses absolut positioning error
76  and moves PTU and camera to position newMean.
77  @param[in] newMean Defines the setpoint to adjust the PTU to.
78  @attention Mode has to be set to ABSOLUTEMODE! */
79  void FollowMidPos(const BIAS::Vector2<double> &newMean);
80 
81  /** @brief Perform PID controlling of the PTU. Very simple algorithm
82  without deadtime and frequency.
83  @param[in] newMean Defines the setpoint to adjust the PTU to.
84  @attention Mode has to be set to SPEEDMODE! */
85  void PIDSpeedAdjustFollow(const BIAS::Vector2<double> &newMean);
86 
87  /**@brief Perform digital controlling of the PTU as described in Herbert
88  Schlitt (pages 215 ff.).
89  Takes care of deadtime and frequency of the algorithm. Makes recursive
90  calculation and calculates the difference in velocity of the PTU.
91  @param[in] newMean Defines the setpoint to adjust the PTU to.
92  @attention Mode has to be set to SPEEDMODE! */
93  void RecursivePIControl(const BIAS::Vector2<double> &newMean);
94 
95  inline void SetSamplingTime(float t) { T_ = t; }
96 
97  inline void SetResetTime(float tn) { Tn_ = tn; }
98 
99  /** @brief Set the size of the picture of the camera mounted to the PTU.
100  This is needed to calculate the speeds to keep an object in
101  the middle of the picture while steering the PTU.
102  @note Implemented for helicopter project by Ingo Schiller */
103  inline void SetPictureSize(unsigned int xSize, unsigned int ySize) {
104  xPictureSize_ = xSize;
105  yPictureSize_ = ySize;
106  }
107 
108  /** @brief Set the aperture angle of the camera mounted to the PTU.
109  This is needed to calculate the speeds to keep an object in
110  the middle of the picture while steering the PTU.
111  @note Implemented for helicopter project by Ingo Schiller */
112  inline void SetApertureAngle(double xAngle, double yAngle) {
113  xApertureAngle_ = xAngle;
114  yApertureAngle_ = yAngle;
115  }
116 
117 #ifdef BIAS_HAVE_PTHREADS
118 
119  /** @brief Start a thread moving the PTU in a circle. */
120  void StartCircularMovementThread();
121 
122  /** @brief Get the position in degrees while moving in thread. */
123  void GetCurrentPositionDegreesThreaded(double &dPanDeg, double& dTiltDeg);
124 
125  /** @brief Get the position in radians while moving in thread. */
126  void GetCurrentPositionRadiansThreaded(double &dPanRad, double& dTiltRad);
127 
128 #endif
129 
130  protected:
131 
132 #ifdef BIAS_HAVE_PTHREADS
133 
134  // variables for thread to control camera movement
135  pthread_t control_thread;
136  static pthread_mutex_t condition_mutex;
137  static long panThreaded_;
138  static long tiltThreaded_;
139  static void* threadFuncCircle_(void *ptr);
140 
141 #endif
142 
143  // parameters for Ziegler-Nichols tuning
144  double KpX_, KpY_, KiX_, KiY_, KdX_, KdY_;
145  int ZiNiErrorX_; // total error in the Ziegler-Nichols tuning method x
146  int ZiNiErrorY_; // total error in the Ziegler-Nichols tuning method y
149 
150  // variables for object tracking
155  unsigned int xPictureSize_;
156  unsigned int yPictureSize_;
157 
158  // variables for sensor/motion compensation
160  short int xPTSpeed_;
161  short int yPTSpeed_;
162  short int panSpeedComp_;
163  short int tiltSpeedComp_;
164 
165  // orientation matrices for sensor/motion compensation
166  BIAS::RMatrix ptuMatrix_, deltaMatrix_, handEyeMatrix_, sensorMatrixMinus1_;
167 
168  // variables for recursive control
169  float T_; // time between discretisation of sampler
170  float Tn_; // time lag
171  short int xPTDeltaSpeed_;
172  short int yPTDeltaSpeed_;
175  std::vector<int> ErrorTMinus1_;
176  int RPICounter_; // iteration counter for recursive control
177 
178  };
179 
180 }
181 
182 #endif // __DPPanTiltControlExtended_hh__
Basic controller interface for Directed Perception Pan Tilt Unit.
Extended controller interface for Directed Perception Pan Tilt Unit.
3D rotation matrix
Definition: RMatrix.hh:49
void SetPictureSize(unsigned int xSize, unsigned int ySize)
Set the size of the picture of the camera mounted to the PTU.
void SetApertureAngle(double xAngle, double yAngle)
Set the aperture angle of the camera mounted to the PTU.