Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
evid100p_thread.h
1 
2 /***************************************************************************
3  * evid100p_thread.h - Sony EviD100P pan/tilt unit act thread
4  *
5  * Created: Sun Jun 21 12:30:59 2009
6  * Copyright 2006-2009 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program 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 Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef __PLUGINS_PANTILT_SONY_EVID100P_THREAD_H_
24 #define __PLUGINS_PANTILT_SONY_EVID100P_THREAD_H_
25 
26 #include "../act_thread.h"
27 
28 #include <blackboard/interface_listener.h>
29 
30 #ifdef USE_TIMETRACKER
31 # include <utils/time/tracker.h>
32 #endif
33 #include <string>
34 #include <memory>
35 
36 namespace fawkes {
37  class PanTiltInterface;
38 }
39 
40 class SonyEviD100PVisca;
41 
43 : public PanTiltActThread,
45 {
46  public:
47  PanTiltSonyEviD100PThread(std::string &pantilt_cfg_prefix,
48  std::string &ptu_cfg_prefix,
49  std::string &ptu_name);
50 
51  virtual void init();
52  virtual void finalize();
53  virtual void loop();
54 
55  // For BlackBoardInterfaceListener
56  virtual bool bb_interface_message_received(fawkes::Interface *interface,
57  fawkes::Message *message) throw();
58 
59  void update_sensor_values();
60 
61  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
62  protected: virtual void run() { Thread::run(); }
63 
64  private:
65  fawkes::PanTiltInterface *__pantilt_if;
66 
68 
69  std::string __pantilt_cfg_prefix;
70  std::string __ptu_cfg_prefix;
71  std::string __ptu_name;
72  std::string __cfg_device;
73  unsigned int __cfg_read_timeout_ms;
74 
75 
76  class WorkerThread : public fawkes::Thread
77  {
78  public:
79  WorkerThread(std::string ptu_name, fawkes::Logger *logger,
81  const float &pan_min, const float &pan_max,
82  const float &tilt_min, const float &tilt_max);
83 
84  ~WorkerThread();
85  void goto_pantilt(float pan, float tilt);
86  void get_pantilt(float &pan, float &tilt);
87  void set_velocities(float pan_vel, float tilt_vel);
88  bool is_final();
89  void stop_motion();
90  bool has_fresh_data();
91 
92  virtual void once();
93  virtual void loop();
94 
95  private:
96  void exec_goto_pantilt(float pan, float tilt);
97 
98  private:
100  fawkes::Logger *__logger;
101 
102  float __pan_min;
103  float __pan_max;
104  float __tilt_min;
105  float __tilt_max;
106 
107  fawkes::Mutex *__move_mutex;
108  bool __move_pending;
109  float __target_pan;
110  float __target_tilt;
111  bool __velo_pending;
112  float __pan_vel;
113  float __tilt_vel;
114 
115  float __cur_pan;
116  float __cur_tilt;
117 
118  bool __fresh_data;
119  };
120 
121  WorkerThread *__wt;
122 };
123 
124 #endif