Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dp_thread.h
1 
2 /***************************************************************************
3  * dp_thread.h - DirectedPerception pan/tilt unit act thread
4  *
5  * Created: Sun Jun 21 17:26:33 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_DIRPERC_DP_THREAD_H_
24 #define __PLUGINS_PANTILT_DIRPERC_DP_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 
41 
43 : public PanTiltActThread,
45 {
46  public:
47  PanTiltDirectedPerceptionThread(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 
82  ~WorkerThread();
83  void goto_pantilt(float pan, float tilt);
84  void get_pantilt(float &pan, float &tilt);
85  bool is_final();
86  void stop_motion();
87  bool has_fresh_data();
88  void reset();
89 
90  virtual void loop();
91 
92  private:
93  void exec_goto_pantilt(float pan, float tilt);
94 
95  private:
97  fawkes::Logger *__logger;
98 
99  float __pan_min;
100  float __pan_max;
101  float __tilt_min;
102  float __tilt_max;
103 
104  fawkes::Mutex *__move_mutex;
105  bool __move_pending;
106  float __target_pan;
107  float __target_tilt;
108 
109  float __cur_pan;
110  float __cur_tilt;
111 
112  bool __reset_pending;
113  bool __fresh_data;
114  };
115 
116  WorkerThread *__wt;
117 };
118 
119 #endif