Fawkes API  Fawkes Development Version
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  class JointInterface;
39 }
40 
42 
44 : public PanTiltActThread,
46 {
47  public:
48  PanTiltDirectedPerceptionThread(std::string &pantilt_cfg_prefix,
49  std::string &ptu_cfg_prefix,
50  std::string &ptu_name);
51 
52  virtual void init();
53  virtual void finalize();
54  virtual void loop();
55 
56  // For BlackBoardInterfaceListener
57  virtual bool bb_interface_message_received(fawkes::Interface *interface,
58  fawkes::Message *message) throw();
59 
60  void update_sensor_values();
61 
62  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
63  protected: virtual void run() { Thread::run(); }
64 
65  private:
66  fawkes::PanTiltInterface *__pantilt_if;
67  fawkes::JointInterface *__panjoint_if;
68  fawkes::JointInterface *__tiltjoint_if;
69 
71 
72  std::string __pantilt_cfg_prefix;
73  std::string __ptu_cfg_prefix;
74  std::string __ptu_name;
75  std::string __cfg_device;
76  unsigned int __cfg_read_timeout_ms;
77 
78 
79  class WorkerThread : public fawkes::Thread
80  {
81  public:
82  WorkerThread(std::string ptu_name, fawkes::Logger *logger,
84 
85  ~WorkerThread();
86  void goto_pantilt(float pan, float tilt);
87  void get_pantilt(float &pan, float &tilt);
88  bool is_final();
89  void stop_motion();
90  bool has_fresh_data();
91  void reset();
92 
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 
112  float __cur_pan;
113  float __cur_tilt;
114 
115  bool __reset_pending;
116  bool __fresh_data;
117  };
118 
119  WorkerThread *__wt;
120 };
121 
122 #endif
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
Fawkes library namespace.
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:939
Thread class encapsulation of pthreads.
Definition: thread.h:42
DirectedPerception PTU implementation.
Definition: dp_ptu.h:30
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
PanTilt act thread for PTUs from DirectedPerception employing the ASCII protocol. ...
Definition: dp_thread.h:43
Pan/tilt act thread.
Definition: act_thread.h:36
PanTiltInterface Fawkes BlackBoard Interface.
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: dp_thread.h:63
JointInterface Fawkes BlackBoard Interface.
Mutex mutual exclusion lock.
Definition: mutex.h:32
BlackBoard interface listener.
Interface for logging.
Definition: logger.h:34