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
FvAcquisitionThread::set_enabled
void set_enabled(bool enabled)
Enable or disable image retrieval.
Definition: acquisition_thread.cpp:244
fawkes::Mutex
Mutex mutual exclusion lock.
Definition: mutex.h:33
fawkes::SwitchInterface
SwitchInterface Fawkes BlackBoard Interface.
Definition: SwitchInterface.h:34
FvAqtVisionThreads
Aquisition-dependant threads.
Definition: aqt_vision_threads.h:40
fawkes::WaitCondition
Wait until a given condition holds.
Definition: wait_condition.h:37
fawkes::Message
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Definition: message.h:45
FvAcquisitionThread::AqtMode
AqtMode
Acquisition thread mode.
Definition: acquisition_thread.h:58
FvAcquisitionThread::aqtmode
AqtMode aqtmode()
Get acquisition thread mode.
Definition: acquisition_thread.cpp:271
FvAcquisitionThread
FireVision base application acquisition thread.
Definition: acquisition_thread.h:55
FvAcquisitionThread::run
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: acquisition_thread.h:95
fawkes::BlackBoardInterfaceListener
BlackBoard interface listener.
Definition: interface_listener.h:42
FvAcquisitionThread::camera_instance
firevision::Camera * camera_instance(firevision::colorspace_t cspace, bool deep_copy)
Get a camera instance.
Definition: acquisition_thread.cpp:177
FvAcquisitionThread::finalize
virtual void finalize()
Finalize the thread.
Definition: acquisition_thread.cpp:137
fawkes::LoggingAspect::logger
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
fawkes::Logger
Interface for logging.
Definition: logger.h:42
FvAcquisitionThread::raw_subscriber_thread
fawkes::Thread * raw_subscriber_thread
Vision thread registered for raw camera access on this camera.
Definition: acquisition_thread.h:90
FvAcquisitionThread::set_vt_prepfin_hold
void set_vt_prepfin_hold(bool hold)
Set prepfin hold status for vision threads.
Definition: acquisition_thread.cpp:281
FvAcquisitionThread::AqtContinuous
@ AqtContinuous
continuous mode, use if there are only continuous threads for this acquisition thread.
Definition: acquisition_thread.h:61
FvBaseThread
FireVision base thread.
Definition: base_thread.h:54
fawkes::BlackBoardAspect
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
fawkes
Fawkes library namespace.
fawkes::LoggingAspect
Thread aspect to log output.
Definition: logging.h:33
FvAcquisitionThread::loop
virtual void loop()
Code to execute in the thread.
Definition: acquisition_thread.cpp:294
FvAcquisitionThread::set_aqtmode
void set_aqtmode(AqtMode mode)
Set acquisition thread mode.
Definition: acquisition_thread.cpp:225
fawkes::Interface
Base class for all Fawkes BlackBoard interfaces.
Definition: interface.h:79
FvAcquisitionThread::AqtCyclic
@ AqtCyclic
cyclic mode, use if there is at least one cyclic thread for this acquisition thread.
Definition: acquisition_thread.h:59
FvAcquisitionThread::~FvAcquisitionThread
virtual ~FvAcquisitionThread()
Destructor.
Definition: acquisition_thread.cpp:105
fawkes::TimeTracker
Time tracking utility.
Definition: tracker.h:37
FvAcquisitionThread::FvAcquisitionThread
FvAcquisitionThread(const char *id, firevision::Camera *camera, fawkes::Logger *logger, fawkes::Clock *clock)
Constructor.
Definition: acquisition_thread.cpp:68
FvAcquisitionThread::vision_threads
FvAqtVisionThreads * vision_threads
Vision threads assigned to this acquisition thread.
Definition: acquisition_thread.h:87
fawkes::Thread
Thread class encapsulation of pthreads.
Definition: thread.h:46
firevision::Camera
Camera interface for image aquiring devices in FireVision.
Definition: camera.h:33
FvAcquisitionThread::get_camera
firevision::Camera * get_camera()
Get the Camera of this acquisition thread.
Definition: acquisition_thread.cpp:214
FvAcquisitionThread::init
virtual void init()
Initialize the thread.
Definition: acquisition_thread.cpp:122
fawkes::Clock
This is supposed to be the central clock in Fawkes.
Definition: clock.h:35