Fawkes API  Fawkes Development Version
acquisition_thread.h
1 
2 /***************************************************************************
3  * acquisition_thread.h - FireVision Acquisition Thread
4  *
5  * Created: Wed Jun 06 19:01:10 2007
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 __FIREVISION_APPS_BASE_ACQUISITION_THREAD_H_
24 #define __FIREVISION_APPS_BASE_ACQUISITION_THREAD_H_
25 
26 #include <core/threading/thread.h>
27 
28 #include <aspect/logging.h>
29 #include <aspect/blackboard.h>
30 
31 #include <fvcams/shmem.h>
32 #include <fvutils/color/colorspaces.h>
33 #include <blackboard/interface_listener.h>
34 
35 #include <map>
36 
37 namespace fawkes {
38  class Logger;
39  class Clock;
40  class Mutex;
41  class WaitCondition;
42  class SwitchInterface;
43 #ifdef FVBASE_TIMETRACKER
44  class TimeTracker;
45 #endif
46 }
47 namespace firevision {
48  class SharedMemoryImageBuffer;
49 }
50 class FvBaseThread;
51 class FvAqtVisionThreads;
52 
54 : public fawkes::Thread,
55  public fawkes::LoggingAspect,
58 {
59  public:
60  /** Acquisition thread mode. */
61  typedef enum {
62  AqtCyclic, /**< cyclic mode, use if there is at least one cyclic thread
63  * for this acquisition thread. */
64  AqtContinuous /**< continuous mode, use if there are only continuous threads
65  * for this acquisition thread. */
66  } AqtMode;
67 
68  FvAcquisitionThread(const char *id, firevision::Camera *camera,
69  fawkes::Logger *logger, fawkes::Clock *clock);
70  virtual ~FvAcquisitionThread();
71 
72  virtual void init();
73  virtual void loop();
74  virtual void finalize();
75 
76  void set_aqtmode(AqtMode mode);
77  AqtMode aqtmode();
78  firevision::Camera * camera_instance(firevision::colorspace_t cspace, bool deep_copy);
79 
80  firevision::Camera *get_camera();
81 
82  void set_vt_prepfin_hold(bool hold);
83  void set_enabled(bool enabled);
84 
85  public:
86  /** Vision threads assigned to this acquisition thread. To be used only by the
87  * base thread. */
89 
90  /** Vision thread registered for raw camera access on this camera. */
92 
93  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
94  protected: virtual void run() { Thread::run(); }
95 
96  private:
97  virtual bool bb_interface_message_received(fawkes::Interface *interface,
98  fawkes::Message *message) throw();
99 
100  private:
101  bool __enabled;
102  fawkes::Mutex *__enabled_mutex;
103  fawkes::WaitCondition *__enabled_waitcond;
104 
105  firevision::Camera *__camera;
106  char *__image_id;
107 
108  firevision::colorspace_t __colorspace;
109  unsigned int __width;
110  unsigned int __height;
111 
112  AqtMode __mode;
113 
114  std::map<firevision::colorspace_t, firevision::SharedMemoryImageBuffer *> __shm;
115  std::map<firevision::colorspace_t, firevision::SharedMemoryImageBuffer *>::iterator __shmit;
116 
117  fawkes::SwitchInterface *__enabled_if;
118 
119 #ifdef FVBASE_TIMETRACKER
120  fawkes::TimeTracker *__tt;
121  unsigned int __loop_count;
122  unsigned int __ttc_capture;
123  unsigned int __ttc_lock;
124  unsigned int __ttc_convert;
125  unsigned int __ttc_unlock;
126  unsigned int __ttc_dispose;
127 #endif
128 };
129 
130 #endif
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
Wait until a given condition holds.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:44
AqtMode
Acquisition thread mode.
Camera interface for image aquiring devices in FireVision.
Definition: camera.h:35
Fawkes library namespace.
fawkes::Thread * raw_subscriber_thread
Vision thread registered for raw camera access on this camera.
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:939
This is supposed to be the central clock in Fawkes.
Definition: clock.h:34
FvAqtVisionThreads * vision_threads
Vision threads assigned to this acquisition thread.
virtual void run()
Stub to see name in backtrace for easier debugging.
Aquisition-dependant threads.
Thread class encapsulation of pthreads.
Definition: thread.h:42
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
FireVision base application acquisition thread.
SwitchInterface Fawkes BlackBoard Interface.
FireVision base thread.
Definition: base_thread.h:46
Time tracking utility.
Definition: tracker.h:38
Thread aspect to log output.
Definition: logging.h:35
Mutex mutual exclusion lock.
Definition: mutex.h:32
BlackBoard interface listener.
Interface for logging.
Definition: logger.h:34