thread.cpp

00001 
00002 /***************************************************************************
00003  *  thread.cpp - Fawkes ball position logger - for demonstration
00004  *
00005  *  Created: Thu Jan 24 17:03:56 2008
00006  *  Copyright  2008  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022 
00023 #include <plugins/examples/ballposlog/thread.h>
00024 #include <interfaces/ObjectPositionInterface.h>
00025 
00026 /** @class BallPosLogThread thread.h "thread.h"
00027  * Main thread of ball position logger plugin.
00028  * @author Tim Niemueller
00029  */
00030 
00031 using namespace fawkes;
00032 
00033 /** Constructor.
00034  */
00035 BallPosLogThread::BallPosLogThread()
00036   : Thread("BallPosLogThread",
00037            Thread::OPMODE_WAITFORWAKEUP),
00038     BlockedTimingAspect(
00039         BlockedTimingAspect::WAKEUP_HOOK_THINK)
00040 {
00041 }
00042 
00043 
00044 /** Destructor. */
00045 BallPosLogThread::~BallPosLogThread()
00046 {
00047 }
00048 
00049 
00050 void
00051 BallPosLogThread::init()
00052 {
00053   wm_ball_interface      = NULL;
00054   try {
00055     wm_ball_interface =
00056       blackboard->open_for_reading<ObjectPositionInterface>("WM Ball");
00057     log_level = (Logger::LogLevel)config->
00058                 get_uint("/ballposlog/log_level");
00059   } catch (Exception &e) {
00060     blackboard->close(wm_ball_interface);
00061     throw;
00062   }
00063 }
00064 
00065 
00066 void
00067 BallPosLogThread::finalize()
00068 {
00069   blackboard->close(wm_ball_interface);
00070 }
00071 
00072 
00073 void
00074 BallPosLogThread::loop()
00075 {
00076   wm_ball_interface->read();
00077 
00078   logger->log(log_level, "BallPosLog",
00079               "Ball is at global (x,y) = (%f,%f)",
00080               wm_ball_interface->world_x(),
00081               wm_ball_interface->world_y());
00082 }

Generated on Tue Feb 22 13:31:25 2011 for Fawkes API by  doxygen 1.4.7