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 <plugins/examples/ballposlog/thread.h>
24 #include <interfaces/ObjectPositionInterface.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",
37  Thread::OPMODE_WAITFORWAKEUP),
39  BlockedTimingAspect::WAKEUP_HOOK_THINK)
40 {
41 }
42 
43 
44 /** Destructor. */
46 {
47 }
48 
49 
50 void
52 {
53  wm_ball_interface = NULL;
54  try {
55  wm_ball_interface =
57  log_level = (Logger::LogLevel)config->
58  get_uint("/ballposlog/log_level");
59  } catch (Exception &e) {
60  blackboard->close(wm_ball_interface);
61  throw;
62  }
63 }
64 
65 
66 void
68 {
69  blackboard->close(wm_ball_interface);
70 }
71 
72 
73 void
75 {
76  wm_ball_interface->read();
77 
78  logger->log(log_level, "BallPosLog",
79  "Ball is at global (x,y) = (%f,%f)",
80  wm_ball_interface->world_x(),
81  wm_ball_interface->world_y());
82 }
LogLevel
Log level.
Definition: logger.h:45
ObjectPositionInterface Fawkes BlackBoard Interface.
Fawkes library namespace.
virtual void loop()
Code to execute in the thread.
Definition: thread.cpp:74
Thread class encapsulation of pthreads.
Definition: thread.h:42
virtual void finalize()
Finalize the thread.
Definition: thread.cpp:67
Logger * logger
This is the Logger member used to access the logger.
Definition: logging.h:44
BallPosLogThread()
Constructor.
Definition: thread.cpp:35
float world_y() const
Get world_y value.
virtual void init()
Initialize the thread.
Definition: thread.cpp:51
Thread aspect to use blocked timing.
Base class for exceptions in Fawkes.
Definition: exception.h:36
void read()
Read from BlackBoard into local copy.
Definition: interface.cpp:477
virtual ~BallPosLogThread()
Destructor.
Definition: thread.cpp:45
virtual Interface * open_for_reading(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for reading.
float world_x() const
Get world_x value.
virtual void log(LogLevel level, const char *component, const char *format,...)
Log message of given log level.
Definition: logger.cpp:315
Configuration * config
This is the Configuration member used to access the configuration.
Definition: configurable.h:44
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
Definition: blackboard.h:44
virtual void close(Interface *interface)=0
Close interface.