Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PanTiltAutoControl.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 PANTILTAUTOCONTROL_HH_
26 #define PANTILTAUTOCONTROL_HH_
27 
28 #include <pthread.h>
29 #include "PanTiltControlInterface.hh"
30 
31 namespace BIAS{
32 
33 /**
34  * \class PanTiltAutoControl, derived from PanTiltControlInterface
35  * \brief Automatic control of the PanTilt Unit from Directed Perception
36  * \author fkellner
37  */
38 class BIASPanTilt_EXPORT PanTiltAutoControl : public PanTiltControlInterface {
39 public:
40  /** \brief constructor has nothing to do,
41  * super-constructor will startup communication */
42  PanTiltAutoControl(std::string device, bool heavyDutyMode);
43  /** \brief destructor moves to (0,0), then
44  * calls super-destructor to release ttyS0 */
46  /** \brief start moving around */
47  void StartControl();
48  /** \brief stop/pause moving around*/
49  void StopControl();
50  /** \brief resume moving around*/
51  void ResumeControl();
52 
53  /** \brief move to desired position */
54  void StartMoveTo(const long int pan, const long int tilt);
55  /** \brief stop move to desired position*/
56  void StopMoveTo();
57  /** \brief check if position is reached */
58  inline bool Stopped() {
59  return !started_;
60  }
61 
62 private:
63  // thread to control camera movement
64  pthread_t control_thread;
65  // actual movement function, ptr should hold a pointer to this classes ptu-object
66  static void* threadFunc_pan_only(void *ptr);
67  // actual movement function, ptr should hold a pointer to this classes ptu-object
68  static void* threadFunc_pan_tilt(void *ptr);
69 
70  // actual movement to a desired position, ptr should hold a pointer to this classes ptu-object
71  static void* threadFunc_move_to(void *ptr);
72 
73  // conditions for the thread
74  static pthread_mutex_t condition_mutex;
75  static pthread_cond_t condition_cond;
76 
77  // thread control variables
78  static bool exiting_;
79  static bool waiting_;
80  static bool started_;
81  static bool bSpeedMode_;
82 
83  // some useful helper functions, should be in some more general class
84  static int abs(int val);
85  static int min(int val1, int val2);
86  static int max(int val1, int val2);
87 
88  static long int des_pan;
89  static long int des_tilt;
90 
91 };
92 
93 /**
94  * \class PanTiltAutoControlFactory
95  * \brief Factory to create a PanTiltAutoControl
96  */
97 class BIASPanTilt_EXPORT PanTiltAutoControlFactory : public PanTiltControlFactory {
98 public:
99  PanTiltAutoControl* Create(std::string device, bool heavyDutyMode) {
100  return new PanTiltAutoControl(device, heavyDutyMode);
101  }
102 };
103 }
104 #endif /*PANTILTAUTOCONTROL_HH_*/
PanTiltControlInterface.
abstract control class for control of Directed Perception Pan Tilt Unit.
bool Stopped()
check if position is reached
PanTiltAutoControl * Create(std::string device, bool heavyDutyMode)
Abstract controller factory used to create all different kinds of PTU controls.
Factory to create a PanTiltAutoControl.