Fawkes API  Fawkes Development Version
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-2014 Tim Niemueller [www.niemueller.de]
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Library General Public License for more details.
18  *
19  * Read the full text in the LICENSE.GPL file in the doc directory.
20  */
21 
22 #ifndef __PLUGINS_PANTILT_SONY_EVID100P_THREAD_H_
23 #define __PLUGINS_PANTILT_SONY_EVID100P_THREAD_H_
24 
25 #include "../act_thread.h"
26 
27 #include <blackboard/interface_listener.h>
28 #include <interfaces/CameraControlInterface.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  class SwitchInterface;
40 }
41 
42 class SonyEviD100PVisca;
43 
45 : public PanTiltActThread,
47 {
48  public:
49  PanTiltSonyEviD100PThread(std::string &pantilt_cfg_prefix,
50  std::string &ptu_cfg_prefix,
51  std::string &ptu_name);
52 
53  virtual void init();
54  virtual void finalize();
55  virtual void loop();
56 
57  // For BlackBoardInterfaceListener
58  virtual bool bb_interface_message_received(fawkes::Interface *interface,
59  fawkes::Message *message) throw();
60 
61  void update_sensor_values();
62 
63  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
64  protected: virtual void run() { Thread::run(); }
65 
66  private:
67  fawkes::PanTiltInterface *__pantilt_if;
68  fawkes::JointInterface *__panjoint_if;
69  fawkes::JointInterface *__tiltjoint_if;
70  fawkes::CameraControlInterface *__camctrl_if;
71  fawkes::SwitchInterface *__power_if;
72 
74 
75  std::string __pantilt_cfg_prefix;
76  std::string __ptu_cfg_prefix;
77  std::string __ptu_name;
78  std::string __cfg_device;
79  unsigned int __cfg_read_timeout_ms;
80 
81  class WorkerThread : public fawkes::Thread
82  {
83  public:
84  WorkerThread(std::string ptu_name, fawkes::Logger *logger,
86  const float &pan_min, const float &pan_max,
87  const float &tilt_min, const float &tilt_max);
88 
89  ~WorkerThread();
90  void set_power(bool powered);
91  void goto_pantilt(float pan, float tilt);
92  void get_pantilt(float &pan, float &tilt);
93  void set_velocities(float pan_vel, float tilt_vel);
94  void set_mirror(bool enabled);
95  void set_zoom(unsigned int zoom_value);
96  unsigned int get_zoom();
97  void set_effect(fawkes::CameraControlInterface::Effect effect);
98  bool is_final();
99  void stop_motion();
100  bool has_fresh_data();
101 
102  virtual void once();
103  virtual void loop();
104 
105  private:
106  void exec_goto_pantilt(float pan, float tilt);
107  void exec_set_zoom(unsigned int zoom);
108  void exec_set_effect(fawkes::CameraControlInterface::Effect effect);
109  void exec_set_mirror(bool mirror);
110 
111  private:
113  fawkes::Logger *__logger;
114 
115  fawkes::Mutex *__power_mutex;
116  bool __powered;
117  bool __power_pending;
118  bool __power_desired;
119 
120  float __pan_min;
121  float __pan_max;
122  float __tilt_min;
123  float __tilt_max;
124 
125  fawkes::Mutex *__move_mutex;
126  bool __move_pending;
127  float __target_pan;
128  float __target_tilt;
129  bool __velo_pending;
130  float __pan_vel;
131  float __tilt_vel;
132 
133  fawkes::Mutex *__zoom_mutex;
134  bool __zoom_pending;
135  float __target_zoom;
136 
137  fawkes::Mutex *__effect_mutex;
138  bool __effect_pending;
140 
141  fawkes::Mutex *__mirror_mutex;
142  bool __mirror_pending;
143  bool __target_mirror;
144 
145  float __cur_pan;
146  float __cur_tilt;
147 
148  unsigned int __cur_zoom;
149 
150  bool __fresh_data;
151  };
152 
153  WorkerThread *__wt;
154 };
155 
156 #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
CameraControlInterface Fawkes BlackBoard Interface.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
SwitchInterface Fawkes BlackBoard Interface.
Pan/tilt act thread.
Definition: act_thread.h:36
Effect
Enumeration defining the possible effects.
Sony EviD100P Visca controller.
Definition: evid100p.h:32
PanTiltInterface Fawkes BlackBoard Interface.
JointInterface Fawkes BlackBoard Interface.
virtual void run()
Stub to see name in backtrace for easier debugging.
Mutex mutual exclusion lock.
Definition: mutex.h:32
PanTilt act thread for the PTU part of the Sony EviD100P camera.
BlackBoard interface listener.
Interface for logging.
Definition: logger.h:34