Fawkes API
Fawkes Development Version
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
sensacq_thread.cpp
1
2
/***************************************************************************
3
* sensaqt_thread.cpp - Katana sensor acqusition thread
4
*
5
* Created: Fri Jun 12 15:08:56 2009
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
#include "sensacq_thread.h"
24
#include "controller.h"
25
26
#include <cstdlib>
27
28
using namespace
fawkes;
29
30
/** @class KatanaSensorAcquisitionThread "sensacq_thread.h"
31
* Katana sensor acquisition thread.
32
* This thread runs continuously and acquires data from the sensor. Since the
33
* operation is blocking and may take several miliseconds it is done concurrently
34
* to the main loop at specified intervals.
35
* @author Tim Niemueller
36
*/
37
38
/** Constructor.
39
* @param katana katana controller base class
40
* @param logger logger
41
*/
42
KatanaSensorAcquisitionThread::KatanaSensorAcquisitionThread
(
fawkes::RefPtr<fawkes::KatanaController>
katana,
43
fawkes::Logger
*logger)
44
:
Thread
(
"KatanaSensorAcqusitionThread"
,
Thread
::OPMODE_WAITFORWAKEUP)
45
{
46
__katana = katana;
47
__logger = logger;
48
__enabled =
false
;
49
}
50
51
52
/** Set whether data acquisition is enabled or not.
53
* In general the thread should only be woken up if sensor data can be acquired.
54
* But for safety data acqusition can also be turned off to be safe against
55
* spurious wakeups. Additionally, this method will acquire the loop mutex,
56
* thereby assuring that a possibly running loop has finished.
57
* @param enabled true to enable sensor data acquisition, false to disable.
58
*/
59
void
60
KatanaSensorAcquisitionThread::set_enabled
(
bool
enabled)
61
{
62
loop_mutex
->
lock
();
63
__enabled = enabled;
64
loop_mutex
->
unlock
();
65
}
66
67
68
void
69
KatanaSensorAcquisitionThread::loop
()
70
{
71
if
(__enabled) {
72
try
{
73
__katana->
read_sensor_data
();
74
}
catch
(
Exception
&e) {
75
__logger->
log_warn
(
name
(), e.
what
());
76
}
77
}
78
}
src
plugins
katana
sensacq_thread.cpp
Generated by
1.8.3.1