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 <memory>
34 #include <string>
35 
36 namespace fawkes {
37 class PanTiltInterface;
38 class JointInterface;
39 class SwitchInterface;
40 } // namespace fawkes
41 
42 class SonyEviD100PVisca;
43 
46 {
47 public:
48  PanTiltSonyEviD100PThread(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) noexcept;
59 
60  void update_sensor_values();
61 
62  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
63 protected:
64  virtual void
65  run()
66  {
67  Thread::run();
68  }
69 
70 private:
71  fawkes::PanTiltInterface * pantilt_if_;
72  fawkes::JointInterface * panjoint_if_;
73  fawkes::JointInterface * tiltjoint_if_;
74  fawkes::CameraControlInterface *camctrl_if_;
75  fawkes::SwitchInterface * power_if_;
76 
78 
79  std::string pantilt_cfg_prefix_;
80  std::string ptu_cfg_prefix_;
81  std::string ptu_name_;
82  std::string cfg_device_;
83  unsigned int cfg_read_timeout_ms_;
84 
85  class WorkerThread : public fawkes::Thread
86  {
87  public:
88  WorkerThread(std::string ptu_name,
91  const float & pan_min,
92  const float & pan_max,
93  const float & tilt_min,
94  const float & tilt_max);
95 
96  ~WorkerThread();
97  void set_power(bool powered);
98  void goto_pantilt(float pan, float tilt);
99  void get_pantilt(float &pan, float &tilt);
100  void set_velocities(float pan_vel, float tilt_vel);
101  void set_mirror(bool enabled);
102  void set_zoom(unsigned int zoom_value);
103  unsigned int get_zoom();
104  void set_effect(fawkes::CameraControlInterface::Effect effect);
105  bool is_final();
106  void stop_motion();
107  bool has_fresh_data();
108 
109  virtual void once();
110  virtual void loop();
111 
112  private:
113  void exec_goto_pantilt(float pan, float tilt);
114  void exec_set_zoom(unsigned int zoom);
115  void exec_set_effect(fawkes::CameraControlInterface::Effect effect);
116  void exec_set_mirror(bool mirror);
117 
118  private:
120  fawkes::Logger * logger_;
121 
122  fawkes::Mutex *power_mutex_;
123  bool powered_;
124  bool power_pending_;
125  bool power_desired_;
126 
127  float pan_min_;
128  float pan_max_;
129  float tilt_min_;
130  float tilt_max_;
131 
132  fawkes::Mutex *move_mutex_;
133  bool move_pending_;
134  float target_pan_;
135  float target_tilt_;
136  bool velo_pending_;
137  float pan_vel_;
138  float tilt_vel_;
139 
140  fawkes::Mutex *zoom_mutex_;
141  bool zoom_pending_;
142  float target_zoom_;
143 
144  fawkes::Mutex * effect_mutex_;
145  bool effect_pending_;
147 
148  fawkes::Mutex *mirror_mutex_;
149  bool mirror_pending_;
150  bool target_mirror_;
151 
152  float cur_pan_;
153  float cur_tilt_;
154 
155  unsigned int cur_zoom_;
156 
157  bool fresh_data_;
158  };
159 
160  WorkerThread *wt_;
161 };
162 
163 #endif
Pan/tilt act thread.
Definition: act_thread.h:41
PanTilt act thread for the PTU part of the Sony EviD100P camera.
PanTiltSonyEviD100PThread(std::string &pantilt_cfg_prefix, std::string &ptu_cfg_prefix, std::string &ptu_name)
Constructor.
virtual void finalize()
Finalize the thread.
virtual void loop()
Code to execute in the thread.
virtual void run()
Stub to see name in backtrace for easier debugging.
virtual bool bb_interface_message_received(fawkes::Interface *interface, fawkes::Message *message) noexcept
BlackBoard message received notification.
void update_sensor_values()
Update sensor values as necessary.
virtual void init()
Initialize the thread.
Sony EviD100P Visca controller.
Definition: evid100p.h:33
BlackBoard interface listener.
CameraControlInterface Fawkes BlackBoard Interface.
Effect
Enumeration defining the possible effects.
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:80
JointInterface Fawkes BlackBoard Interface.
Interface for logging.
Definition: logger.h:42
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
Mutex mutual exclusion lock.
Definition: mutex.h:33
PanTiltInterface Fawkes BlackBoard Interface.
SwitchInterface Fawkes BlackBoard Interface.
Thread class encapsulation of pthreads.
Definition: thread.h:46
virtual void once()
Execute an action exactly once.
Definition: thread.cpp:1085
Fawkes library namespace.