Fawkes API
Fawkes Development Version
thread.cpp
1
2
/***************************************************************************
3
* thread.cpp - Fawkes ball position logger - for demonstration
4
*
5
* Created: Thu Jan 24 17:03:56 2008
6
* Copyright 2008 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 <interfaces/ObjectPositionInterface.h>
24
#include <plugins/examples/ballposlog/thread.h>
25
26
/** @class BallPosLogThread thread.h "thread.h"
27
* Main thread of ball position logger plugin.
28
* @author Tim Niemueller
29
*/
30
31
using namespace
fawkes
;
32
33
/** Constructor.
34
*/
35
BallPosLogThread::BallPosLogThread
()
36
:
Thread
(
"BallPosLogThread"
,
Thread
::OPMODE_WAITFORWAKEUP),
37
BlockedTimingAspect
(
BlockedTimingAspect
::WAKEUP_HOOK_THINK)
38
{
39
}
40
41
/** Destructor. */
42
BallPosLogThread::~BallPosLogThread
()
43
{
44
}
45
46
void
47
BallPosLogThread::init
()
48
{
49
wm_ball_interface = NULL;
50
try
{
51
wm_ball_interface =
blackboard
->
open_for_reading
<
ObjectPositionInterface
>(
"WM Ball"
);
52
log_level = (
Logger::LogLevel
)
config
->
get_uint
(
"/ballposlog/log_level"
);
53
}
catch
(
Exception
&e) {
54
blackboard
->
close
(wm_ball_interface);
55
throw
;
56
}
57
}
58
59
void
60
BallPosLogThread::finalize
()
61
{
62
blackboard
->
close
(wm_ball_interface);
63
}
64
65
void
66
BallPosLogThread::loop
()
67
{
68
wm_ball_interface->
read
();
69
70
logger
->
log
(log_level,
71
"BallPosLog"
,
72
"Ball is at global (x,y) = (%f,%f)"
,
73
wm_ball_interface->
world_x
(),
74
wm_ball_interface->
world_y
());
75
}
fawkes::Logger::log
virtual void log(LogLevel level, const char *component, const char *format,...)
Log message of given log level.
Definition:
logger.cpp:325
fawkes::ObjectPositionInterface::world_y
float world_y() const
Get world_y value.
Definition:
ObjectPositionInterface.cpp:631
BallPosLogThread::~BallPosLogThread
virtual ~BallPosLogThread()
Destructor.
Definition:
thread.cpp:41
fawkes::Interface::read
void read()
Read from BlackBoard into local copy.
Definition:
interface.cpp:475
fawkes::ObjectPositionInterface::world_x
float world_x() const
Get world_x value.
Definition:
ObjectPositionInterface.cpp:592
fawkes::BlockedTimingAspect
Definition:
blocked_timing.h:54
fawkes::LoggingAspect::logger
Logger * logger
Definition:
logging.h:50
fawkes::BlackBoard::close
virtual void close(Interface *interface)=0
fawkes
BallPosLogThread::loop
virtual void loop()
Code to execute in the thread.
Definition:
thread.cpp:65
fawkes::ConfigurableAspect::config
Configuration * config
Definition:
configurable.h:50
BallPosLogThread::init
virtual void init()
Initialize the thread.
Definition:
thread.cpp:46
BallPosLogThread::BallPosLogThread
BallPosLogThread()
Constructor.
Definition:
thread.cpp:34
fawkes::Logger::LogLevel
LogLevel
Log level.
Definition:
logger.h:50
fawkes::Thread
Definition:
thread.h:44
fawkes::BlackBoardAspect::blackboard
BlackBoard * blackboard
Definition:
blackboard.h:47
fawkes::Configuration::get_uint
virtual unsigned int get_uint(const char *path)=0
fawkes::BlackBoard::open_for_reading
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
BallPosLogThread::finalize
virtual void finalize()
Finalize the thread.
Definition:
thread.cpp:59
fawkes::ObjectPositionInterface
Definition:
ObjectPositionInterface.h:37
fawkes::Exception
Definition:
exception.h:39
src
plugins
examples
ballposlog
thread.cpp
Generated by
1.8.16