Fawkes API  Fawkes Development Version
sensor_thread.cpp
00001 
00002 /***************************************************************************
00003  *  sensor_thread.cpp - Roomba plugin sensor thread
00004  *
00005  *  Created: Mon Jan 03 00:05:32 2011
00006  *  Copyright  2006-2010  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 "sensor_thread.h"
00024 #include "thread_roomba_500.h"
00025 
00026 using namespace fawkes;
00027 
00028 /** @class RoombaSensorThread "sensor_thread.h"
00029  * Roomba sensor hook integration thread.
00030  * This thread integrates into the Fawkes main loop at the SENSOR hook and
00031  * triggers the Roomba thread to write new sensor data.
00032  * @author Tim Niemueller
00033  */
00034 
00035 /** Constructor.
00036  * @param roomba500_thread Roomba 500 thread to trigger to write to blackboard.
00037  */
00038 RoombaSensorThread::RoombaSensorThread(Roomba500Thread *roomba500_thread)
00039   : Thread("RoombaSensorThread", Thread::OPMODE_WAITFORWAKEUP),
00040     BlockedTimingAspect(BlockedTimingAspect::WAKEUP_HOOK_SENSOR_ACQUIRE)
00041 {
00042   __roomba500_thread = roomba500_thread;
00043 }
00044 
00045 
00046 
00047 void
00048 RoombaSensorThread::loop()
00049 {
00050   try {
00051     __roomba500_thread->write_blackboard();
00052   } catch (Exception &e) {
00053     logger->log_warn(name(), "%s failed to write to BB, exception follows.",
00054                      __roomba500_thread->name());
00055     logger->log_warn(name(), e);
00056   }
00057 }