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  */
36 : Thread("BallPosLogThread", Thread::OPMODE_WAITFORWAKEUP),
37  BlockedTimingAspect(BlockedTimingAspect::WAKEUP_HOOK_THINK)
38 {
39 }
40 
41 /** Destructor. */
43 {
44 }
45 
46 void
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
61 {
62  blackboard->close(wm_ball_interface);
63 }
64 
65 void
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 }
virtual void loop()
Code to execute in the thread.
Definition: thread.cpp:66
virtual ~BallPosLogThread()
Destructor.
Definition: thread.cpp:42
virtual void finalize()
Finalize the thread.
Definition: thread.cpp:60
BallPosLogThread()
Constructor.
Definition: thread.cpp:35
virtual void init()
Initialize the thread.
Definition: thread.cpp:47
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
Definition: blackboard.h:44
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
virtual void close(Interface *interface)=0
Close interface.
Thread aspect to use blocked timing.
Configuration * config
This is the Configuration member used to access the configuration.
Definition: configurable.h:41
virtual unsigned int get_uint(const char *path)=0
Get value from configuration which is of type unsigned int.
Base class for exceptions in Fawkes.
Definition: exception.h:36
void read()
Read from BlackBoard into local copy.
Definition: interface.cpp:472
virtual void log(LogLevel level, const char *component, const char *format,...)
Log message of given log level.
Definition: logger.cpp:326
LogLevel
Log level.
Definition: logger.h:51
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:41
ObjectPositionInterface Fawkes BlackBoard Interface.
float world_y() const
Get world_y value.
float world_x() const
Get world_x value.
Thread class encapsulation of pthreads.
Definition: thread.h:46
Fawkes library namespace.