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 <aspect/blackboard.h>
27 #include <aspect/logging.h>
28 #include <blackboard/interface_listener.h>
29 #include <core/threading/thread.h>
30 #include <fvcams/shmem.h>
31 #include <fvutils/color/colorspaces.h>
32 
33 #include <map>
34 
35 namespace fawkes {
36 class Logger;
37 class Clock;
38 class Mutex;
39 class WaitCondition;
40 class SwitchInterface;
41 #ifdef FVBASE_TIMETRACKER
42 class TimeTracker;
43 #endif
44 } // namespace fawkes
45 namespace firevision {
46 class SharedMemoryImageBuffer;
47 }
48 class FvBaseThread;
49 class FvAqtVisionThreads;
50 
52  public fawkes::LoggingAspect,
55 {
56 public:
57  /** Acquisition thread mode. */
58  typedef enum {
59  AqtCyclic, /**< cyclic mode, use if there is at least one cyclic thread
60  * for this acquisition thread. */
61  AqtContinuous /**< continuous mode, use if there are only continuous threads
62  * for this acquisition thread. */
64 
65  FvAcquisitionThread(const char * id,
66  firevision::Camera *camera,
68  fawkes::Clock * clock);
69  virtual ~FvAcquisitionThread();
70 
71  virtual void init();
72  virtual void loop();
73  virtual void finalize();
74 
75  void set_aqtmode(AqtMode mode);
76  AqtMode aqtmode();
77  firevision::Camera *camera_instance(firevision::colorspace_t cspace, bool deep_copy);
78 
80 
81  void set_vt_prepfin_hold(bool hold);
82  void set_enabled(bool enabled);
83 
84 public:
85  /** Vision threads assigned to this acquisition thread. To be used only by the
86  * base thread. */
88 
89  /** Vision thread registered for raw camera access on this camera. */
91 
92  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
93 protected:
94  virtual void
95  run()
96  {
97  Thread::run();
98  }
99 
100 private:
101  virtual bool bb_interface_message_received(fawkes::Interface *interface,
102  fawkes::Message * message) throw();
103 
104 private:
105  bool enabled_;
106  fawkes::Mutex * enabled_mutex_;
107  fawkes::WaitCondition *enabled_waitcond_;
108 
109  firevision::Camera *camera_;
110  char * image_id_;
111 
112  firevision::colorspace_t colorspace_;
113  unsigned int width_;
114  unsigned int height_;
115 
116  AqtMode mode_;
117 
118  std::map<firevision::colorspace_t, firevision::SharedMemoryImageBuffer *> shm_;
119  std::map<firevision::colorspace_t, firevision::SharedMemoryImageBuffer *>::iterator shmit_;
120 
121  fawkes::SwitchInterface *enabled_if_;
122 
123 #ifdef FVBASE_TIMETRACKER
124  fawkes::TimeTracker *tt_;
125  unsigned int loop_count_;
126  unsigned int ttc_capture_;
127  unsigned int ttc_lock_;
128  unsigned int ttc_convert_;
129  unsigned int ttc_unlock_;
130  unsigned int ttc_dispose_;
131 #endif
132 };
133 
134 #endif
FireVision base application acquisition thread.
firevision::Camera * get_camera()
Get the Camera of this acquisition thread.
FvAcquisitionThread(const char *id, firevision::Camera *camera, fawkes::Logger *logger, fawkes::Clock *clock)
Constructor.
virtual ~FvAcquisitionThread()
Destructor.
virtual void finalize()
Finalize the thread.
void set_aqtmode(AqtMode mode)
Set acquisition thread mode.
FvAqtVisionThreads * vision_threads
Vision threads assigned to this acquisition thread.
virtual void loop()
Code to execute in the thread.
void set_enabled(bool enabled)
Enable or disable image retrieval.
AqtMode aqtmode()
Get acquisition thread mode.
virtual void run()
Stub to see name in backtrace for easier debugging.
void set_vt_prepfin_hold(bool hold)
Set prepfin hold status for vision threads.
virtual void init()
Initialize the thread.
AqtMode
Acquisition thread mode.
@ AqtContinuous
continuous mode, use if there are only continuous threads for this acquisition thread.
@ AqtCyclic
cyclic mode, use if there is at least one cyclic thread for this acquisition thread.
fawkes::Thread * raw_subscriber_thread
Vision thread registered for raw camera access on this camera.
firevision::Camera * camera_instance(firevision::colorspace_t cspace, bool deep_copy)
Get a camera instance.
Aquisition-dependant threads.
FireVision base thread.
Definition: base_thread.h:54
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
BlackBoard interface listener.
This is supposed to be the central clock in Fawkes.
Definition: clock.h:35
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
Interface for logging.
Definition: logger.h:42
Thread aspect to log output.
Definition: logging.h:33
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:45
Mutex mutual exclusion lock.
Definition: mutex.h:33
SwitchInterface Fawkes BlackBoard Interface.
Thread class encapsulation of pthreads.
Definition: thread.h:46
Time tracking utility.
Definition: tracker.h:37
Wait until a given condition holds.
Camera interface for image aquiring devices in FireVision.
Definition: camera.h:33
Fawkes library namespace.